1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#include <ilsolver/ilcint.h>
#ifdef ILUSESTL
#include <iostream>
#else
#include <iostream.h>
#endif
#include <ilopl/oplcomponent.h>
#include <ilopl/oplerror.h>
ILCSTLBEGIN
class MyReporter : public OPLerrorReporter {
void notifySyntaxError(const OPLsyntaxError& err){
cout << "OPL syntax error near line "
<< err.getLine() << " : "
<< err.getMessage() << endl;
}
void notifySemanticError(const OPLsemanticError& err){
cout << "OPL semantic error near line "
<< err.getLine() << " : "
<< err.getMessage() << endl;
}
void notifyRuntimeError(const OPLruntimeError& err){
cout << "OPL runtime error near line "
<< err.getLine() << " : "
<< err.getMessage() << endl;
}
void notifyInternalError(const OPLinternalError& err){
cout << "OPL internal error : "
<< err.getMessage() << endl;
}
};
int main(){
int status = 0;
OPLsolver solver;
MyReporter reporter;
solver.setErrorReporter(&reporter);
try{
solver.loadInterpretedModelFileAndDataFile
("d:\ILOG\OPLSl37\opl\scheduler\bridge.mod",
"d:\ILOG\OPLSl37\opl\scheduler\bridge.dat", 1);
if(solver.solve()){
int obj = solver.getObjectiveValueInt();
double time = solver.getTime();
cout << "\nObjective: " << obj << endl;
cout << "Time: " << time << endl << endl;
OPLenum task = solver.getEnum("Task");
int nbTasks = task.getCard();
OPLarray activities = solver.getArray("a");
OPLenumIterator ite = task.getIterator();
for(; ite.ok() == 1; ite.next()) {
OPLenumValue c = ite.get();
OPLactivity act = activities.getActivity(c);
cout << "Activity '" << c.getName() << "'";
cout << " starts at " << act.getStart();
cout << " with duration " << act.getDuration() << endl;
}
}else {
cout << "No solution found" << endl;
}
}
catch(...){
cout << "An error occurred" << endl;
status = -1;
}
solver.close();
return status;
} |
Partager