Skip to content
Snippets Groups Projects
Commit e4ce60d7 authored by Paul A. Rubin's avatar Paul A. Rubin
Browse files

Added a method to hot-start MIPModel.

parent 0c7658a3
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@ import ilog.cplex.IloCplex;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.OptionalInt;
import xmtrclusters.Problem;
/**
......@@ -229,4 +230,45 @@ public final class MIPModel {
}
return clusters;
}
/**
* Adds a hot start to the MIP.
* @param start an initial solution (collection of clusters)
* @throws IloException if CPLEX cannot process the starting solution
*/
public void hotStart(final Collection<Collection<Integer>> start)
throws IloException {
// Set initial values for the x variables (only).
int nT = problem.getNTrans();
double[][] xx = new double[nT][nT];
for (Collection<Integer> c : start) {
for (int t : c) {
for (int t1 : c) {
if (t < t1) {
xx[t][t1] = 1.0;
xx[t1][t] = 1.0;
}
}
}
// Make the smallest element of c the anchor.
OptionalInt m = c.stream().mapToInt(i -> i).min();
if (m.isPresent()) {
int mm = m.getAsInt();
xx[mm][mm] = 1.0;
}
}
// Flatten x and xx into vectors.
IloNumVar[] vars = new IloNumVar[nT * nT];
double[] vals = new double[nT * nT];
int index = 0;
for (int t = 0; t < nT; t++) {
for (int t1 = 0; t1 < nT; t1++) {
vars[index] = x[t][t1];
vals[index] = xx[t][t1];
index += 1;
}
}
// Add the MIP start.
mip.addMIPStart(vars, vals);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment