Originally posted by: beratpostalci
cplex.addMinimize(expr);
//System.out.println(cplex.getModel());
Integer nOfVariables = 0;
boolean hasSubtour = false;
do {
if( cplex.solve() ) {
if ( cplex.getStatus().equals(IloCplex.Status.Optimal) ) {
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if( i != j ) {
if( cplex.getValue(x[i][j]) > 0 ) {
// Some operations here
}
}
}
}
hasSubtour = findSubTours(departureList, destinationList);
if(hasSubtour) {
if(nOfVariables > destinationList.size()) {
for(int i = 0; i < n; i++) {
IloLinearNumExpr tempExpr = cplex.linearNumExpr();
for(int j = 0; j < n; j++) {
if( i != j ) {
if( cplex.getValue(x[i][j]) == 1 ) {
tempExpr.addTerm(1.0,x[i][j]);
}
}
}
cplex.addEq(tempExpr, 1)
}
}
System.out.println(cplex.getModel());
}
}
} while(hasSubtour);
hasSubtour method controls if there are subtours and returns true or false.
#CPLEXOptimizers#DecisionOptimization