Skip to content

Commit ed28e3e

Browse files
committed
Add simple lazy constraint profiling code
1 parent 2372862 commit ed28e3e

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/main/java/io/github/plastix/SubtourConstraint.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
import gurobi.*;
99

1010
import java.util.Arrays;
11+
import java.util.concurrent.TimeUnit;
12+
13+
import static gurobi.GRB.Callback.RUNTIME;
1114

1215
public class SubtourConstraint extends GRBCallback {
1316

1417
private final int START_NODE_ID;
1518
private GraphUtils graphUtils;
1619
private Vars vars;
20+
private double time = 0;
1721

1822
SubtourConstraint(Vars vars, int startNodeId, GraphUtils graphUtils) {
1923
this.vars = vars;
@@ -25,7 +29,7 @@ public class SubtourConstraint extends GRBCallback {
2529
protected void callback() {
2630
try {
2731
if(where == GRB.CB_MIPSOL) { // Found an integer feasible solution
28-
32+
long start = System.nanoTime();
2933
IntHashSet solutionVertices = getSolutionVertices();
3034
IntHashSet visitedVertices = getReachableVertexSubset(START_NODE_ID);
3135

@@ -62,10 +66,20 @@ protected void callback() {
6266
}
6367

6468
double rhs = ((double) sumVertexVisits) / ((double) totalOutgoingEdges);
65-
System.out.println("adding lazy constraint! " + lhs + " >= " + rhs);
69+
// System.out.println("adding lazy constraint! " + lhs + " >= " + rhs);
6670
addLazy(subtourConstraint, GRB.GREATER_EQUAL, rhs);
6771

6872
}
73+
74+
long end = System.nanoTime();
75+
time += TimeUnit.NANOSECONDS.toSeconds(end - start);
76+
77+
double solverTime = getDoubleInfo(RUNTIME);
78+
if(solverTime > 600) {
79+
System.out.println(String.format("Lazy constraint time: %f s", time));
80+
System.out.println(String.format("Gurobi wall time: %f s", solverTime));
81+
System.exit(0);
82+
}
6983
}
7084
} catch(GRBException e) {
7185
System.out.println("Error code: " + e.getErrorCode() + ". " +

0 commit comments

Comments
 (0)