- Timestamp:
- 10/10/2017 12:07:14 PM (9 years ago)
- Location:
- trunk/src
- Files:
-
- 6 edited
-
atmsdriver/ATMSDriver.java (modified) (1 diff)
-
atmsdriver/model/FEPLine.java (modified) (1 diff)
-
atmsdriver/model/Highway.java (modified) (2 diffs)
-
atmsdriver/model/Highways.java (modified) (4 diffs)
-
atmsdriver/model/Station.java (modified) (1 diff)
-
tmcsim/application.properties (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/atmsdriver/ATMSDriver.java
r87 r88 78 78 .getProperty(PROPERTIES.EXCHANGE_FILE_NAME.name)); 79 79 80 System.out.println(highways.toXML());81 80 highways.writeToFEP(); 82 81 // Update if exchangeInfo is recieved -
trunk/src/atmsdriver/model/FEPLine.java
r87 r88 40 40 this.globalSeq = globalSeq; 41 41 this.scheduleSeq = scheduleSeq; 42 } 43 44 public int getLineNumber() 45 { 46 return this.lineNum; 47 } 48 49 public List<Station> getStations() 50 { 51 return this.stations; 42 52 } 43 53 -
trunk/src/atmsdriver/model/Highway.java
r87 r88 1 1 package atmsdriver.model; 2 2 3 import atmsdriver.model.Station.DIRECTION; 3 4 import java.util.ArrayList; 4 5 import java.util.Collections; … … 9 10 */ 10 11 class Highway { 12 11 13 final private ArrayList<Station> stations; 14 final private Integer highwayNumber; 15 final private DIRECTION direction; 12 16 13 public Highway( ArrayList<FEPLine> lines, int highway)17 public Highway(Integer highwayNum, DIRECTION direction, ArrayList<Station> stations) 14 18 { 15 stations = new ArrayList<Station>(); 16 loadHighwayStations(lines); 17 } 18 19 private void loadHighwayStations(ArrayList<FEPLine> lines) 20 { 21 Collections.sort(stations); 19 this.highwayNumber = highwayNum; 20 this.direction = direction; 21 this.stations = stations; 22 22 } 23 23 } -
trunk/src/atmsdriver/model/Highways.java
r87 r88 12 12 import java.net.Socket; 13 13 import java.util.ArrayList; 14 import java.util.Collections; 15 import java.util.Enumeration; 16 import java.util.Hashtable; 17 import java.util.Map; 14 18 import java.util.Scanner; 19 import java.util.Set; 15 20 import java.util.logging.Level; 16 21 import java.util.logging.Logger; … … 27 32 /** 28 33 * 29 * @author andrew34 * @author John A. Torres 30 35 */ 31 36 public class Highways { … … 34 39 final private String FEPHostName; 35 40 final private int FEPPortNum; 41 final private ArrayList<Highway> highways; 36 42 37 43 // NEED FINISH final private ArrayList<Highway> highways; 38 39 public Highways(String ldsFileName, String loopsFileName, 44 public Highways(String ldsFileName, String loopsFileName, 40 45 String highwayMetaFileName, String FEPHostName, int FEPPortNum) { 41 46 /* 42 lines = loadLines(highwayMetaFileName);43 System.out.println("SIZE: " + toXML().toCharArray().length);44 */45 47 lines = loadLines(highwayMetaFileName); 48 System.out.println("SIZE: " + toXML().toCharArray().length); 49 */ 50 46 51 NetworkLoader ldr = new NetworkLoader(new File(ldsFileName), new File(loopsFileName)); 47 52 this.lines = (ArrayList<FEPLine>) ldr.getFEPLines(); 48 53 this.FEPHostName = FEPHostName; 49 54 this.FEPPortNum = FEPPortNum; 50 // NEED FINISHthis.highways = loadHighways();55 this.highways = loadHighways(); 51 56 //writeHighwaysMeta("hard.txt"); 52 57 } 58 53 59 54 // NEED FINISH 55 private void loadHighways() 56 { 60 private ArrayList<Highway> loadHighways() { 61 System.out.println("Loading highways..."); 62 ArrayList<Highway> highways = new ArrayList<Highway>(); 63 Hashtable<Hashtable<Integer, DIRECTION>, ArrayList<Station>> 64 highwayTable = new Hashtable<>(); 57 65 58 //highways.add(new Highway(lines, )); 66 for (FEPLine line : lines) 67 { 68 ArrayList<Station> lineStations = (ArrayList<Station>) line.getStations(); 69 for(Station station : lineStations) 70 { 71 Integer hwyNum = station.getHighwayNumber(); 72 DIRECTION dir = station.getDirection(); 73 Hashtable<Integer, DIRECTION> check = new Hashtable<>(); 74 check.put(hwyNum, dir); 75 if(highwayTable.get(check) == null) 76 { 77 ArrayList<Station> stnList = new ArrayList<>(); 78 stnList.add(station); 79 Hashtable<Hashtable<Integer, DIRECTION>, ArrayList<Station>> 80 newEntry = new Hashtable(); 81 newEntry.put(check, stnList); 82 highwayTable.putAll(newEntry); 83 } 84 else 85 { 86 highwayTable.get(check).add(station); 87 } 88 } 89 } 59 90 60 } 61 /* 62 private ArrayList<FEPLine> loadLines(String highwayMetaFileName) { 63 ArrayList<FEPLine> lines = new ArrayList<>(); 64 try { 65 Scanner sc = new Scanner(new File(highwayMetaFileName)); 66 String firstLine = sc.nextLine(); 67 68 Scanner linesc = new Scanner(firstLine); 69 int numLines = linesc.nextInt(); 70 linesc.close(); 71 72 for (int i = 0; i < numLines; i++) { 73 System.out.println("CURR: " + i); 74 lines.add(loadLine(sc)); 75 } 76 sc.close(); 77 78 } catch (FileNotFoundException ex) { 79 Logger.getLogger(Highways.class.getName()).log(Level.SEVERE, null, ex); 80 } 81 return lines; 82 } 83 84 private FEPLine loadLine(Scanner sc) { 85 String line = sc.nextLine(); 86 System.out.println(line); 87 Scanner scline = new Scanner(line); 88 89 int lineNum = scline.nextInt(); 90 int count = scline.nextInt(); 91 int numStations = scline.nextInt(); 92 ArrayList<Station> stations = new ArrayList<>(); 93 for (int i = 0; i < numStations; i++) { 94 stations.add(loadStation(sc, lineNum)); 95 } 96 97 return new FEPLine(lineNum, stations, count); 98 } 99 100 private Station loadStation(Scanner sc, int lineNum) { 101 String line = sc.nextLine(); 102 System.out.println(line); 103 Scanner scline = new Scanner(line); 104 int ldsID = scline.nextInt(); 105 int drop = scline.nextInt(); 106 int fwy = scline.nextInt(); 107 DIRECTION dir = DIRECTION.getEnum(scline.next()); 108 double postmile = scline.nextDouble(); 109 int numLoops = scline.nextInt(); 110 String location = getStationLoc(line); 111 ArrayList<LoopDetector> loops = new ArrayList<>(); 112 for (int i = 0; i < numLoops; i++) { 113 loops.add(loadLoop(sc)); 114 } 115 116 return new Station(lineNum, ldsID, drop, location, loops, fwy, dir, postmile); 117 } 118 119 private LoopDetector loadLoop(Scanner sc) { 120 String line = sc.nextLine(); 121 Scanner scline = new Scanner(line); 122 123 int loopID = scline.nextInt(); 124 int laneNum = scline.nextInt(); 125 String loopLoc = getLoopLoc(line); // NEED GET LOOPLOC 126 scline.close(); 127 return new LoopDetector(loopID, loopLoc, laneNum); 128 } 129 130 private String getLoopLoc(String line) { 131 Scanner sc = new Scanner(line); 132 sc.nextInt(); 133 sc.nextInt(); 134 135 // GRABS FROM CURRENT TO END OF LINE 91 Set<Hashtable<Integer, DIRECTION>> hwyKeys = highwayTable.keySet(); 92 for(Hashtable<Integer, DIRECTION> hwyKey : hwyKeys) 93 { 94 Enumeration<Integer> hwyNumEnum = hwyKey.keys(); 95 Integer hwyNum = hwyNumEnum.nextElement(); 96 ArrayList<Station> hwyStations = highwayTable.get(hwyKey); 97 DIRECTION hwyDir = hwyKey.get(hwyNum); 98 Collections.sort(highwayTable.get(hwyKey)); 99 System.out.println("Adding highway: " + hwyNum + " " + hwyDir.name + " " + hwyStations.size()); 100 highways.add(new Highway(hwyNum, 101 hwyDir, hwyStations)); 102 } 103 return highways; 104 } 105 /* 106 private ArrayList<FEPLine> loadLines(String highwayMetaFileName) { 107 ArrayList<FEPLine> lines = new ArrayList<>(); 108 try { 109 Scanner sc = new Scanner(new File(highwayMetaFileName)); 110 String firstLine = sc.nextLine(); 111 112 Scanner linesc = new Scanner(firstLine); 113 int numLines = linesc.nextInt(); 114 linesc.close(); 115 116 for (int i = 0; i < numLines; i++) { 117 System.out.println("CURR: " + i); 118 lines.add(loadLine(sc)); 119 } 120 sc.close(); 121 122 } catch (FileNotFoundException ex) { 123 Logger.getLogger(Highways.class.getName()).log(Level.SEVERE, null, ex); 124 } 125 return lines; 126 } 127 128 private FEPLine loadLine(Scanner sc) { 129 String line = sc.nextLine(); 130 System.out.println(line); 131 Scanner scline = new Scanner(line); 132 133 int lineNum = scline.nextInt(); 134 int count = scline.nextInt(); 135 int numStations = scline.nextInt(); 136 ArrayList<Station> stations = new ArrayList<>(); 137 for (int i = 0; i < numStations; i++) { 138 stations.add(loadStation(sc, lineNum)); 139 } 140 141 return new FEPLine(lineNum, stations, count); 142 } 143 144 private Station loadStation(Scanner sc, int lineNum) { 145 String line = sc.nextLine(); 146 System.out.println(line); 147 Scanner scline = new Scanner(line); 148 int ldsID = scline.nextInt(); 149 int drop = scline.nextInt(); 150 int fwy = scline.nextInt(); 151 DIRECTION dir = DIRECTION.getEnum(scline.next()); 152 double postmile = scline.nextDouble(); 153 int numLoops = scline.nextInt(); 154 String location = getStationLoc(line); 155 ArrayList<LoopDetector> loops = new ArrayList<>(); 156 for (int i = 0; i < numLoops; i++) { 157 loops.add(loadLoop(sc)); 158 } 159 160 return new Station(lineNum, ldsID, drop, location, loops, fwy, dir, postmile); 161 } 162 163 private LoopDetector loadLoop(Scanner sc) { 164 String line = sc.nextLine(); 165 Scanner scline = new Scanner(line); 166 167 int loopID = scline.nextInt(); 168 int laneNum = scline.nextInt(); 169 String loopLoc = getLoopLoc(line); // NEED GET LOOPLOC 170 scline.close(); 171 return new LoopDetector(loopID, loopLoc, laneNum); 172 } 173 174 private String getLoopLoc(String line) { 175 Scanner sc = new Scanner(line); 176 sc.nextInt(); 177 sc.nextInt(); 178 179 // GRABS FROM CURRENT TO END OF LINE 136 180 137 sc.useDelimiter("\\z"); 138 String loc = sc.next().trim(); 139 sc.close(); 140 return loc; 141 } 142 143 // Returns the loction given the whole line from the lookup file 144 private String getStationLoc(String line) { 145 Scanner scline = new Scanner(line); 146 scline.nextInt(); 147 scline.nextInt(); 148 scline.nextInt(); 149 scline.next(); 150 scline.nextDouble(); 151 scline.nextInt(); 152 153 // GRABS FROM CURRENT TO END OF LINE 154 scline.useDelimiter("\\z"); 155 String loc = scline.next().trim(); 156 scline.close(); 157 return loc; 158 } 159 */ 181 sc.useDelimiter("\\z"); 182 String loc = sc.next().trim(); 183 sc.close(); 184 return loc; 185 } 186 187 // Returns the loction given the whole line from the lookup file 188 private String getStationLoc(String line) { 189 Scanner scline = new Scanner(line); 190 scline.nextInt(); 191 scline.nextInt(); 192 scline.nextInt(); 193 scline.next(); 194 scline.nextDouble(); 195 scline.nextInt(); 196 197 // GRABS FROM CURRENT TO END OF LINE 198 scline.useDelimiter("\\z"); 199 String loc = scline.next().trim(); 200 scline.close(); 201 return loc; 202 } 203 */ 204 160 205 public void writeToFEP() { 161 206 try { … … 168 213 } 169 214 } 170 215 171 216 // CHECK: DO WE EVEN NEED TO DO THIS? 172 217 private void updateSequences() { -
trunk/src/atmsdriver/model/Station.java
r87 r88 50 50 } 51 51 52 public int getHighwayNumber() 53 { 54 return this.freeway; 55 } 56 57 public DIRECTION getDirection() 58 { 59 return this.direction; 60 } 61 52 62 /** 53 63 * Returns the station metadata in condensed form. This is just a quick -
trunk/src/tmcsim/application.properties
r87 r88 1 #Tue, 10 Oct 2017 02:07:01-07001 #Tue, 10 Oct 2017 13:13:29 -0700 2 2 3 Application.revision=8 43 Application.revision=87 4 4 5 Application.buildnumber= 485 Application.buildnumber=50
Note: See TracChangeset
for help on using the changeset viewer.
