8
8
import gurobi .*;
9
9
10
10
import java .util .Arrays ;
11
+ import java .util .concurrent .TimeUnit ;
12
+
13
+ import static gurobi .GRB .Callback .RUNTIME ;
11
14
12
15
public class SubtourConstraint extends GRBCallback {
13
16
14
17
private final int START_NODE_ID ;
15
18
private GraphUtils graphUtils ;
16
19
private Vars vars ;
20
+ private double time = 0 ;
17
21
18
22
SubtourConstraint (Vars vars , int startNodeId , GraphUtils graphUtils ) {
19
23
this .vars = vars ;
@@ -25,7 +29,7 @@ public class SubtourConstraint extends GRBCallback {
25
29
protected void callback () {
26
30
try {
27
31
if (where == GRB .CB_MIPSOL ) { // Found an integer feasible solution
28
-
32
+ long start = System . nanoTime ();
29
33
IntHashSet solutionVertices = getSolutionVertices ();
30
34
IntHashSet visitedVertices = getReachableVertexSubset (START_NODE_ID );
31
35
@@ -62,10 +66,20 @@ protected void callback() {
62
66
}
63
67
64
68
double rhs = ((double ) sumVertexVisits ) / ((double ) totalOutgoingEdges );
65
- System .out .println ("adding lazy constraint! " + lhs + " >= " + rhs );
69
+ // System.out.println("adding lazy constraint! " + lhs + " >= " + rhs);
66
70
addLazy (subtourConstraint , GRB .GREATER_EQUAL , rhs );
67
71
68
72
}
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
+ }
69
83
}
70
84
} catch (GRBException e ) {
71
85
System .out .println ("Error code: " + e .getErrorCode () + ". " +
0 commit comments