20 #include "UtilMacrosDecomp.h"
35 bool columnMajor =
false;
39 =
new CoinPackedMatrix(
62 std::cout <<
"PROBLEM READING OSiL File" << std::endl;
64 std::cout << eclass.
errormsg << std::endl;
93 std::cout <<
"Problem reading OSoL File" << std::endl;
95 std::cout << eclass.
errormsg << std::endl;
110 m_row =
new CoinPackedVector();
118 for (k = sm->
starts[i]; k < sm->starts[i + 1]; k++) {
133 for (i = 0; i < numVars; i++) {
171 std::vector<OtherVariableOption*> otherVariableOptions;
172 std::vector<OtherVariableOption*>::iterator vit;
179 for (vit = otherVariableOptions.begin(); vit
180 != otherVariableOptions.end(); vit++) {
183 if ((*vit)->name.compare(
"variableBlockSet") == 0) {
185 if ((*vit)->value.size() > 0) {
203 std::cout << eclass.
errormsg << std::endl;
214 std::set<int> varSet;
224 std::vector<OtherVariableOption*> otherVariableOptions;
225 std::vector<OtherVariableOption*>::iterator vit;
232 for (vit = otherVariableOptions.begin(); vit
233 != otherVariableOptions.end(); vit++) {
236 if ((*vit)->name.compare(
"variableBlockSet") == 0) {
242 numVar = (*vit)->numberOfVar;
244 for (i = 0; i < numVar; i++) {
246 if ((*vit)->var[i]->idx
249 "found an invalid varaible index in OSoL file");
251 varSet.insert((*vit)->var[i]->idx);
264 throw ErrorClass(
"someting wrong -- no variables in the blocks");
270 std::cout << eclass.
errormsg << std::endl;
284 std::map<int, int> conMap;
285 std::set<int> varSet;
286 std::set<int> coreConstraintIndexes;
287 std::vector<std::set<int> > blockVariableIndexes;
300 if (blockVariableIndexes.size() <= 0)
301 throw ErrorClass(
"someting wrong -- no variables in the blocks");
303 std::vector<std::set<int> >::iterator vit;
304 std::set<int>::iterator sit;
307 for (vit = blockVariableIndexes.begin(); vit
308 != blockVariableIndexes.end(); vit++) {
318 for (sit = varSet.begin(); sit != varSet.end(); sit++) {
325 for (i = starts[*sit]; i < starts[*sit + 1]; i++) {
329 if (coreConstraintIndexes.find(indexes[i])
330 == coreConstraintIndexes.end() &&
331 (conMap.find(indexes[i] ) == conMap.end() )
335 conMap.insert(std::make_pair(indexes[i], kount));
350 std::cout << eclass.
errormsg << std::endl;
364 std::map<int, int> conMap;
365 std::set<int> varSet;
366 std::vector<std::map<int, int> > blockConstraintIndexes;
367 std::set<int> coreConstraintIndexes;
368 std::vector<std::set<int> > blockVariableIndexes;
375 std::vector<std::set<int> >::iterator vit;
376 std::set<int>::iterator sit;
377 std::map<int, int>::iterator mit;
387 std::string* varNames = NULL;
388 char* varTypes = NULL;
389 double* varLowerBounds = NULL;
390 double* varUpperBounds = NULL;
394 std::string* conNames = NULL;
395 double* conLowerBounds = NULL;
396 double* conUpperBounds = NULL;
397 double* conConstants = NULL;
412 if (blockVariableIndexes.size() <= 0)
414 "someting wrong in getBlockOSInstances() -- no variables in the blocks");
420 for (vit = blockVariableIndexes.begin(); vit
421 != blockVariableIndexes.end(); vit++) {
429 numberVar = varSet.size();
430 varTypes =
new char[numberVar];
431 varNames =
new std::string[numberVar];
432 varLowerBounds =
new double[numberVar];
433 varUpperBounds =
new double[numberVar];
449 for (sit = varSet.begin(); sit != varSet.end(); sit++) {
452 varLowerBounds[kount]
454 varUpperBounds[kount]
459 objcoeff->
indexes[kount] = kount;
470 osinstance->
setVariables(numberVar, varNames, varLowerBounds,
471 varUpperBounds, varTypes);
480 conMap = blockConstraintIndexes[whichBlock];
481 numberCon = conMap.size();
485 starts =
new int[numberVar + 1];
486 indexes =
new int[numNonz];
487 values =
new double[numNonz];
492 for (sit = varSet.begin(); sit != varSet.end(); sit++) {
500 for (i = k1; i < k2; i++) {
506 if (coreConstraintIndexes.find(idx)
507 == coreConstraintIndexes.end()) {
509 indexes[numNonz] = conMap[idx];
516 starts[kount + 1] = numNonz;
526 conLowerBounds =
new double[numberCon];
527 conUpperBounds =
new double[numberCon];
528 conConstants =
new double[numberCon];
530 for (mit = conMap.begin(); mit != conMap.end(); mit++) {
532 conLowerBounds[mit->second]
534 conUpperBounds[mit->second]
536 conConstants[mit->second] = 1.0;
542 std::cout <<
"Call setConstraints " << numberCon << std::endl;
545 conUpperBounds, conConstants);
548 values, 0, numNonz - 1, indexes, 0, numNonz - 1,
549 starts, 0, numberVar);
565 if (varLowerBounds != NULL)
566 delete[] varLowerBounds;
567 if (varUpperBounds != NULL)
568 delete[] varUpperBounds;
569 if (varTypes != NULL)
571 if (varNames != NULL)
578 if (conLowerBounds != NULL)
579 delete[] conLowerBounds;
580 if (conUpperBounds != NULL)
581 delete[] conUpperBounds;
582 if (conConstants != NULL)
583 delete[] conConstants;
594 std::cout << eclass.
errormsg << std::endl;
615 std::vector<OtherConstraintOption*> otherConstraintOptions;
616 std::vector<OtherConstraintOption*>::iterator vit;
624 for (vit = otherConstraintOptions.begin(); vit
625 != otherConstraintOptions.end(); vit++) {
629 if (((*vit)->name.compare(
"constraintSet") == 0)
630 && ((*vit)->type.compare(
"Core") == 0)) {
632 numCoreCon = (*vit)->numberOfCon;
634 for (i = 0; i < numCoreCon; i++) {
636 if ((*vit)->con[i]->idx
639 "found an invalid constraint index in OSoL file");
655 "there were no core constraints listed in the option file");
661 std::cout << eclass.
errormsg << std::endl;
682 m_isProvenOptimal(false), m_bestKnownLB(-1.e20), m_bestKnownUB(1.e20),
690 m_blockVariableIndexesProcessed(false),
691 m_coreConstraintIndexesProcessed(false),
692 m_blockConstraintIndexesProcessed(false),
693 m_blockOSInstancesProcessed(false),
694 m_blockFactoriesProcessed(false)
700 std::cout <<
"INSIDE OS DIP INTERFACE DESTRUCTOR" << std::endl;
707 std::vector<OSInstance*>::iterator vit;
731 std::string testFileName;
735 std::map<int, std::vector< int> > indexMap;
736 std::vector< int> indexes;
741 testFileName =
"../data/restrictedMaster5.osil";
746 std::cout <<
"Done reading the file" << std::endl;
755 parsingTestResult <<
"Reading files successfully" << std::endl;
758 osinstance = osilreader->
readOSiL(osil);
764 std::cout <<
"CALLING SOLVE FOR RESTRICTED MASTER" << std::endl;
771 std::vector<IndexValuePair*> primalValPair;
773 vecSize = primalValPair.size();
782 int* routeDemand = NULL;
785 routeDemand =
new int[ numHubs];
788 std::string* varNames;
793 for(k = 0; k < numHubs; k++){
795 routeDemand[
k ] = (
int)primalValPair[ kount]->value;
797 std::cout <<
"Route Demand = " << routeDemand[
k] << std::endl;
804 for(k = 0; k < numHubs; k++){
806 startPnt = k*totalDemand*(numNodes*numNodes - numNodes) + (routeDemand[ k] - 1)*(numNodes*numNodes - numNodes);
808 for(i = 0; i < numNodes; i++){
811 for(j = 0; j < i; j++){
813 if( primalValPair[ kount]->value > .1){
815 std::cout << varNames[ kount] << std::endl;
816 indexes.push_back(startPnt + i*(numNodes-1) + j );
825 for(j = i + 1; j < numNodes; j++){
828 if( primalValPair[ kount]->value > .1){
829 std::cout << varNames[ kount] << std::endl;
830 indexes.push_back(startPnt + i*(numNodes-1) + j -1 );
844 indexMap.insert(make_pair(k, indexes));
849 std::cout <<
"DONE CALLING SOLVE FOR RESTRICTED MASTER" << std::endl;
853 delete[] routeDemand;
865 std::cout << std::endl << std::endl << std::endl;
866 if (osilreader != NULL)
870 if (osoption != NULL)
double * getConstraintLowerBounds()
Get constraint lower bounds.
double * getVariableLowerBounds()
Get variable lower bounds.
double * getConstraintUpperBounds()
Get constraint upper bounds.
char * getVariableTypes()
Get variable initial values.
CoinPackedMatrix * getCoinPackedMatrix()
Returns array[getNumCols()] specifying if a variable is integer.
std::vector< OtherConstraintOption * > getOtherConstraintOptions(std::string solver_name)
Get the array of other constraint options.
bool m_blockOSInstancesProcessed
Returns array[getNumCols()] specifying if a variable is integer.
const int getVariableNumber() const
Get variable number.
int getNumberOfOtherConstraintOptions()
Get the number of other constraint options.
bool m_coreConstraintIndexesProcessed
Returns array[getNumCols()] specifying if a variable is integer.
bool setLinearConstraintCoefficients(int numberOfValues, bool isColumnMajor, double *values, int valuesBegin, int valuesEnd, int *indexes, int indexesBegin, int indexesEnd, int *starts, int startsBegin, int startsEnd)
set linear constraint coefficients
int getVariableNumber()
Get number of variables.
std::string errormsg
errormsg is the error that is causing the exception to be thrown
int getLinearConstraintCoefficientNumber()
Get number of specified (usually nonzero) linear constraint coefficient values.
std::vector< IndexValuePair * > getOptimalPrimalVariableValues(int solIdx)
Get one solution of optimal primal variable values.
std::vector< std::set< int > > m_blockVariableIndexes
Returns array[getNumCols()] specifying if a variable is integer.
OSResult * osresult
osresult holds the solution or result of the model in-memory as an OSResult object ...
bool m_blockVariableIndexesProcessed
Returns array[getNumCols()] specifying if a variable is integer.
CoinPackedMatrix * m_coinpm
double * getObjectiveFunctionCoeff()
Returns array[getNumCols()] specifying if a variable is integer.
OSiLReader * m_osilreader
OSInstance * readOSiL(const std::string &osil)
parse the OSiL model instance.
std::string * getVariableNames()
Get variable names.
CoinPackedVector * getRow(int i)
Returns array[getNumCols()] specifying if a variable is integer.
int * indexes
indexes holds an integer array of rowIdx (or colIdx) elements in coefMatrix (AMatrix).
virtual void solve()=0
solve is a virtual function – the actual solvers will implement their own solve method ...
double ** getDenseObjectiveCoefficients()
getDenseObjectiveCoefficients.
std::vector< std::set< int > > getBlockVarIndexes()
Returns array[getNumCols()] specifying if a variable is integer.
std::vector< std::map< int, int > > getBlockConstraintIndexes()
Returns array[getNumCols()] specifying if a variable is integer.
~OS_DipInterface()
class destructor
void readOSiL(std::string &filename)
Returns array[getNumCols()] specifying if a variable is integer.
bool setConstraintNumber(int number)
set the number of constraints.
Used to read an OSiL string.
bool bDeleteArrays
bDeleteArrays is true if we delete the arrays in garbage collection set to true by default ...
double getObjectiveOffset()
Returns array[getNumCols()] specifying if a variable is integer.
a sparse matrix data structure
SparseMatrix * getLinearConstraintCoefficientsInRowMajor()
Get linear constraint coefficients in row major.
OS_DipInterface()
class constructor
bool setObjectiveNumber(int number)
set the number of objectives.
OSOption * osoption
osoption holds the solver options in-memory as an OSOption object
OSoLReader * m_osolreader
The Default Solver Class.
bool addObjective(int index, std::string name, std::string maxOrMin, double constant, double weight, SparseVector *objectiveCoefficients)
add an objective.
std::string * getObjectiveMaxOrMins()
Get objective maxOrMins.
a sparse vector data structure
SparseMatrix * getLinearConstraintCoefficientsInColumnMajor()
Get linear constraint coefficients in column major.
OSOption * readOSoL(const std::string &osol)
parse the OSoL solver options.
bool setVariables(int number, std::string *names, double *lowerBounds, double *upperBounds, char *types)
set all the variable related elements.
double * values
values holds a double array of value elements in coefMatrix (AMatrix), which contains nonzero element...
OSInstance * osinstance
osinstance holds the problem instance in-memory as an OSInstance object
const double * getObjectiveConstants() const
Get objective constants.
std::set< int > getCoreConstraintIndexes()
Returns array[getNumCols()] specifying if a variable is integer.
int getConstraintNumber()
Get number of constraints.
std::string sSolverName
sSolverName is the name of the Coin solver used, e.g.
void readOSoL(std::string &filename)
Returns array[getNumCols()] specifying if a variable is integer.
std::vector< OSInstance * > getBlockOSInstances()
Returns array[getNumCols()] specifying if a variable is integer.
Used to read an OSoL string.
std::vector< std::map< int, int > > m_blockConstraintIndexes
Returns array[getNumCols()] specifying if a variable is integer.
std::vector< OSInstance * > m_blockOSInstances
Returns array[getNumCols()] specifying if a variable is integer.
std::vector< std::string > getBlockFactories()
Returns array[getNumCols()] specifying if a variable is integer.
Implements a solve method for the Coin solvers.
std::string getFileAsString(const char *fname)
read a file and return contents as a string.
int * starts
starts holds an integer array of start elements in coefMatrix (AMatrix), which points to the start of...
double * values
values holds a double array of nonzero values.
double * getVariableUpperBounds()
Get variable upper bounds.
const char * getIntegerColumns()
Returns array[getNumCols()] specifying if a variable is integer.
bool m_blockConstraintIndexesProcessed
Returns array[getNumCols()] specifying if a variable is integer.
int * indexes
indexes holds an integer array of indexes whose corresponding values are nonzero. ...
OSInstance * m_osinstance
int getNumberOfOtherVariableOptions()
Get the number of other variable options.
std::vector< std::string > m_blockFactories
Returns array[getNumCols()] specifying if a variable is integer.
bool setVariableNumber(int number)
set the number of variables.
The in-memory representation of an OSiL instance..
class used to make it easy to read and write files.
bool setConstraints(int number, std::string *names, double *lowerBounds, double *upperBounds, double *constants)
set all the constraint related elements.
std::set< int > m_coreConstraintIndexes
Returns array[getNumCols()] specifying if a variable is integer.
used for throwing exceptions.
bool m_blockFactoriesProcessed
Returns array[getNumCols()] specifying if a variable is integer.
std::map< int, std::vector< int > > generateInitialMaster()
Returns array[getNumCols()] specifying if a variable is integer.
std::vector< OtherVariableOption * > getOtherVariableOptions(std::string solver_name)
Get the <other> variable options associated with a particular solver.