16 #include <cppad/cppad.hpp>
34 #include "OSInstance.h"
56 cout <<
"Start Building the Model" << endl;
82 osinstance->
addObjective(-1,
"objfunction",
"max", 0.0, 1.0, objcoeff);
97 double *
values =
new double[ 8];
98 int *indexes =
new int[ 8];
99 int *starts =
new int[ 5];
121 cout <<
"Call setLinearConstraintCoefficients" << endl;
123 indexes, 0, 7, starts, 0, 4);
124 cout <<
"End Building the Model" << endl;
129 osil = osilwriter->
writeOSiL( osinstance);
135 osagent =
new OSSolverAgent(
"http://74.94.100.129:8080/OSServer/services/OSSolverService");
138 std::string osol =
"<osol></osol>";
139 cout <<
"Solve the model synchronously" << endl;
140 cout <<
"osil input:" << endl << endl;
141 cout << osil << endl << endl;
142 std::string osrl =
"" ;
143 osrl = osagent->
solve(osil, osol);
144 cout <<
"osrl result from osagent:" << endl << endl;
145 cout << osrl << endl << endl;
149 cout <<
"Now solve the problem in asynchronous mode" << endl;
150 cout <<
"get the jobID" << endl;
151 std::string jobID = osagent->
getJobID(
"");
152 cout << jobID << endl << endl;
156 osol =
"<osol><general><jobID>" + jobID +
"</jobID></general></osol>";
157 cout <<
"submit the problem" << endl;
158 bool sent = osagent->
send(osil, osol);
159 cout <<
"problem submitted; success?" << sent << endl << endl;
160 std::string ospl =
"<ospl><processHeader><request action=\"getAll\"/></processHeader><processData/></ospl>";
161 cout <<
"Enquire about job status" << endl << endl;
162 std::string osql = osagent->
knock(ospl, osol);
163 cout <<
"Result of knock {} method:" << endl << osql << endl << endl;
166 cout <<
"Parse the result" << endl << endl;
167 bool status_finished =
false;
168 bool status_found =
false;
170 std::string::size_type pos1;
171 std::string::size_type pos2;
172 pos1 = osql.find(
"<response" );
173 if (pos1 != std::string::npos){
174 pos2 = osql.find(
">", pos1 + 1);
175 if (pos2 != std::string::npos){
176 pos1 = osql.find(
"status", pos1 + 1);
177 if (pos1 != std::string::npos){
178 pos1 = osql.find(
"=", pos1 + 1);
179 if (pos1 != std::string::npos){
181 pos1 = osql.find(
"finished", pos1 + 1);
182 if (pos1 != std::string::npos){
184 status_finished =
true;
188 status_finished =
false;
196 if (status_finished){
197 cout <<
"process finished; retrieve results" << endl;
199 cout << osrl << endl << endl;
202 cout <<
"process still running; kill it!" << endl;
203 osrl = osagent->
kill(osol);
204 cout << osrl << endl << endl;
208 cout <<
"Improperly formed string" << endl;
219 cout <<
"Done with garbage collection" << endl;
220 cout <<
"Program terminates normally" << endl;
226 std::cout << eclass.
errormsg << std::endl;
Used by a client to invoke a remote solver.
bool addVariable(int index, std::string name, double lowerBound, double upperBound, char type)
add a variable.
std::string retrieve(std::string osol)
implement the retrieve() method which is a virtual function in OShL
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
bool send(std::string osil, std::string osol)
implement the send() method which is a virtual function in OShL
std::string errormsg
errormsg is the error that is causing the exception to be thrown
int main(int argc, char *argv[])
std::string solve(std::string osil, std::string osol)
implement the solve() method which is a virtual function in OShL, this is synchronous ...
bool setConstraintNumber(int number)
set the number of constraints.
bool bDeleteArrays
bDeleteArrays is true if we delete the arrays in garbage collection set to true by default ...
bool setObjectiveNumber(int number)
set the number of objectives.
bool addConstraint(int index, std::string name, double lowerBound, double upperBound, double constant)
add a constraint.
bool addObjective(int index, std::string name, std::string maxOrMin, double constant, double weight, SparseVector *objectiveCoefficients)
add an objective.
a sparse vector data structure
std::string knock(std::string ospl, std::string osol)
implement the knock() method which is a virtual function in OShL
bool setInstanceSource(std::string source)
set the instance source.
bool setInstanceDescription(std::string description)
set the instance description.
std::string writeOSiL(const OSInstance *theosinstance)
create an osil string from an OSInstance object
double * values
values holds a double array of nonzero values.
std::string kill(std::string osol)
implement the kill() method which is a virtual function in OShL
std::string getJobID(std::string osol)
implement the getJobID() method which is a virtual function in OShL
int * indexes
indexes holds an integer array of indexes whose corresponding values are nonzero. ...
bool setVariableNumber(int number)
set the number of variables.
The in-memory representation of an OSiL instance..
used for throwing exceptions.
Take an OSInstance object and write a string that validates against the OSiL schema.