1

I'm new to the world cp optimizer and this starting to make small tests. I have the following question and I need your help, please. This is my code:

Data

const IloInt nbPair = 6;
const IloInt nbPairElements = 15;
const IloInt nbElement = 2;
IloIntVarArray SolPair(env, nbPair,0,1);

IloIntArray PairCost(env, nbPair,100,150,200,300,350,133);

IloIntArray2 PairElements(env, nbPairElements);
PairElements[0] = IloIntArray(env, nbElement, 0,1);
PairElements[1] = IloIntArray(env, nbElement, 0,2);
PairElements[2] = IloIntArray(env, nbElement, 1,1);
PairElements[3] = IloIntArray(env, nbElement, 1,2);
PairElements[4] = IloIntArray(env, nbElement, 1,3);
PairElements[5] = IloIntArray(env, nbElement, 2,3);
PairElements[6] = IloIntArray(env, nbElement, 2,4);
PairElements[7] = IloIntArray(env, nbElement, 2,5);
PairElements[8] = IloIntArray(env, nbElement, 3,1);
PairElements[9] = IloIntArray(env, nbElement, 3,2);
PairElements[10] = IloIntArray(env, nbElement, 3,3);
PairElements[11] = IloIntArray(env, nbElement, 4,2);
PairElements[12] = IloIntArray(env, nbElement, 5,2);
PairElements[13] = IloIntArray(env, nbElement, 5,4);
PairElements[14] = IloIntArray(env, nbElement, 5,5);



// build model



//Objective
IloExpr Obj_Func_1(env);
for (int i = 0; i < nbPair; ++i)
    {
            Obj_Func_1 += PairCost[i] * SolPair[i];
    }
model.add(IloMinimize(env, Obj_Func_1));
Obj_Func_1.end();
IloCP cp(model);

.....

PairElements is the tuple [Par, element] and need to get the couple with the lowest cost with the following restriction::

- There should be a single time all elements.

I do not know how to create the restriction


the result is:

Par: 0 and 2.

because the two pair contain all the elements once and represented in lower cost

thank you very much Juan Carlos

Xavier Nodet
  • 5,033
  • 2
  • 37
  • 48

1 Answers1

0
  • There should be a single time all elements.

I don't understand your question.

To add constraints, you could try to set up an expression like this:

IloLinearIntExpr expr = this.model.linearIntExpr();
for (int j = 0; j < this.dim; j++) {
    if (i != j) {
       expr.addTerm(1, this.xVars[i][j]);
    }
}
this.model.addEq(expr, 1);

Where xVars denotes an array of IloIntVar initialized with model.boolVar("X0101")

If you want an inequality, just add it with this.model.addLe(expr,1);

Hope that helped you. Otherwise, try to explain your question a little bit better

Delfic
  • 167
  • 2
  • 15