Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. RoadMap(String inputFile) throws MapException {
  2. try {
  3. BufferedReader file = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile)));
  4.  
  5. scale = Integer.parseInt(file.readLine());
  6. start = Integer.parseInt(file.readLine());
  7. end = Integer.parseInt(file.readLine());
  8. width = Integer.parseInt(file.readLine());
  9. length = Integer.parseInt(file.readLine());
  10. initialBudget = Integer.parseInt(file.readLine());
  11. toll = Integer.parseInt(file.readLine());
  12. gain = Integer.parseInt(file.readLine());
  13.  
  14. size = length * width;
  15. graph = new Graph(size);
  16.  
  17. String line;
  18.  
  19. for (int row = 0; row < length * 2 - 1; row++) {
  20. line = file.readLine();
  21. for (int col = 0; col < width * 2 - 1; col++) {
  22. if (row % 2 == 0) {
  23. if (col % 2 != 0) {
  24. if (line.charAt(col) != 'X') {
  25. switch (line.charAt(col)) {
  26. case 'T':
  27. graph.insertEdge(graph.getNode((row / 2 * width) + (col - 1) / 2), graph.getNode((row / 2 * width) + (col + 1) / 2), 1);
  28. break;
  29. case 'C':
  30. graph.insertEdge(graph.getNode((row / 2 * width) + (col - 1) / 2), graph.getNode((row / 2 * width) + (col + 1) / 2), -1);
  31. break;
  32. case 'F':
  33. graph.insertEdge(graph.getNode((row / 2 * width) + (col - 1) / 2), graph.getNode((row / 2 * width) + (col + 1) / 2), 0);
  34. break;
  35. }
  36. }
  37. }
  38. } else {
  39. if (col % 2 == 0) {
  40. if (line.charAt(col) != 'X') {
  41. switch (line.charAt(col)) {
  42. case 'T':
  43. graph.insertEdge(graph.getNode(((row - 1) / 2 * width) + col / 2), graph.getNode(((row + 1) / 2 * width) + col / 2), 1);
  44. break;
  45. case 'C':
  46. graph.insertEdge(graph.getNode(((row - 1) / 2 * width) + col / 2), graph.getNode(((row + 1) / 2 * width) + col / 2), -1);
  47. break;
  48. case 'F':
  49. graph.insertEdge(graph.getNode(((row - 1) / 2 * width) + col / 2), graph.getNode(((row + 1) / 2 * width) + col / 2), 0);
  50. break;
  51. }
  52. }
  53. }
  54. }
  55. }
  56. }
  57. file.close();
  58. } catch (Exception e) {
  59. throw new MapException("The specified input file does not exist.");
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement