Originally posted by: valkiri
Thanks ol.
I understand how this code work . Now what can i do after to control the search.
Thanks.
ILCGOAL2(MyIntInstantiate, IlcIntVar, var, IlcIntSelectI*, select) {
if (var.isFixed()) return 0;
IlcInt val = (select) ? select->select(var) : var.getMin();
return IlcOr(var == val, IlcAnd(var != val, this));
}
ILCGOAL3(MyIntGenerate, IlcIntVarArray, vars, IlcChooseIntIndex, chooseIndex, IlcIntSelectI*, select){
IlcInt index = chooseIndex(vars);
if (index == -1) return 0;
return IlcAnd(MyIntInstantiate(getCP(), vars[index],select),this);
}
IlcGoal MyGenerate(const IlcIntVarArray array, IlcChooseIntIndex chooseIndex){
return MyIntGenerate(array.getCP(), array,chooseIndex,0);
}
IlcGoal MyGenerate(const IlcIntVarArray array, IlcChooseIntIndex chooseIndex, IlcIntSelect select){
return MyIntGenerate(array.getCP(), array, chooseIndex, select.getImpl());
}
ILOCPGOALWRAPPER1(NCSearch,cp, IloIntVarArray, x){
return MyGenerate( cp.getIntVarArray(x), IlcChooseFirstNonFixedInt, 0);
}
int main(){
IloEnv env;
IloIntVar x(env, -1, 3);
IloIntVar y(env, 2, 5);
IloIntVarArray array(env);
array.add(x);
array.add(y);
IloModel model(env);
model.add(array[0] >0);
model.add(array[1] <5);
model.add(array[0] <= array[1]);
model.add(IloMaximize(env,IloSum(array)));
IloCP cp(model);
if(cp.solve(NCSearch(env,array))){
cp.out() << "obj=" << cp.getObjValue() << endl;
cp.out() << "x1=" << cp.getValue(array[0]) << endl;
cp.out() << "x2=" << cp.getValue(array[1]) << endl;
}
env.end();
system("PAUSE");
return 0;
}
#CPOptimizer#DecisionOptimization