FMT 1.2.0
Forest management tools for forest planning
Loading...
Searching...
No Matches
FMTMatrixBuild.h
Go to the documentation of this file.
1/*
2Copyright (c) 2019 Gouvernement du Québec
3
4SPDX-License-Identifier: LiLiQ-R-1.1
5License-Filename: LICENSES/EN/LiLiQ-R11unicode.txt
6*/
7
8#ifdef FMTWITHOSI
9
10#ifndef FMTmatrixbuild_Hm_included
11#define FMTmatrixbuild_Hm_included
12
13
14#include <vector>
15#include <string>
16#include <memory>
17#include "FMTutility.h"
18#include "FMTObject.h"
19class OsiSolverInterface;
20class CoinBuild;
21
22
23namespace Models
24
25{
26 // DocString: FMTMatrixBuild
32 {
33 public:
34 // DocString: FMTMatrixBuild::swap
39 void swap(FMTMatrixBuild& rhs);
40 // DocString: FMTMatrixBuild::getColumnNames
45 inline std::vector<std::string>& getColumnNames()
46 {
47 return m_columnnames;
48 }
49 // DocString: FMTMatrixBuild::getRowNames
54 inline std::vector<std::string>& getRowNames()
55 {
56 return m_rownames;
57 }
58 // DocString: FMTMatrixBuild::formatAllNames
63 void formatAllNames(bool shortformat);
64 // DocString: FMTMatrixBuild::setColName
70 void setColName(const std::string& name,const int& columnid);
71 // DocString: FMTMatrixBuild::setRowName
77 void setRowName(const std::string& name, const int& rowid);
78 // DocString: FMTMatrixBuild::synchronize
83 void synchronize(std::shared_ptr<OsiSolverInterface> solver);
84 // DocString: FMTMatrixBuild()
89 // DocString: FMTMatrixBuild(const FMTMatrixBuild)
95 // DocString: FMTMatrixBuild::operator=
101 FMTMatrixBuild& operator = (const FMTMatrixBuild& rhs);
102 // DocString: ~FMTMatrixBuild()
107 // DocString: FMTMatrixBuild::addCol
117 void addCol(int numberInColumn, const int * rows, const double * elements, double columnLower = 0.0,
118 double columnUpper = std::numeric_limits<double>::max(), double objectiveValue = 0.0);
119 // DocString: FMTMatrixBuild::addRow
128 void addRow(int numberInRow, const int * columns, const double * elements,
129 double rowLower = -std::numeric_limits<double>::max(), double rowUpper = std::numeric_limits<double>::max());
130 // DocString: FMTMatrixBuild::deleteRow
135 void deleteRow(const int& rowindex);
136 // DocString: FMTMatrixBuild::deleteCol
141 void deleteCol(const int& colindex);
142 // DocString: FMTMatrixBuild::numberNewRows
147 inline int numberNewRows() const
148 {
149 return m_rowscount;
150 }
151 // DocString: FMTMatrixBuild::numberNewCols
156 inline int numberNewCols() const
157 {
158 return m_colscount;
159 }
160 // DocString: FMTMatrixBuild::numberOfDeletedRows
165 inline int numberOfDeletedRows() const
166 {
167 return static_cast<int>(m_deletedconstraints.size());
168 }
169 // DocString: FMTMatrixBuild::numberOfDeletedCols
174 inline int numberOfDeletedCols() const
175 {
176 return static_cast<int>(m_deletedvariables.size());
177 }
178 // DocString: FMTMatrixBuild::getDeletedConstraints
183 inline const std::vector<int>& getDeletedConstraints() const
184 {
185 return m_deletedconstraints;
186 }
187 // DocString: FMTMatrixBuild::getDeletedVariables
192 inline const std::vector<int>& getDeletedVariables() const
193 {
194 return m_deletedvariables;
195 }
196 // DocString: FMTMatrixBuild::sortAndCleanDeleted
201 // DocString: FMTMatrixBuild::getRowsToSynchronize
206 std::string getRowsToSynchronize() const;
207 // DocString: FMTMatrixBuild::getRowsToSynchronize
212 std::string getColsToSynchronize() const;
213 // DocString: FMTMatrixBuild::getRow
223 int getRow(int whichRow, double &rowLower, double &rowUpper,
224 std::vector<int>& indices, std::vector<double>&elements) const;
225 // DocString: FMTMatrixBuild::getCol
236 int getCol(int whichCol, double &colLower, double &colUpper, double &objectiveValue,
237 std::vector<int>& indices, std::vector<double>&elements) const;
238
239
240 private:
241 // DocString: FMTMatrixBuild::lastcol
243 int m_colscount;
244 // DocString: FMTMatrixBuild::lastrow
246 int m_rowscount;
247 // DocString: FMTMatrixBuild::m_colsbuild
249 std::unique_ptr<CoinBuild>m_colsbuild;
250 // DocString: FMTMatrixBuild::m_rowsbuild
252 std::unique_ptr<CoinBuild>m_rowsbuild;
253 // DocString: FMTMatrixBuild::m_deletedconstraints
255 std::vector<int>m_deletedconstraints;
256 // DocString: FMTMatrixBuild::m_deletedvariables
258 std::vector<int>m_deletedvariables;
259 // DocString: FMTMatrixBuild::m_columnnames
261 std::vector<std::string>m_columnnames;
262 // DocString: FMTMatrixBuild::m_rownames
264 std::vector<std::string>m_rownames;
265 // DocString: FMTMatrixBuild::_sortElementsAndClean
270 void _sortElementsAndClean(std::vector<int>& elements) const;
271 // DocString: FMTMatrixBuild::_formatForMatrixName
278 std::string _formatForMatrixName(std::string name, bool shortformat) const;
279 };
280}
281
282#endif
283#endif
#define FMTEXPORT
Definition: FMTutility.h:125
Helper caching rows and columns to add to a solver matrix in batch for efficiency.
Definition: FMTMatrixBuild.h:32
void synchronize(std::shared_ptr< OsiSolverInterface > solver)
Synchronize the cached columns and rows with the solver matrix.
void formatAllNames(bool shortformat)
Format the cached row and column names.
FMTMatrixBuild(const FMTMatrixBuild &rhs)
Copy constructor for FMTMatrixBuild.
int getCol(int whichCol, double &colLower, double &colUpper, double &objectiveValue, std::vector< int > &indices, std::vector< double > &elements) const
Fill up the bounds, objective, indices and elements of a given column present in the cache.
void deleteCol(const int &colindex)
Delete a column from the matrix cache.
void swap(FMTMatrixBuild &rhs)
Swap this FMTMatrixBuild with another.
int numberOfDeletedRows() const
Return the number of newly deleted rows in the matrix cache.
Definition: FMTMatrixBuild.h:165
~FMTMatrixBuild()
Destructor for FMTMatrixBuild.
std::string getColsToSynchronize() const
Return a string of all the columns in the matrix cache, mainly for debugging.
int getRow(int whichRow, double &rowLower, double &rowUpper, std::vector< int > &indices, std::vector< double > &elements) const
Fill up the bounds, indices and elements of a given row present in the cache.
int numberNewCols() const
Return the number of newly added columns in the matrix cache.
Definition: FMTMatrixBuild.h:156
void addCol(int numberInColumn, const int *rows, const double *elements, double columnLower=0.0, double columnUpper=std::numeric_limits< double >::max(), double objectiveValue=0.0)
Add a column to the cache to potentially synchronize it later.
void sortAndCleanDeleted()
Remove duplicates from the deleted rows and columns and sort them.
int numberNewRows() const
Return the number of newly added rows in the matrix cache.
Definition: FMTMatrixBuild.h:147
void deleteRow(const int &rowindex)
Delete a row from the matrix cache.
const std::vector< int > & getDeletedConstraints() const
Return the newly deleted rows in the matrix cache.
Definition: FMTMatrixBuild.h:183
FMTMatrixBuild()
Default constructor for FMTMatrixBuild.
std::vector< std::string > & getRowNames()
Return the cached row names.
Definition: FMTMatrixBuild.h:54
std::string getRowsToSynchronize() const
Return a string of all the rows in the matrix cache, mainly for debugging.
void addRow(int numberInRow, const int *columns, const double *elements, double rowLower=-std::numeric_limits< double >::max(), double rowUpper=std::numeric_limits< double >::max())
Add a row to the cache to potentially synchronize it later.
const std::vector< int > & getDeletedVariables() const
Return the newly deleted columns in the matrix cache.
Definition: FMTMatrixBuild.h:192
std::vector< std::string > & getColumnNames()
Return the cached column names.
Definition: FMTMatrixBuild.h:45
int numberOfDeletedCols() const
Return the number of newly deleted columns in the matrix cache.
Definition: FMTMatrixBuild.h:174
void setRowName(const std::string &name, const int &rowid)
Set a row name.
void setColName(const std::string &name, const int &columnid)
Set a column name.
Namespace containing all enumerator and classes used to construct or manipulate the different type of...
Definition: FMTAreaParser.h:54