Originally posted by: Torben-Ger-1988
Hey there,
i am trying to optimize a simple Form.
The picture shows you what i'd like to minimize.
Basicly there are two poissibilties how to do something. These possibilities are destribed with x_i
In different locations we have to check which possibility would be smaller. Therefor i added the letter "w".
y_i_w stands for the number of actings you got to do, to finish your work.
For excample:
Location A Possibilty 1: 300 actings
Locations A Possibilty 2: 350 actings
Location B Possibilty 1: 50 actings
Locations B Possibilty 2: 20 actings
I'd like to use the LP to Minimize the Problem. Therefor i added some constrains:
At the moment i entered my code like this:
My main Problem is how do i get my Data into the objective funktion??
for (int j = 0; j < w; w++) {
for (int k = 0; k < i; k++) {
Kapa.addTerm(1.0, y[j][k]);
Deci.addTerm(1.0, x[j][k]);
public static void solveMe() {
int i = 2; //possibilities
int w = 56; //locations
final double M = 99999999;
//model
try {
IloCplex cplex = new IloCplex();
IloNumVar[][] y = new IloNumVar[w][];
for (int j = 0; j < w; j++) {
y[j] = cplex.numVarArray(i, 0, Double.MAX_VALUE); //actings between 0 and max..
}
IloNumVar[][] x = new IloNumVar[w][];
for (int j = 0; j < w; j++) {
x[j] = cplex.boolVarArray(i); //xiw either 0 or 1
}
// Objective Function: Minimize Kapazität
IloLinearNumExpr Kapa = cplex.linearNumExpr ();
IloLinearNumExpr Deci = cplex.linearNumExpr();
for (int j = 0; j < w; w++) {
for (int k = 0; k < i; k++) {
Kapa.addTerm(1.0, y[j][k]);
Deci.addTerm(1.0, x[j][k]);
}
}
cplex.addMinimize(cplex.sum(Kapa, Deci));
//constraint between Xit and Yit
for (int j = 0; j < w; j++) {
for (int k = 0; k < w; k++)
{
cplex.addLe(y[j][k], cplex.prod(M, x[j][k]));
}
}
//solve model
cplex.solve();
//end
cplex.end();
} catch (IloException e) {
e.printStackTrace();
}
}
#CPLEXOptimizers#DecisionOptimization