Skip to content

Commit d6e8ca8

Browse files
committed
Properly cleanup Gurobi and GraphHopper resources
1 parent 9440475 commit d6e8ca8

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,22 @@ public class Main {
2929
private static double START_LON;
3030
private static int START_NODE_ID;
3131
private static String VEHICLE;
32-
private static String ENABLED_VEHICLES;
3332

3433
// Graph variables
34+
private static GraphHopper hopper;
3535
private static Graph graph;
3636
private static GraphUtils graphUtils;
3737
private static Weighting score;
3838
private static FlagEncoder flagEncoder;
3939

40+
private static GRBEnv env;
4041
private static GRBModel model;
4142
private static GRBVar[] arcsFwd;
4243
private static GRBVar[] arcsBwd;
4344
private static int[] arcBaseIds;
4445

4546
private static void setupSolver() throws GRBException {
46-
GRBEnv env = new GRBEnv("osm.log");
47+
env = new GRBEnv("osm.log");
4748
model = new GRBModel(env);
4849

4950
AllEdgesIterator edges = graph.getAllEdges();
@@ -159,16 +160,20 @@ private static void runSolver() throws GRBException {
159160
System.out.println("Start position: " + START_LAT + ", " + START_LON + " (Node " + START_NODE_ID + ")");
160161

161162
model.optimize();
163+
164+
env.dispose();
165+
model.dispose();
166+
hopper.close();
162167
}
163168

164169
private static void loadOSM() {
165170
System.out.println("---- Starting GraphHopper ----");
166-
GraphHopper hopper = new GraphHopperOSM();
171+
hopper = new GraphHopperOSM();
167172
hopper.setDataReaderFile(GRAPH_FILE);
168173
hopper.setGraphHopperLocation(GRAPH_FOLDER);
169174
hopper.forDesktop();
170175

171-
EncodingManager encodingManager = new EncodingManager(ENABLED_VEHICLES);
176+
EncodingManager encodingManager = new EncodingManager(VEHICLE);
172177
hopper.setEncodingManager(encodingManager);
173178
hopper.setCHEnabled(false);
174179
hopper.importOrLoad();
@@ -220,10 +225,8 @@ private static void loadParams() {
220225
START_LON = Double.parseDouble(properties.getProperty("startLon"));
221226
MAX_COST = Double.parseDouble(properties.getProperty("maxCost"));
222227
VEHICLE = properties.getProperty("vehicle");
223-
ENABLED_VEHICLES = VEHICLE;
224228
}
225229

226-
227230
public static void main(String[] args) {
228231
loadParams();
229232

0 commit comments

Comments
 (0)