# What cplex function I have to use to write this variable?

I have a Dial a ride problem written in Java (cplex). Now i'm trying to write the relaxation. In the problem there is a binary variable xijk, that is 1 if the car k goes from i to j, 0 otherwise. If i want to know the total flow on every arc, i have to write: xij = sum k∈K xijk. How can i write correctly with cplex?

``````enter code here IloIntVar[][][] x = new IloIntVar[P][P][];
for (int i = 0; i < P; i++) {
for (int j = 0; j < P; j++) {
x[i][j] = cplex.boolVarArray(V);
for (int k = 0; k < V; k++) {
x[i][j][k].setName("x." + i + "." + j + "." + k);
}
}
}
``````

On

How to do that depends on whether you want to use the sum in another constraint or just want to get this sum in the result.

If you want to use the sum in another constraint then use `cplex.sum(x[i][j])`. That evaluates to an expression that is the sum of all variables in `x[i][j]`.

If you want to compute the value of this sum in a solution (after calling `cplex.solve()`) then do a loop like this:

``````double sum = 0.0;
for (double d : cplex.getValues(x[i][j])) sum += d;
``````

I am not sure why you mention "relaxation" in your question. However, if you want to create the relaxation of a model then you may want to look into the reference documentation of `IloCplex.conversion()`.