Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RoadMap(String inputFile) throws MapException {
- try {
- BufferedReader file = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile)));
- scale = Integer.parseInt(file.readLine());
- start = Integer.parseInt(file.readLine());
- end = Integer.parseInt(file.readLine());
- width = Integer.parseInt(file.readLine());
- length = Integer.parseInt(file.readLine());
- initialBudget = Integer.parseInt(file.readLine());
- toll = Integer.parseInt(file.readLine());
- gain = Integer.parseInt(file.readLine());
- size = length * width;
- graph = new Graph(size);
- String line;
- for (int row = 0; row < length * 2 - 1; row++) {
- line = file.readLine();
- for (int col = 0; col < width * 2 - 1; col++) {
- if (row % 2 == 0) {
- if (col % 2 != 0) {
- if (line.charAt(col) != 'X') {
- switch (line.charAt(col)) {
- case 'T':
- graph.insertEdge(graph.getNode((row / 2 * width) + (col - 1) / 2), graph.getNode((row / 2 * width) + (col + 1) / 2), 1);
- break;
- case 'C':
- graph.insertEdge(graph.getNode((row / 2 * width) + (col - 1) / 2), graph.getNode((row / 2 * width) + (col + 1) / 2), -1);
- break;
- case 'F':
- graph.insertEdge(graph.getNode((row / 2 * width) + (col - 1) / 2), graph.getNode((row / 2 * width) + (col + 1) / 2), 0);
- break;
- }
- }
- }
- } else {
- if (col % 2 == 0) {
- if (line.charAt(col) != 'X') {
- switch (line.charAt(col)) {
- case 'T':
- graph.insertEdge(graph.getNode(((row - 1) / 2 * width) + col / 2), graph.getNode(((row + 1) / 2 * width) + col / 2), 1);
- break;
- case 'C':
- graph.insertEdge(graph.getNode(((row - 1) / 2 * width) + col / 2), graph.getNode(((row + 1) / 2 * width) + col / 2), -1);
- break;
- case 'F':
- graph.insertEdge(graph.getNode(((row - 1) / 2 * width) + col / 2), graph.getNode(((row + 1) / 2 * width) + col / 2), 0);
- break;
- }
- }
- }
- }
- }
- }
- file.close();
- } catch (Exception e) {
- throw new MapException("The specified input file does not exist.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement