@@ -27,20 +27,19 @@ protected void callback() {
27
27
try {
28
28
if (where == GRB .CB_MIPSOL ) { // Found an integer feasible solution
29
29
30
- IntHashSet vertices = getReachableVertexSubset (START_NODE_ID );
31
- int verticesVisited = numVisitedVertices ();
30
+ IntHashSet visitedVertices = getReachableVertexSubset (START_NODE_ID );
31
+ int numVerticesInSolution = numVerticesInSolution ();
32
32
33
33
// If the number of vertices we can reach from the start is not the number of vertices we
34
34
// visit in the entire solution, we have a disconnected tour
35
- if (vertices .size () < verticesVisited ) {
36
- vertices .remove (START_NODE_ID );
35
+ if (visitedVertices .size () != numVerticesInSolution ) {
37
36
38
37
// Add sub-tour elimination constraint
39
38
GRBLinExpr subtourConstraint = new GRBLinExpr ();
40
39
int sumVertexVisits = 0 ;
41
40
int totalOutgoingEdges = 0 ;
42
41
43
- for (IntCursor cursor : vertices ) {
42
+ for (IntCursor cursor : visitedVertices ) {
44
43
int vertexId = cursor .value ;
45
44
EdgeIterator outgoing = graphUtils .outgoingEdges (vertexId );
46
45
@@ -64,7 +63,7 @@ protected void callback() {
64
63
}
65
64
}
66
65
67
- private int numVisitedVertices () throws GRBException {
66
+ private int numVerticesInSolution () throws GRBException {
68
67
double [] values = getSolution (vars .getVerts ());
69
68
70
69
int visited = 0 ;
@@ -73,7 +72,6 @@ private int numVisitedVertices() throws GRBException {
73
72
visited ++;
74
73
}
75
74
}
76
-
77
75
return visited ;
78
76
}
79
77
0 commit comments