Originally posted by: Abousedera
I have 3 resources and 4 cloud providers. I would like to know which provider is the cheapest one, for all products combined. Cplex can't find a solution because there is a problem with the constraints.
|
|
CP1
|
CP2
|
CP3
|
CP4
|
|
Resource1
|
10
|
20
|
25
|
30
|
|
Resource2
|
20
|
10
|
40
|
20
|
|
Resource3
|
25
|
10
|
30
|
10
|
|
Total Summation
|
55$
|
40$
|
95$
|
60$
|
The result of the is LP is "CP2" because it has minimum summation of the costs. I am not sure if the constraints are correct or not, because I don't get a solution at all.
Here is the mathematical model, where "r" is resources, "c" is cost, "p" is provider and "X" is decision variable
public static void model1(){
try{
//define model
IloCplex cplex = new IloCplex();
IloNumVar[][] x = new IloNumVar[m][];
for (int i=0; i<m; i++) {
x[i] = cplex.boolVarArray(n);
}
IloLinearNumExpr[] product = new IloLinearNumExpr[n];
IloLinearNumExpr[] OneProvider = new IloLinearNumExpr[n];
for (int i=0; i<m; i++) {
product[i] = cplex.linearNumExpr();
for (int j=0; j<m; j++) {
product[i].addTerm(1.0, x[i][j]);
}
}
for (int j=0; j<n; j++) {
OneProvider[j] = cplex.linearNumExpr();
for (int i=0; i<m; i++) {
OneProvider[j].addTerm(1.0, x[i][j]);
}
}
//Create objective function
IloLinearNumExpr objectivefunction = cplex.linearNumExpr();
for (int i=0; i<m; i++) {
for (int j=0; j<n; j++) {
objectivefunction.addTerm(costs[i][j],x[i][j]);
}
}
//Minimize objective function
cplex.addMinimize(objectivefunction);
// define constraints
for (int i=0; i<m; i++) {
for (int j=0; j<n; j++){
cplex.addEq((product[j]), 1); //first constraint
}
}
for (int j=0; j<m; j++) {
for (int i=0; i<n; i++){
cplex.addEq((OneProvider[i]), 3); //second constraint
}
}
//Display
cplex.setParam(IloCplex.Param.Simplex.Display, 0);
cplex.exportModel("aloha2.lp"); // solve
if (cplex.solve()) {
System.out.println("obj = "+cplex.getObjValue());
cplex.output().println("Solution status = " + cplex.getStatus());
}
else {
System.out.println("problem not solved");
}
cplex.end();
}
catch (IloException exc){
exc.printStackTrace();
}
}
#ConstraintProgramming-General#DecisionOptimization