13
13
import com .graphhopper .util .EdgeIterator ;
14
14
import gurobi .*;
15
15
16
- import java .io .FileInputStream ;
17
- import java .io .FileNotFoundException ;
18
- import java .io .IOException ;
19
- import java .io .InputStream ;
20
16
import java .util .Arrays ;
21
- import java .util .Properties ;
22
17
23
18
public class Main {
24
19
25
- private static String GRAPH_FILE ;
26
- private static String GRAPH_FOLDER ;
27
- private static double MAX_COST ;
28
- private static double START_LAT ;
29
- private static double START_LON ;
20
+ private static Params params ;
30
21
private static int START_NODE_ID ;
31
- private static String VEHICLE ;
32
22
33
23
// Graph variables
34
24
private static GraphHopper hopper ;
@@ -103,7 +93,7 @@ private static void setupSolver() throws GRBException {
103
93
}
104
94
105
95
model .setObjective (objective , GRB .MAXIMIZE );
106
- model .addConstr (maxCost , GRB .LESS_EQUAL , MAX_COST , "max_cost" );
96
+ model .addConstr (maxCost , GRB .LESS_EQUAL , params . getMaxCost () , "max_cost" );
107
97
108
98
for (int i = 0 ; i < numNodes ; i ++) {
109
99
// (1d)
@@ -156,8 +146,9 @@ private static GRBVar getArc(EdgeIterator edge) {
156
146
}
157
147
158
148
private static void runSolver () throws GRBException {
159
- System .out .println ("Max cost: " + MAX_COST );
160
- System .out .println ("Start position: " + START_LAT + ", " + START_LON + " (Node " + START_NODE_ID + ")" );
149
+ System .out .println ("Max cost: " + params .getMaxCost ());
150
+ System .out .println ("Start position: " + params .getStartLat () + ", " + params .getStartLon () +
151
+ " (Node " + START_NODE_ID + ")" );
161
152
162
153
model .optimize ();
163
154
@@ -169,26 +160,25 @@ private static void runSolver() throws GRBException {
169
160
private static void loadOSM () {
170
161
System .out .println ("---- Starting GraphHopper ----" );
171
162
hopper = new GraphHopperOSM ();
172
- hopper .setDataReaderFile (GRAPH_FILE );
173
- hopper .setGraphHopperLocation (GRAPH_FOLDER );
163
+ hopper .setDataReaderFile (params . getGraphFile () );
164
+ hopper .setGraphHopperLocation (params . getGraphFolder () );
174
165
hopper .forDesktop ();
175
166
176
- EncodingManager encodingManager = new EncodingManager (VEHICLE );
167
+ EncodingManager encodingManager = new EncodingManager (params . getVehicle () );
177
168
hopper .setEncodingManager (encodingManager );
178
169
hopper .setCHEnabled (false );
179
170
hopper .importOrLoad ();
180
171
181
172
graph = hopper .getGraphHopperStorage ().getBaseGraph ();
182
- flagEncoder = encodingManager .getEncoder (VEHICLE );
173
+ flagEncoder = encodingManager .getEncoder (params . getVehicle () );
183
174
score = new BikePriorityWeighting (flagEncoder );
184
175
graphUtils = new GraphUtils (graph , flagEncoder );
185
176
186
- QueryResult result = hopper .getLocationIndex ().findClosest (START_LAT , START_LON ,
177
+ QueryResult result = hopper .getLocationIndex ().findClosest (params . getStartLat (), params . getStartLon () ,
187
178
new DefaultEdgeFilter (flagEncoder ));
188
179
if (!result .isValid ()) {
189
180
System .out .println ("Unable to find starting node near lat/lon points!" );
190
181
System .exit (1 );
191
-
192
182
}
193
183
194
184
START_NODE_ID = result .getClosestNode ();
@@ -206,29 +196,9 @@ private static void loadOSM() {
206
196
graph .getAllEdges ().getMaxId (), graph .getNodes (), nonTraversable , oneWay ));
207
197
}
208
198
209
- private static void loadParams () {
210
- Properties properties = new Properties ();
211
- InputStream inputStream = null ;
212
- try {
213
- inputStream = new FileInputStream ("src/main/resources/params.properties" );
214
- properties .load (inputStream );
215
- } catch (FileNotFoundException e ) {
216
- System .out .println ("No params file!" );
217
- e .printStackTrace ();
218
- } catch (IOException e ) {
219
- System .out .println ("Error reading params!" );
220
- e .printStackTrace ();
221
- }
222
- GRAPH_FILE = properties .getProperty ("graphFile" );
223
- GRAPH_FOLDER = properties .getProperty ("graphFolder" );
224
- START_LAT = Double .parseDouble (properties .getProperty ("startLat" ));
225
- START_LON = Double .parseDouble (properties .getProperty ("startLon" ));
226
- MAX_COST = Double .parseDouble (properties .getProperty ("maxCost" ));
227
- VEHICLE = properties .getProperty ("vehicle" );
228
- }
229
-
230
199
public static void main (String [] args ) {
231
- loadParams ();
200
+ params = new Params ();
201
+ params .loadParams ();
232
202
233
203
// Parse & Load Open Street Map data
234
204
loadOSM ();
0 commit comments