OSDipBlockSlpSolver.cpp
Go to the documentation of this file.
1 /* $Id: OSBlockSlpSolver.cpp 3038 2009-11-07 11:43:44Z Gassmann $ */
15 #include "OSDipBlockSlpSolver.h"
16 #include "OSErrorClass.h"
17 #include "OSDataStructures.h"
18 
19 
20 
22  m_osinstance(NULL) {
23  std::cout << "INSIDE OSDipBlockCoinSolver CONSTRUCTOR" << std::endl;
24 }//end OSDipBlockSlpSolver
25 
26 
28 
29  try{
32 
33  } catch (const ErrorClass& eclass) {
34 
35  throw ErrorClass(eclass.errormsg);
36 
37  }
38 
39 }//end OSDipBlockSlpSolver
40 
42 
43  std::cout << "INSIDED ~OSDipBlockSlpSolver()" << std::endl;
44 
45 
46  std::vector<IndexValuePair*>::iterator vit;
47 
48  for (vit = m_primalVals.begin(); vit != m_primalVals.end(); vit++) {
49 
50  delete *vit;
51  }
52  //if(m_osrlreader != NULL) delete m_osrlreader;
53 }//end ~OSDipBlockSlpSolver
54 
55 void OSDipBlockSlpSolver::solve(double *cost, std::vector<IndexValuePair*> *solIndexValPair, double *optVal){
56 
57  try{
58  struct IndexValuePair *primalValPair;
59 
60  std::vector<IndexValuePair*>::iterator vit;
61 
62  for (vit = m_primalVals.begin(); vit != m_primalVals.end(); vit++) {
63 
64  delete *vit;
65  }
66  m_primalVals.clear();
67  //sum up negative coefficient
68  // -- critical -- we assume last variable is the y variable
69  // this is just for illustration
70  *optVal = 0;
71  for(int i = 0 ; i < m_numberOfVar - 1; i++){
72 
74  = cost[ i];
75 
76 
77  primalValPair = new IndexValuePair();
78 
79  primalValPair->value = 0.0;
80  primalValPair->idx = i;
81 
82  if (cost[ i] < 0){
83 
84  *optVal = *optVal + cost[ i];
85  primalValPair->value = 1.0;
86  }
87 
88  m_primalVals.push_back( primalValPair);
89 
90 
91  }//end for
92 
93  //now set the y variable to 1 if optVal is negative
94  //otherwise 0
95  primalValPair = new IndexValuePair();
96  primalValPair->idx = m_numberOfVar - 1;
97 
98  if(*optVal < 0){
99 
100  primalValPair->value = 1.0;
101  *optVal = *optVal + cost[ m_numberOfVar - 1];
102 
103  }else{
104 
105  primalValPair->value = 0.0;
106  }
107 
108  m_primalVals.push_back( primalValPair);
109 
110 
112  std::cout << m_osinstance->printModel( ) << std::endl;
113  //
114 
115  std::cout << "NUMBER OF VARIABLES m_primalVals = " << m_primalVals.size() << std::endl;
116 
117  for (vit = m_primalVals.begin(); vit != m_primalVals.end(); vit++) {
118 
119  //solIndexValPair.push_back( *vit);
120 
121  }
122 
123  *solIndexValPair = m_primalVals;
124  // the argument is the solution index
125 
126 
127  //solStatus = m_osresult->getSolutionStatusType( 0 );
128 
129  //std::cout << "SOLUTION STATUS " << solStatus << std::endl;
130  // if solStatus is optimal get the optimal solution value
131  //if( solStatus.find("ptimal") != string::npos ){
132  //first index is objIdx, second is solution index
133  // *optVal = m_osresult->getOptimalObjValue( -1, 0);
134  // *solIndexValPair = m_osresult->getOptimalPrimalVariableValues( 0);
135  //}else{
136  // throw ErrorClass("problem -- did not optimize a subproblem");
137  //}
138 
139  } catch (const ErrorClass& eclass) {
140 
141  throw ErrorClass(eclass.errormsg);
142 
143  }
144 
145 }//end solve
146 
147 
148 void OSDipBlockSlpSolver::solve(double *cost, std::string *osrl){
149 
150 
151  try{
152  //not implemented
153 
154  } catch (const ErrorClass& eclass) {
155 
156  throw ErrorClass(eclass.errormsg);
157 
158  }
159 
160 }//end solve
161 
double value
value is a double that holds the value of the entity
Definition: OSGeneral.h:638
int getVariableNumber()
Get number of variables.
std::string printModel()
Print the infix representation of the problem.
A commonly used structure holding an index-value pair.
Definition: OSGeneral.h:630
std::string errormsg
errormsg is the error that is causing the exception to be thrown
Definition: OSErrorClass.h:42
ObjCoef ** coef
coef is pointer to an array of ObjCoef object pointers
Definition: OSInstance.h:176
~OSDipBlockSlpSolver()
Default destructor.
OSDipBlockSlpSolver()
Default Constructor.
std::vector< IndexValuePair * > m_primalVals
bool bObjectivesModified
bObjectivesModified is true if the objective function data has been modified.
Definition: OSInstance.h:2293
double value
value is the value of the objective function coefficient corresponding to the variable with index idx...
Definition: OSInstance.h:128
int idx
idx holds the index of an entity (such as a variable, constraint, objective) that is part of a sparse...
Definition: OSGeneral.h:635
InstanceData * instanceData
A pointer to an InstanceData object.
Definition: OSInstance.h:2278
Objective ** obj
coef is pointer to an array of ObjCoef object pointers
Definition: OSInstance.h:205
Objectives * objectives
objectives is a pointer to a Objectives object
Definition: OSInstance.h:2188
The in-memory representation of an OSiL instance..
Definition: OSInstance.h:2262
OSInstance * osinstance
used for throwing exceptions.
Definition: OSErrorClass.h:31
virtual void solve(double *cost, std::vector< IndexValuePair * > *solIndexValPair, double *optVal)