Changeset 103 in tmcsimulator
- Timestamp:
- 10/12/2017 12:28:28 AM (9 years ago)
- Files:
-
- 4 deleted
- 11 edited
- 1 moved
-
branches/FEPSimulator/build/Debug/GNU-MacOSX/DataPacker.o.d (deleted)
-
branches/FEPSimulator/build/Debug/GNU-MacOSX/FEPSim.o.d (deleted)
-
branches/FEPSimulator/build/Debug/GNU-MacOSX/NetworkReader.o.d (deleted)
-
branches/FEPSimulator/dist/Debug/GNU-MacOSX/fepsimulator (deleted)
-
trunk/IDE_metadata/NetBeans/TMCSim/nbproject/configs/ATMSDriverLocal.properties (modified) (1 diff)
-
trunk/src/atmsdriver/ATMSDriver.java (modified) (5 diffs)
-
trunk/src/atmsdriver/ConsoleDriver.java (modified) (1 diff)
-
trunk/src/atmsdriver/FEPLineLoader.java (moved) (moved from trunk/src/atmsdriver/NetworkLoader.java) (3 diffs)
-
trunk/src/atmsdriver/model/FEPLine.java (modified) (3 diffs)
-
trunk/src/atmsdriver/model/Highway.java (modified) (2 diffs)
-
trunk/src/atmsdriver/model/Highways.java (modified) (8 diffs)
-
trunk/src/atmsdriver/model/LoopDetector.java (modified) (1 diff)
-
trunk/src/atmsdriver/model/Station.java (modified) (8 diffs)
-
trunk/src/tmcsim/application.properties (modified) (1 diff)
-
trunk/test/atmsdriver/model/LoadHighwaysTest.java (modified) (6 diffs)
-
trunk/test/atmsdriver/model/StationTest.java (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/IDE_metadata/NetBeans/TMCSim/nbproject/configs/ATMSDriverLocal.properties
r101 r103 1 main.class=atmsdriver.ATMSDriver 1 2 run.jvmargs=-DATMSDRIVER_PROPERTIES=config/atms_driver_config_local.properties -
trunk/src/atmsdriver/ATMSDriver.java
r88 r103 2 2 3 3 import atmsdriver.model.Highways; 4 import java.io.File;5 4 import java.io.FileInputStream; 6 import java.io.FileNotFoundException;7 import java.io.PrintWriter;8 5 import java.util.Properties; 9 6 import java.util.logging.Level; … … 25 22 */ 26 23 private static Logger ATMSDriverLogger = Logger.getLogger("atmsdriver"); 27 28 private static final String CONFIG_FILE_NAME = "atms_driver_config.properties";29 24 30 25 /** … … 95 90 96 91 public ATMSDriver(String propertiesFile) { 97 92 // verify properties file 98 93 if (!verifyProperties(propertiesFile)) { 99 94 System.exit(0); 100 95 } 101 96 // create the highways model 102 97 highways = new Highways( 103 98 ATMSDriverProperties.getProperty( … … 110 105 Integer.parseInt(ATMSDriverProperties.getProperty( 111 106 PROPERTIES.FEP_WRITER_PORT.name))); 112 107 // create the exchange reader 113 108 exchangeReader = new ExchangeReader(); 114 109 } 115 110 111 /** 112 * Verifies that the properties file has all necessary properties. 113 * 114 * @param propertiesFile 115 * @return 116 */ 116 117 private boolean verifyProperties(String propertiesFile) { 117 118 // Load the properties file. … … 133 134 try { 134 135 if (System.getProperty("ATMSDRIVER_PROPERTIES") != null) { 135 new Thread(new ATMSDriver(System.getProperty( 136 "ATMSDRIVER_PROPERTIES"))).start(); 136 // Create and run the ATMSDriver thread 137 ATMSDriver atmsDriver = new ATMSDriver(System.getProperty("ATMSDRIVER_PROPERTIES")); 138 Thread ATMSDriverThread = new Thread(atmsDriver); 139 ATMSDriverThread.start(); 140 141 // run the console driver, pass it the atmsDriver highways model 142 ConsoleDriver driver = new ConsoleDriver(atmsDriver.highways); 143 137 144 } else { 138 145 throw new Exception("ATMSDRIVER_PROPERTIES system property not defined."); -
trunk/src/atmsdriver/ConsoleDriver.java
r97 r103 1 1 package atmsdriver; 2 2 3 import atmsdriver.model.Highways; 4 import atmsdriver.model.Station.DIRECTION; 5 import atmsdriver.model.Highway; 6 import atmsdriver.model.Station; 7 import java.util.ArrayList; 8 import java.util.Arrays; 9 import java.util.List; 10 import java.util.Scanner; 11 3 12 /** 4 * A console application to drive the ATMS Server. 5 * @author jdalbey 13 * A console application to drive the ATMS Server. 14 * 15 * @author jdalbey, John A. Torres 16 * @version 10/11/2017 6 17 */ 7 public class ConsoleDriver 8 { 9 // 10 //Given 11 // <Highway Number> <Dir> <Postmile> <Range> <DotColor> 12 // 13 //IF default direction of Highway Number = Dir THEN 14 // Set StartPost = Postmile 15 // Set EndPost = Postmile + Range 16 //ELSE 17 // Set StartPost = Postmile - Range 18 // Set EndPost = Postmile 19 //END IF 20 // 21 //FOR each Station in Highway Number LOOP 22 // 23 // IF Station.Postmile within range of StartPost:EndPost THEN 24 // IF default direction of Highway Number = Dir THEN 25 // Set ML color to DotColor 26 // ELSE 27 // Set OPP color to DotColor 28 // END IF 29 // END IF 30 // 31 //END LOOP 32 // 33 // 18 public final class ConsoleDriver { 19 // highways model 20 private final Highways highways; 21 22 // lists used for user input validation 23 private final List<Integer> routeNumInputList; 24 private final List<String> dotColorInputList; 25 26 /** 27 * Constructor. Sets the highways model and generates the input validation 28 * lists, and then runs the console driver application. 29 * @param highways 30 */ 31 public ConsoleDriver(Highways highways) { 32 // set highways model 33 this.highways = highways; 34 35 // set input validation lists 36 routeNumInputList = generateRouteNumInputList(); 37 dotColorInputList = new ArrayList<>(Arrays.asList("R", "Y", "G")); 38 39 // run the console driver 40 runConsole(); 41 } 42 43 /** 44 * Generates the route number list, used for user input validation. 45 * @return list of route numbers. 46 */ 47 private ArrayList<Integer> generateRouteNumInputList() 48 { 49 ArrayList<Integer> routeNums = new ArrayList<>(); 50 // add the route number for each highway to the list 51 for(Highway hwy : highways.highways) 52 { 53 routeNums.add(hwy.routeNumber); 54 } 55 return routeNums; 56 } 57 58 /** 59 * Runs the console driver application. 60 */ 61 public void runConsole() { 62 Scanner sc = new Scanner(System.in); 63 // Run continuously 64 while (true) { 65 // Get necessary values for colorization of highways 66 Integer routeNumber = getRouteNumber(sc); 67 DIRECTION direction = getDirection(sc, routeNumber); 68 Double postmile = getPostmile(sc, routeNumber, direction); 69 Integer range = getRange(sc, postmile); 70 DOTCOLOR dotcolor = getDotColor(sc); 71 72 // apply colorization to highways 73 applyColorToHighwayStretch(routeNumber, direction, postmile, range, dotcolor); 74 } 75 } 76 77 /** 78 * Applies specified color to the specified highway stretch. Route number and 79 * direction specify the highway. Postmile and range specify the stretch of 80 * specified highway. Dot color is the color to be applied to the stretch. 81 * 82 * @param routeNumber highway route number 83 * @param direction highway direction 84 * @param postmile origin postmile value 85 * @param range range from origin postmile 86 * @param dotColor the color to be applied to specified highway stretch 87 */ 88 private void applyColorToHighwayStretch(Integer routeNumber, DIRECTION direction, 89 Double postmile, Integer range, DOTCOLOR dotColor) { 90 System.out.println("Applying " + dotColor.name() + " dots to highway " 91 + routeNumber + " " + direction.name() + " at postmile " 92 + postmile + " with a range of " + range + " miles..."); 93 94 // Get the highway by route number 95 Highway highway = highways.getHighwayByRouteNumber(routeNumber); 96 97 // start value for highway section, and end value for highway section 98 // by postmile 99 Double startPost; 100 Double endPost; 101 102 // postmiles increase from s to n and w to e 103 104 // if the direction is south or west 105 if(direction.equals(DIRECTION.SOUTH) || direction.equals(DIRECTION.WEST)) 106 { 107 // add range value to startPost to get 108 // the end postmile value of the highway section 109 startPost = postmile; 110 endPost = postmile + range; 111 112 // iterate through the stations, if within the specified highway 113 // stretch, update the station by direction and apply dot color 114 for(Station station : highway.stations) 115 { 116 if(station.postmile > startPost && station.postmile < endPost) 117 { 118 station.updateByDirection(direction, dotColor); 119 } 120 } 121 } 122 // if the direction is north or east 123 else 124 { 125 //subtract range value from startPost 126 // to get the end postmile value of the highway section 127 startPost = postmile; 128 endPost = postmile - range; 129 130 // iterate through the stations, if within the specified highway 131 // section, update the station by direction and apply dot color 132 for(Station station : highway.stations) 133 { 134 if(station.postmile < startPost && station.postmile > endPost) 135 { 136 station.updateByDirection(direction, dotColor); 137 } 138 } 139 } 140 System.out.println(""); 141 } 142 143 /** 144 * Gets the highway route number from user and validates the input. 145 * 146 * @param sc stdIn scanner 147 * @return highway route number 148 */ 149 private Integer getRouteNumber(Scanner sc) { 150 Integer routeNum = null; 151 Boolean verified = false; 152 153 // validation loop 154 while(!verified) 155 { 156 // Prints out available route numbers to user to select from 157 System.out.print("Available route numbers: ["); 158 for(Integer rtNum : routeNumInputList) 159 { 160 System.out.print(rtNum.toString() + ", "); 161 } 162 System.out.print("]"); 163 System.out.println(""); 164 165 // Prompt user to input a route number 166 System.out.println("Enter a route number: "); 167 routeNum = sc.nextInt(); 168 System.out.println(""); 169 170 // validate the user's input 171 if(routeNumInputList.contains(routeNum)) 172 { 173 verified = true; 174 } 175 else 176 { 177 System.out.println("Invalid route number, please re-enter: "); 178 } 179 } 180 181 return routeNum; 182 } 183 184 /** 185 * Gets the highway direction from the user and validates the input. 186 * 187 * @param sc stdIn scanner 188 * @return highway direction 189 */ 190 private DIRECTION getDirection(Scanner sc, Integer routeNum) { 191 DIRECTION direction; 192 String directionInput = null; 193 Boolean verified = false; 194 195 // validation loop 196 while(!verified) 197 { 198 // Get available directions for route 199 ArrayList<DIRECTION> availDirs = new ArrayList<>(); 200 for(Station stn : highways.getHighwayByRouteNumber(routeNum).stations) 201 { 202 if(!availDirs.contains(stn.direction)) 203 { 204 availDirs.add(stn.direction); 205 } 206 } 207 208 // prompt user for input 209 System.out.print("Available directions for highway " + routeNum + ": ["); 210 for(DIRECTION dir : availDirs) 211 { 212 System.out.print(dir.getLetter() + ", "); 213 } 214 System.out.print("]"); 215 System.out.println(""); 216 System.out.println("Enter a direction:"); 217 directionInput = sc.next(); 218 System.out.println(""); 219 220 // validate the user's input 221 if(availDirs.contains(DIRECTION.toDirection(directionInput))) 222 { 223 verified = true; 224 } 225 else 226 { 227 System.out.println("Invalid direction, please re-enter: "); 228 } 229 } 230 231 return DIRECTION.toDirection(directionInput); 232 } 233 234 /** 235 * Gets the starting/origin postmile value for the highway section from the 236 * user and validates the input. 237 * 238 * @param sc stdIn scanner 239 * @param routeNumber highway route number 240 * @param dir highway direction 241 * @return highway section start/origin postmile value 242 */ 243 private Double getPostmile(Scanner sc, Integer routeNumber, DIRECTION dir) { 244 Double postmile = null; 245 Boolean verified = false; 246 247 // validation loop 248 while(!verified) 249 { 250 // Get highway, and grab the floor and ceiling for postmile values 251 // from the highway stations to present to the user 252 Highway hwy = highways.getHighwayByRouteNumber(routeNumber); 253 Double floorPostmile = hwy.stations.get(0).postmile; 254 Double ceilPostmile = hwy.stations 255 .get(hwy.stations.size() - 1).postmile; 256 257 // present user with range of postmiles for given highway 258 System.out.println("Route " + hwy.routeNumber + " " + dir 259 + " postmile range: [" + floorPostmile + ", " 260 + ceilPostmile + "]"); 261 262 // prompt user for postmile value 263 System.out.println("Enter a postmile value (Integer/Double): "); 264 postmile = sc.nextDouble(); 265 System.out.println(""); 266 267 // validate user's input, ensures that the postmile is within given 268 // postmile range (floorPostmile, ceilPostmile) 269 if(postmile >= floorPostmile && postmile <= ceilPostmile) 270 { 271 verified = true; 272 } 273 else 274 { 275 System.out.println("Postmile must be within postmile range: [" + floorPostmile + ", " 276 + ceilPostmile + "] please re-enter: "); 277 } 278 } 279 280 return postmile; 281 } 282 283 /** 284 * Gets the range to extend the highway stretch from the start/origin postmile 285 * value from the user and validates the input. 286 * 287 * @param sc stdIn scanner 288 * @param postmile origin/start postmile value for highway stretch 289 * @return range value 290 */ 291 private Integer getRange(Scanner sc, Double postmile) { 292 Integer range = null; 293 Boolean verified = false; 294 295 // validation loop 296 while(!verified) 297 { 298 // prompt user for range value 299 System.out.println("Enter a range value (Integer):"); 300 range = sc.nextInt(); 301 System.out.println(""); 302 303 // range must be greater than or equal to 0 304 if(range >= 0) 305 { 306 verified = true; 307 } 308 else 309 { 310 System.out.println("Range must be >= 0"); 311 } 312 } 313 314 return range; 315 } 316 317 /** 318 * Gets the dot color from the user, to be applied to specified highway 319 * stretch and validates the user's input. 320 * 321 * @param sc stdIn scanner 322 * @return dot color to be applied to highway stretch 323 */ 324 private DOTCOLOR getDotColor(Scanner sc) { 325 DOTCOLOR dotColor; 326 String dotColorInput = null; 327 Boolean verified = false; 328 329 // validationloop 330 while(!verified) 331 { 332 // prompt user for color 333 System.out.println("Enter a dot color (G/Y/R):"); 334 dotColorInput = sc.next(); 335 System.out.println(""); 336 // validate user's input 337 if(dotColorInputList.contains(dotColorInput)) 338 { 339 verified = true; 340 } 341 else 342 { 343 System.out.println("Invalid dot color, please re-enter: "); 344 } 345 } 346 347 return DOTCOLOR.toDotColor(dotColorInput); 348 } 349 350 /** 351 * Enum for highway status dot colors. 352 * 353 * @author John A. Torres 354 * @version 10/11/2017 355 */ 356 public static enum DOTCOLOR { 357 358 RED, 359 YELLOW, 360 GREEN; 361 362 // All the first letters of the values, in order. 363 private static String allLetters = "RYG"; 364 365 /** 366 * Return the first letter of this enum. 367 * 368 * @return String first letter of this enum. 369 */ 370 public String getLetter() { 371 return this.toString().substring(0, 1); 372 } 373 374 /** 375 * Returns a dot color given its first character. 376 * 377 * @param letter the first character of a dot color 378 * @return dot color corresponding to letter 379 * @pre letter must be one of allLetters 380 */ 381 public static DOTCOLOR toDotColor(String letter) { 382 return values()[allLetters.indexOf(letter.charAt(0))]; 383 } 384 } 34 385 } -
trunk/src/atmsdriver/FEPLineLoader.java
r90 r103 13 13 import java.util.logging.Logger; 14 14 15 /** The NetworkReader loads all static data for the traffic network through 16 * network lookup files. 15 /** The FEPLineLoader loads all static data for the FEPLines, using the station 16 * and loop lookup files. 17 * 18 * THIS CLASS WILL BE REMOVED AND THE LOADING OF FEPLINES WILL BE THE RESPONSIBILITY 19 * OF THE HIGHWAYS.JAVA CLASS FOR PROPER OOP. JUST USING FOR NOW BECAUSE IT WORKS. 17 20 * 18 21 * The public method getFEPLines() method can be used to get all the FEPLines 19 within a network. All other methods are private and are used to construct 20 the FEPLines. 21 22 The "LDSFile" contains Station and FEPLine information. 23 ex. 24 < Insert file here > 25 * The "loopFile" contains individual LoopDetector information. 26 * ex. 27 * < Insert file here > 22 * within the network. All other methods are private and are used to construct 23 * the FEPLines. 28 24 * 29 25 * @author John A. Torres 30 26 * @version 09/10/2017 31 27 */ 32 public class NetworkLoader {28 public class FEPLineLoader { 33 29 // Two network config files 34 30 private final File LDSFile; … … 43 39 * @param loopFile contains individual LoopDetector static data 44 40 */ 45 public NetworkLoader(File LDSFile, File loopFile)41 public FEPLineLoader(File LDSFile, File loopFile) 46 42 { 47 43 this.LDSFile = LDSFile; … … 176 172 } 177 173 } catch (FileNotFoundException ex) { 178 Logger.getLogger( NetworkLoader.class.getName()).log(Level.SEVERE, null, ex);174 Logger.getLogger(FEPLineLoader.class.getName()).log(Level.SEVERE, null, ex); 179 175 } 180 176 } -
trunk/src/atmsdriver/model/FEPLine.java
r88 r103 4 4 import org.w3c.dom.Document; 5 5 import org.w3c.dom.Element; 6 7 8 6 9 7 /** An FEPLine is a simulated line of communication from the FEP to … … 18 16 public class FEPLine { 19 17 /* Static FEPLine meta data */ 20 final p rivateint lineNum;21 final p rivateList<Station> stations;18 final public int lineNum; 19 final public List<Station> stations; 22 20 final private int count; 23 // NOT SURE IF NEXT IS FINAL21 24 22 final private int schedule; 25 23 final private int lineInfo; 26 24 final private long systemKey; 25 26 // THESE WILL NEED TO BE UPDATED MAYBE, NOT SURE, NOT A PRIORITY. SEE METHOD 27 // UPDATESEQUENCES() 27 28 private long globalSeq; 28 29 private long scheduleSeq; … … 40 41 this.globalSeq = globalSeq; 41 42 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;52 43 } 53 44 -
trunk/src/atmsdriver/model/Highway.java
r93 r103 10 10 * @author jdalbey 11 11 */ 12 final class Highway12 final public class Highway 13 13 { 14 14 /** The identifying number for this highway, e.g., 101 */ 15 public final Integer highwayNumber;15 public final Integer routeNumber; 16 16 /** The ordered list of stations (lane detector stations) on this highway */ 17 17 public final ArrayList<Station> stations; … … 22 22 * @param stations ordered list of stations on this highway 23 23 */ 24 public Highway(Integer highwayNum, ArrayList<Station> stations)24 public Highway(Integer routeNumber, ArrayList<Station> stations) 25 25 { 26 this. highwayNumber = highwayNum;26 this.routeNumber = routeNumber; 27 27 this.stations = stations; 28 28 } -
trunk/src/atmsdriver/model/Highways.java
r101 r103 1 1 package atmsdriver.model; 2 2 3 import atmsdriver.NetworkLoader; 4 import atmsdriver.model.Station.DIRECTION; 3 import atmsdriver.FEPLineLoader; 5 4 import java.io.File; 6 import java.io.FileNotFoundException;7 5 import java.io.FileWriter; 8 6 import java.io.IOException; … … 13 11 import java.util.ArrayList; 14 12 import java.util.Collections; 15 import java.util.Enumeration;16 13 import java.util.HashMap; 17 import java.util.Hashtable;18 import java.util.List;19 14 import java.util.Map; 20 15 import java.util.Observable; 21 16 import java.util.Observer; 22 import java.util.Scanner;23 17 import java.util.Set; 24 18 import java.util.logging.Level; … … 34 28 import org.w3c.dom.Element; 35 29 36 /** 30 /** The Highways class aggregates all Highway instances within a geographic 31 * region, and all of the FEPLines within an electronic detector 32 * network, in the same geographic region. An instance of Highways.java 33 * comprises the underlying model for the ATMSDriver application. 34 * 35 * Highways uses method writeToFEP() to communicate with the FEP Simulator. 36 * It creates a socket client which sends the FEP Simulator a highways status 37 * message over the socket. This message is in the XML format required by the 38 * FEP Simulator, which is provided by the resident toXML() method. 39 * 40 * Currently, there is no driving logic within the highways class. It is only 41 * done through an instance of the ConsoleDriver.java class. Eventually, it 42 * will receive incident data (from exchange.xml or better yet, directly from 43 * the TMCSimulator itself) and drive the highways using resident logic. 37 44 * 38 45 * @author John A. Torres 39 46 */ 40 public class Highways implements Observer{47 public class Highways { 41 48 42 49 final private ArrayList<FEPLine> lines; 43 50 final private String FEPHostName; 44 51 final private int FEPPortNum; 45 final private ArrayList<Highway> highways;46 private Map<Integer, List<Station>> HiwayMap = new HashMap<Integer, List<Station>>();47 52 48 // NEED FINISH final private ArrayList<Highway> highways; 53 final public ArrayList<Highway> highways; 54 49 55 public Highways(String ldsFileName, String loopsFileName, 50 56 String highwayMetaFileName, String FEPHostName, int FEPPortNum) { … … 54 60 */ 55 61 56 NetworkLoader ldr = new NetworkLoader(new File(ldsFileName), new File(loopsFileName));62 FEPLineLoader ldr = new FEPLineLoader(new File(ldsFileName), new File(loopsFileName)); 57 63 this.lines = (ArrayList<FEPLine>) ldr.getFEPLines(); 58 64 this.FEPHostName = FEPHostName; … … 61 67 //writeHighwaysMeta("hard.txt"); 62 68 } 63 64 public ArrayList<Highway> getHighways()65 {66 return this.highways;67 }68 69 69 70 70 private ArrayList<Highway> loadHighways() { … … 72 72 // The list of highways to return 73 73 ArrayList<Highway> highways = new ArrayList<Highway>(); 74 Hashtable<Hashtable<Integer, DIRECTION>, ArrayList<Station>> 75 highwayTable = new Hashtable<>(); 74 75 Map<Integer, ArrayList<Station>> 76 highwayMap = new HashMap<>(); 76 77 77 78 for (FEPLine line : lines) 78 79 { 79 ArrayList<Station> lineStations = (ArrayList<Station>) line. getStations();80 ArrayList<Station> lineStations = (ArrayList<Station>) line.stations; 80 81 for(Station station : lineStations) 81 82 { 82 Integer hwyNum = station.getHighwayNumber(); 83 DIRECTION dir = station.getDirection(); 84 Hashtable<Integer, DIRECTION> check = new Hashtable<>(); 85 check.put(hwyNum, dir); 86 if(highwayTable.get(check) == null) 83 Integer hwyNum = station.routeNumber; 84 85 if(!highwayMap.containsKey(hwyNum)) 87 86 { 88 87 ArrayList<Station> stnList = new ArrayList<>(); 89 88 stnList.add(station); 90 Hashtable<Hashtable<Integer, DIRECTION>, ArrayList<Station>> 91 newEntry = new Hashtable(); 92 newEntry.put(check, stnList); 93 highwayTable.putAll(newEntry); 89 highwayMap.put(hwyNum, stnList); 94 90 } 95 91 else 96 92 { 97 highway Table.get(check).add(station);93 highwayMap.get(hwyNum).add(station); 98 94 } 99 95 } 100 96 } 101 97 102 Set< Hashtable<Integer, DIRECTION>> hwyKeys = highwayTable.keySet();103 for( Hashtable<Integer, DIRECTION>hwyKey : hwyKeys)98 Set<Integer> hwyKeys = highwayMap.keySet(); 99 for(Integer hwyKey : hwyKeys) 104 100 { 105 Enumeration<Integer> hwyNumEnum = hwyKey.keys(); 106 Integer hwyNum = hwyNumEnum.nextElement(); 107 ArrayList<Station> hwyStations = highwayTable.get(hwyKey); 108 DIRECTION hwyDir = hwyKey.get(hwyNum); 109 Collections.sort(highwayTable.get(hwyKey)); 110 System.out.println("Adding highway: " + hwyNum + " " + hwyDir.toString().charAt(0)); 111 highways.add(new Highway(hwyNum, 101 ArrayList<Station> hwyStations = highwayMap.get(hwyKey); 102 Collections.sort(hwyStations); 103 System.out.println("Loaded highway " + hwyKey + "..."); 104 highways.add(new Highway(hwyKey, 112 105 hwyStations)); 113 106 } 107 System.out.println(""); 114 108 return highways; 115 109 } 110 116 111 /* 117 112 private ArrayList<FEPLine> loadLines(String highwayMetaFileName) { … … 215 210 216 211 public void writeToFEP() { 217 System.out.println(this.toXML().toCharArray().length);218 219 212 try { 220 213 Socket sock = new Socket(FEPHostName, FEPPortNum); … … 293 286 } 294 287 295 @Override 296 public void update(Observable o, Object arg) { 297 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. 288 public Highway getHighwayByRouteNumber(Integer routeNum) { 289 Highway returnHwy = null; 290 for(Highway hwy : highways) 291 { 292 if(hwy.routeNumber.equals(routeNum)) 293 { 294 returnHwy = hwy; 295 break; 296 } 297 } 298 return returnHwy; 298 299 } 299 300 -
trunk/src/atmsdriver/model/LoopDetector.java
r87 r103 17 17 { 18 18 /* static data */ 19 final p rivateint loopID;20 final p rivateString loopLocation;21 final p rivateint laneNum;19 final public int loopID; 20 final public String loopLocation; 21 final public int laneNum; 22 22 23 23 /* dynamic data */ -
trunk/src/atmsdriver/model/Station.java
r94 r103 1 1 package atmsdriver.model; 2 2 3 import atmsdriver.ConsoleDriver; 4 import atmsdriver.ConsoleDriver.DOTCOLOR; 3 5 import java.util.List; 4 6 import org.w3c.dom.Document; … … 21 23 22 24 /* Static Station meta data */ 23 final p rivateint lineNum;24 final p rivateint ldsID; // double check25 final p rivateint drop;26 final p rivateString location;27 final p rivateList<LoopDetector> loops;28 final p rivate int highwayNum;29 final p rivatedouble postmile;30 final p rivateDIRECTION direction;25 final public int lineNum; 26 final public int ldsID; // double check 27 final public int drop; 28 final public String location; 29 final public List<LoopDetector> loops; 30 final public int routeNumber; 31 final public double postmile; 32 final public DIRECTION direction; 31 33 32 34 /* Dynamic Station data */ … … 46 48 this.postmile = postmile; 47 49 this.direction = direction; 48 this. highwayNum= hwy;50 this.routeNumber = hwy; 49 51 50 52 this.MLTotVol = 0; 51 53 this.OppTotVol = 0; 52 }53 54 public int getHighwayNumber()55 {56 return this.highwayNum;57 }58 59 public DIRECTION getDirection()60 {61 return this.direction;62 54 } 63 55 … … 76 68 build.append(Integer.toString(this.drop)); 77 69 build.append(" "); 78 build.append(Integer.toString(this. highwayNum));70 build.append(Integer.toString(this.routeNumber)); 79 71 build.append(" "); 80 72 build.append(this.direction.getLetter()); … … 91 83 } 92 84 return build.toString(); 93 }94 95 public double getPostmile()96 {97 return postmile;98 85 } 99 86 … … 117 104 118 105 // get difference of values 119 double otherStationPostmile = ((Station) otherStation). getPostmile();106 double otherStationPostmile = ((Station) otherStation).postmile; 120 107 double val = this.postmile - otherStationPostmile; 121 108 … … 134 121 } 135 122 123 public void updateByDirection(DIRECTION direction, DOTCOLOR dotColor) { 124 if(direction.equals(this.direction)) 125 { 126 updateML(dotColor); 127 } 128 else 129 { 130 updateOPP(dotColor); 131 } 132 } 133 134 private void updateML(DOTCOLOR dotcolor) 135 { 136 outputUpdateMessage(dotcolor, "ML"); 137 138 for(LoopDetector loop : loops) 139 { 140 if(loop.loopLocation.startsWith("ML")) 141 { 142 // UPDATE LOOP WITH VALUES 143 } 144 } 145 } 146 147 private void updateOPP(DOTCOLOR dotcolor) 148 { 149 outputUpdateMessage(dotcolor, "OPP"); 150 for(LoopDetector loop : loops) 151 { 152 if(loop.loopLocation.startsWith("OP")) 153 { 154 // UPDATE LOOP WITH VALUES 155 } 156 } 157 } 158 159 private void outputUpdateMessage(DOTCOLOR dotcolor, String OPP_ML) 160 { 161 System.out.printf("Updating route %-3.3s %-5.5s %-3.3s lanes\t %-12.12s " 162 + "at postmile %-6.6s to %-7.7s\n", 163 Integer.toString(this.routeNumber), this.direction.name(), 164 OPP_ML, this.location, Double.toString(this.postmile), 165 dotcolor.name()); 166 } 167 136 168 private static enum XML_TAGS 137 169 { … … 189 221 190 222 Element freewayElement = theDoc.createElement(XML_TAGS.FREEWAY.tag); 191 freewayElement.appendChild(theDoc.createTextNode(String.valueOf(this. highwayNum)));223 freewayElement.appendChild(theDoc.createTextNode(String.valueOf(this.routeNumber))); 192 224 stationElement.appendChild(freewayElement); 193 225 -
trunk/src/tmcsim/application.properties
r101 r103 1 # Wed, 11 Oct 2017 17:25:07-07001 #Thu, 12 Oct 2017 01:19:36 -0700 2 2 3 Application.revision= 973 Application.revision=101 4 4 5 Application.buildnumber=5 05 Application.buildnumber=51 -
trunk/test/atmsdriver/model/LoadHighwaysTest.java
r96 r103 1 1 package atmsdriver.model; 2 2 3 import atmsdriver.ATMSDriver;4 import atmsdriver.model.Station.DIRECTION;5 import java.io.File;6 3 import java.io.FileWriter; 7 4 import java.io.PrintWriter; … … 70 67 71 68 // Test for correct number of highways 72 ArrayList<Highway> result = highways. getHighways();73 assertEquals( 3, result.size());69 ArrayList<Highway> result = highways.highways; 70 assertEquals(2, result.size()); 74 71 75 72 // Test 55 N was loaded 76 Highway fiftyfiveN = result.get( 2);77 assertEquals(new Integer(55), fiftyfiveN. highwayNumber);73 Highway fiftyfiveN = result.get(0); 74 assertEquals(new Integer(55), fiftyfiveN.routeNumber); 78 75 79 76 // Test 55 N stations are sorted by postmile … … 82 79 for(Station station : stations) 83 80 { 84 stationsPostmiles.add(station. getPostmile());81 stationsPostmiles.add(station.postmile); 85 82 } 83 84 // Create expected station postmile list (sorted) 86 85 ArrayList<Double> expectedStationsPostmiles = new ArrayList<>(); 87 86 expectedStationsPostmiles.add(new Double(4.58)); 87 expectedStationsPostmiles.add(new Double(4.7)); 88 expectedStationsPostmiles.add(new Double(5.06)); 88 89 expectedStationsPostmiles.add(new Double(5.51)); 89 90 expectedStationsPostmiles.add(new Double(9.41)); 90 91 expectedStationsPostmiles.add(new Double(10)); 91 for(int i = 0; i < 4; i++) 92 expectedStationsPostmiles.add(new Double(10.4)); 93 expectedStationsPostmiles.add(new Double(10.5)); 94 for(int i = 0; i < 8; i++) 92 95 { 93 96 assertEquals(expectedStationsPostmiles.get(i), … … 96 99 97 100 // Test 55 S was loaded 98 Highway fiftyfiveS = result.get( 0);99 assertEquals(new Integer(5 5), fiftyfiveS.highwayNumber);101 Highway fiftyfiveS = result.get(1); 102 assertEquals(new Integer(5), fiftyfiveS.routeNumber); 100 103 101 104 // Test 55 S stations are sorted by postmile … … 104 107 for(Station station : stations) 105 108 { 106 stationsPostmiles.add(station.getPostmile()); 107 } 108 expectedStationsPostmiles.clear(); 109 expectedStationsPostmiles.add(new Double(4.7)); 110 expectedStationsPostmiles.add(new Double(5.06)); 111 expectedStationsPostmiles.add(new Double(10.4)); 112 expectedStationsPostmiles.add(new Double(10.5)); 113 for(int i = 0; i < 4; i++) 114 { 115 assertEquals(expectedStationsPostmiles.get(i), 116 stationsPostmiles.get(i)); 117 } 118 119 Highway fiveS = result.get(1); 120 assertEquals(new Integer(5), fiveS.highwayNumber); 121 122 // Test 5 S stations are sorted by postmile 123 stations = fiveS.stations; 124 stationsPostmiles.clear(); 125 for(Station station : stations) 126 { 127 stationsPostmiles.add(station.getPostmile()); 109 stationsPostmiles.add(station.postmile); 128 110 } 129 111 expectedStationsPostmiles.clear(); … … 131 113 expectedStationsPostmiles.add(new Double(32.25)); 132 114 expectedStationsPostmiles.add(new Double(33)); 133 for(int i = 0; i < 2; i++)115 for(int i = 0; i < 3; i++) 134 116 { 135 117 assertEquals(expectedStationsPostmiles.get(i), -
trunk/test/atmsdriver/model/StationTest.java
r91 r103 33 33 public void testGetHighwayNumber() { 34 34 System.out.println("getHighwayNumber"); 35 assertEquals(4, alpha. getHighwayNumber());35 assertEquals(4, alpha.routeNumber); 36 36 } 37 37 … … 41 41 public void testGetDirection() { 42 42 System.out.println("getDirection"); 43 assertEquals(DIRECTION.NORTH, alpha. getDirection());43 assertEquals(DIRECTION.NORTH, alpha.direction); 44 44 } 45 45 … … 59 59 public void testGetPostmile() { 60 60 System.out.println("getPostmile"); 61 assertEquals(1.0, alpha. getPostmile(),0.1);61 assertEquals(1.0, alpha.postmile,0.1); 62 62 } 63 63
Note: See TracChangeset
for help on using the changeset viewer.
