#include #include #define IlcTraceDemons ((IlcUInt) 1) #define IlcTraceConstraint ((IlcUInt) 2) #define IlcTraceProcess ((IlcUInt) 4) #define IlcTraceVars ((IlcUInt) 8) #define IlcTraceFail ((IlcUInt) 16) #define IlcTraceNoEvent ((IlcUInt) 32) #define IlcTraceAllEvents ((IlcUInt) 31) /* a simple example of using a variable and value ordering heuristics simultaneously plus showing how to use the tracing facility of Solver 5.x */ ILOSTLBEGIN IlcChooseIndex1(MyChooseVar, var.getSize(), IlcIntVar) //this bit is for dynamically choosing variables to instantiate //in this particular realisation I choose SDF, smallest domain first //although there is a predefined selector, I code it up by hand //if need be, var.getSize() could be replaced with another criterion to be minimized. //There can even be 2 criteria, if IlcChooseIndex2, e.g., for Brelaz heuristic - //this could be realised using setObject() in each variable's "intestines". //That I use the tracing facility helps visualise the process of search. class mySelectI: public IlcIntSelectI { public: mySelectI(){} virtual IlcInt select(IlcIntVar var); }; // here is the fuction for dynamically selecting values of a chosen variable // in this particular realisation it is chosen randomly IlcInt mySelectI::select(IlcIntVar var) { IlcInt domSize = var.getSize(); IlcInt lowerBound = var.getMin(); return lowerBound + domSize*rand()/(RAND_MAX+1); } IlcIntSelect mySelect(IloSolver solver) { return new (solver.getHeap()) mySelectI(); } ILOCPGOALWRAPPER1(MyGenerate, solver, IloIntVarArray, vars) { return IlcGenerate(solver.getIntVarArray(vars), MyChooseVar,mySelect(solver)); } int main(int argc, char* argv[]){ int seed = atoi(argv[1]); srand(seed); IloEnv env; IloModel model(env); int sizeArr = 5; IloNumVarArray xArr(env, sizeArr); xArr[0] = IloNumVar (env,-3,50,ILOINT); xArr[0].setName("1"); xArr[1] = IloNumVar (env,-2,10,ILOINT); xArr[1].setName("2"); xArr[2] = IloNumVar (env,-1,3,ILOINT); xArr[2].setName("3"); xArr[3] = IloNumVar (env,-1,5,ILOINT); xArr[3].setName("4"); xArr[4] = IloNumVar (env,0,10,ILOINT); xArr[4].setName("5"); model.add(xArr); model.add(xArr[2]<=xArr[3]); model.add(xArr[0]<=xArr[2]+1); IloSolver solver(model); solver.setTraceMode(IlcTrue); //IlcPrintTrace trace(solver,IlcTraceVars | IlcTraceFail); IlcPrintTrace trace(solver,IlcTraceAllEvents); solver.setTrace(trace); IloGoal goal = MyGenerate(env, xArr); if (solver.solve(goal)) { for (int i=0;i