Reputation: 1
I am trying to solve a problem similar to the TSP with additional constraint (weight), I already wrote my code in Java, but I have a problem when compiling : This is my code :
package example01;
import ilog.concert.*;
import ilog.cplex.*;
import java.io.*;
import java.util.Arrays;
public class modele {
public static void solveme1 (){
int n = 5;
int [] W = {1,2,3,4,5};
int [][] distance = {
{ 0,14,10,12,20 },
{ 14,0,23,4,30 },
{ 10,23,0,25,18 },
{ 12,4,25,0,17 },
{ 20,30,18,17,0 },
};
try {
IloCplex cplex = new IloCplex();
//variables
IloNumVar[][] x = new IloNumVar[n][];
for (int i=0; i<n ; i++){
x[i] = cplex.boolVarArray(n);
}
IloNumVar [] time = cplex.numVarArray(n, 0, Double.MAX_VALUE);
// objective
IloLinearNumExpr obj = cplex.linearNumExpr();
for (int i =0; i<n; i++) {
obj.addTerm(time[i], W[i]);
}
cplex.addMinimize(obj);
//constraints
// Flux In
for (int j=0; j<n; j++){
IloLinearNumExpr expr = cplex.linearNumExpr();
for(int i=0; i<n; i++){
if (i!=j){
expr.addTerm(1.0,x[i][j]);
}
}
cplex.addEq(expr, 1);
}
// Flux Out
for (int j=0; j<n; j++){
IloLinearNumExpr expr = cplex.linearNumExpr();
for(int i=0; i<n; i++){
if (i!=j){
expr.addTerm(1.0,x[j][i]);
}
}
cplex.addEq(expr, 1);
}
// Starting at time =0
cplex.addEq(time[0],0);
// To force the starting from the location 0
for (int j=1; j<n; j++){
IloLinearNumExpr expr = cplex.linearNumExpr();
expr.addTerm(1.0,x[0][j]);
cplex.addEq(expr, 1);
}
// Constraint to determine the time in "J" after visiting "I"
for (int j=0; j<n;j++){
for (int i=0;i<n;i++){
if (i!=j){
cplex.addGe(time[j], cplex.sum(cplex.sum(time[i], cplex.prod(x[i][j],
distance[i][j])),cplex.prod(cplex.sum(x[i][j],-1),Double.MAX_VALUE)));
}
}
}
if (cplex.solve())
{
System.out.println("objective = "+cplex.getObjValue());
}
else {
System.out.println("Not solved");
}
cplex.end();
}
catch (IloException e){
e.printStackTrace();
}
}
}
The journal Log is as following :
"Column 'x2' set to infinite lower bound.
Presolve time = 0.00 sec. (0.01 ticks)
Root node processing (before b&c):
Real time = 0.00 sec. (0.01 ticks)
Parallel b&c, 8 threads:
Real time = 0.00 sec. (0.00 ticks)
Sync time (average) = 0.00 sec.
Wait time (average) = 0.00 sec.
Total (root+branch&cut) = 0.00 sec. (0.01 ticks)
Not solved"
Thank you in advance for your answers ! */
Upvotes: 0
Views: 509
Reputation: 1320
You state you have a problem when compiling. It seems to me you get a problem when running the program, and it's cplex telling you that the model is infeasible (a variable with an infinite lower bound doesn't sound feasible).
Upvotes: 1