11
11
import com .graphhopper .storage .Graph ;
12
12
import com .graphhopper .storage .index .QueryResult ;
13
13
import com .graphhopper .util .EdgeIterator ;
14
- import com .graphhopper .util .shapes .GHPoint ;
15
14
import gurobi .*;
16
15
16
+ import java .io .FileInputStream ;
17
+ import java .io .FileNotFoundException ;
18
+ import java .io .IOException ;
19
+ import java .io .InputStream ;
17
20
import java .util .Arrays ;
21
+ import java .util .Properties ;
18
22
19
23
public class Main {
20
24
21
- // TODO (Aidan) Read these params from file
22
- private static final int MAX_COST = 40_000 ; // In meters
23
- private static final int MIN_COST = 20_000 ; // In meters
24
- private static final GHPoint START_POSITION = new GHPoint (43.009449 , -74.006824 );
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 ;
25
30
private static int START_NODE_ID ;
26
- private static final String RACE_BIKE_VEHICLE = "racingbike" ;
27
- private static final String ENABLED_VEHICLES = RACE_BIKE_VEHICLE ;
31
+ private static String VEHICLE ;
32
+ private static String ENABLED_VEHICLES ;
28
33
29
34
// Graph variables
30
35
private static Graph graph ;
@@ -151,16 +156,16 @@ private static GRBVar getArc(EdgeIterator edge) {
151
156
152
157
private static void runSolver () throws GRBException {
153
158
System .out .println ("Max cost: " + MAX_COST );
154
- System .out .println ("Start position: " + START_POSITION + " (Node " + START_NODE_ID + ")" );
159
+ System .out .println ("Start position: " + START_LAT + ", " + START_LON + " (Node " + START_NODE_ID + ")" );
155
160
156
161
model .optimize ();
157
162
}
158
163
159
164
private static void loadOSM () {
160
165
System .out .println ("---- Starting GraphHopper ----" );
161
166
GraphHopper hopper = new GraphHopperOSM ();
162
- hopper .setDataReaderFile ("src/main/resources/ny_capital_district.pbf" );
163
- hopper .setGraphHopperLocation ("src/main/resources/ny_capital_district-gh/" );
167
+ hopper .setDataReaderFile (GRAPH_FILE );
168
+ hopper .setGraphHopperLocation (GRAPH_FOLDER );
164
169
hopper .forDesktop ();
165
170
166
171
EncodingManager encodingManager = new EncodingManager (ENABLED_VEHICLES );
@@ -169,11 +174,11 @@ private static void loadOSM() {
169
174
hopper .importOrLoad ();
170
175
171
176
graph = hopper .getGraphHopperStorage ().getBaseGraph ();
172
- flagEncoder = encodingManager .getEncoder (RACE_BIKE_VEHICLE );
177
+ flagEncoder = encodingManager .getEncoder (VEHICLE );
173
178
score = new BikePriorityWeighting (flagEncoder );
174
179
graphUtils = new GraphUtils (graph , flagEncoder );
175
180
176
- QueryResult result = hopper .getLocationIndex ().findClosest (START_POSITION . lat , START_POSITION . lon ,
181
+ QueryResult result = hopper .getLocationIndex ().findClosest (START_LAT , START_LON ,
177
182
new DefaultEdgeFilter (flagEncoder ));
178
183
if (!result .isValid ()) {
179
184
System .out .println ("Unable to find starting node near lat/lon points!" );
@@ -196,7 +201,32 @@ private static void loadOSM() {
196
201
graph .getAllEdges ().getMaxId (), graph .getNodes (), nonTraversable , oneWay ));
197
202
}
198
203
204
+ private static void loadParams () {
205
+ Properties properties = new Properties ();
206
+ InputStream inputStream = null ;
207
+ try {
208
+ inputStream = new FileInputStream ("src/main/resources/params.properties" );
209
+ properties .load (inputStream );
210
+ } catch (FileNotFoundException e ) {
211
+ System .out .println ("No params file!" );
212
+ e .printStackTrace ();
213
+ } catch (IOException e ) {
214
+ System .out .println ("Error reading params!" );
215
+ e .printStackTrace ();
216
+ }
217
+ GRAPH_FILE = properties .getProperty ("graphFile" );
218
+ GRAPH_FOLDER = properties .getProperty ("graphFolder" );
219
+ START_LAT = Double .parseDouble (properties .getProperty ("startLat" ));
220
+ START_LON = Double .parseDouble (properties .getProperty ("startLon" ));
221
+ MAX_COST = Double .parseDouble (properties .getProperty ("maxCost" ));
222
+ VEHICLE = properties .getProperty ("vehicle" );
223
+ ENABLED_VEHICLES = VEHICLE ;
224
+ }
225
+
226
+
199
227
public static void main (String [] args ) {
228
+ loadParams ();
229
+
200
230
// Parse & Load Open Street Map data
201
231
loadOSM ();
202
232
@@ -210,5 +240,4 @@ public static void main(String[] args) {
210
240
e .getMessage ());
211
241
}
212
242
}
213
-
214
243
}
0 commit comments