Skip to content

Commit f9e5b27

Browse files
committed
Rename variables in SubtourConstraint
1 parent 0a8a23c commit f9e5b27

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ private static void runSolver() throws GRBException {
115115
System.out.println("Start position: " + params.getStartLat() + ", " + params.getStartLon() +
116116
" (Node " + START_NODE_ID + ")");
117117

118+
// model.set(GRB.IntParam.LogToConsole, 0);
118119
model.optimize();
119120

120121
env.dispose();

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,19 @@ protected void callback() {
2727
try {
2828
if(where == GRB.CB_MIPSOL) { // Found an integer feasible solution
2929

30-
IntHashSet vertices = getReachableVertexSubset(START_NODE_ID);
31-
int verticesVisited = numVisitedVertices();
30+
IntHashSet visitedVertices = getReachableVertexSubset(START_NODE_ID);
31+
int numVerticesInSolution = numVerticesInSolution();
3232

3333
// If the number of vertices we can reach from the start is not the number of vertices we
3434
// 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) {
3736

3837
// Add sub-tour elimination constraint
3938
GRBLinExpr subtourConstraint = new GRBLinExpr();
4039
int sumVertexVisits = 0;
4140
int totalOutgoingEdges = 0;
4241

43-
for(IntCursor cursor : vertices) {
42+
for(IntCursor cursor : visitedVertices) {
4443
int vertexId = cursor.value;
4544
EdgeIterator outgoing = graphUtils.outgoingEdges(vertexId);
4645

@@ -64,7 +63,7 @@ protected void callback() {
6463
}
6564
}
6665

67-
private int numVisitedVertices() throws GRBException {
66+
private int numVerticesInSolution() throws GRBException {
6867
double[] values = getSolution(vars.getVerts());
6968

7069
int visited = 0;
@@ -73,7 +72,6 @@ private int numVisitedVertices() throws GRBException {
7372
visited++;
7473
}
7574
}
76-
7775
return visited;
7876
}
7977

0 commit comments

Comments
 (0)