Reputation: 153
I'm using Cplex in Java and want to minimize the sum of the products of elements from two matrices (products of elements with the same index).
x[n][n] contains decisionvariables [0, 1]
cost[n][n] contains the cost for the way from i to j
I want to minimize the sum of costs x[i][j] * j[i][j] for all i..n; j..n.
I created the variables like this:
[...]
static double lb = 0.0;
static double ub = 1.0;
static double cost[][] = new double[n][n];
IloNumVar[][] x = new IloNumVar[n][n];
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
x[i][j] = cplex.numVar(lb, ub);
}
}
My Problem is that I don't know how to create the minimize part.
I found something that seems to be very similar to my problem (Cplex c++ multidimensional decision variable) but as I am not familiar to c++, I don't get any solution out of it.
Upvotes: 1
Views: 860
Reputation: 2641
This should do it:
IloLinearNumExpr obj = cplex.linearNumExpr();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
obj.addTerm(cost[i][j], x[i][j]);
}
}
cplex.addMinimize(obj);
Upvotes: 2