Changeset 180 in tmcsimulator
- Timestamp:
- 10/27/2017 01:38:13 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 8 edited
- 1 moved
-
IDE_metadata/NetBeans/TMCSim/build.xml (modified) (1 diff)
-
IDE_metadata/NetBeans/TMCSim/nbproject/configs/ConsoleDriver.properties (modified) (1 diff)
-
IDE_metadata/NetBeans/TMCSim/nbproject/configs/ConsoleDriverLocal.properties (modified) (1 diff)
-
src/atmsdriver/ATMSDriver.java (modified) (1 diff)
-
src/atmsdriver/ConsoleTrafficDriver.java (moved) (moved from trunk/src/atmsdriver/ConsoleDriver.java) (10 diffs)
-
src/atmsdriver/model/Highways.java (modified) (1 diff)
-
src/atmsdriver/model/LoopDetector.java (modified) (1 diff)
-
src/atmsdriver/model/Station.java (modified) (2 diffs)
-
src/tmcsim/client/ATMSBatchDriver.java (modified) (5 diffs)
-
test/atmsdriver/runtraffic.bash (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/IDE_metadata/NetBeans/TMCSim/build.xml
r158 r180 250 250 </manifest> 251 251 </jar> 252 <!-- *** Console Traffic Driver Only Jar *** --> 253 <jar destfile="${deploy.dir}/ConsoleTrafficDriver.jar" 254 basedir="${build.dir}/classes" 255 includes="atmsdriver/**, atmsdriver.model/**, tmcsim/common/**" 256 excludes="**/Test.class"> 257 <zipgroupfileset dir="dist/lib" includes="xercesImpl.jar"/> 258 <manifest> 259 <attribute name="Main-Class" value="atmsdriver/ConsoleTrafficDriver"/> 260 </manifest> 261 </jar> 252 262 </target> 253 263 -
trunk/IDE_metadata/NetBeans/TMCSim/nbproject/configs/ConsoleDriver.properties
r136 r180 1 main.class=atmsdriver.Console Driver1 main.class=atmsdriver.ConsoleTrafficDriver 2 2 run.jvmargs=-DATMSDRIVER_PROPERTIES=config/console_driver_config.properties -
trunk/IDE_metadata/NetBeans/TMCSim/nbproject/configs/ConsoleDriverLocal.properties
r120 r180 1 main.class=atmsdriver.Console Driver1 main.class=atmsdriver.ConsoleTrafficDriver 2 2 run.jvmargs=-DATMSDRIVER_PROPERTIES=config/console_driver_config_local.properties -
trunk/src/atmsdriver/ATMSDriver.java
r128 r180 145 145 146 146 // run the console driver, pass it the atmsDriver highways model 147 Console Driver driver = new ConsoleDriver(atmsDriver.highways);147 ConsoleTrafficDriver driver = new ConsoleTrafficDriver(atmsDriver.highways); 148 148 149 149 } else { -
trunk/src/atmsdriver/ConsoleTrafficDriver.java
r176 r180 5 5 import atmsdriver.model.Highway; 6 6 import atmsdriver.model.Station; 7 import atmsdriver.model.LoopDetector.DOTCOLOR; 7 8 import java.io.FileInputStream; 8 9 import java.util.ArrayList; … … 21 22 * @version 10/11/2017 22 23 */ 23 public final class Console Driver {24 public final class ConsoleTrafficDriver { 24 25 // highways model 25 26 private final Highways highways; … … 27 28 // lists used for user input validation 28 29 private final List<Integer> routeNumInputList; 29 private final List<String> dotColorInputList; 30 /** 31 * Properties for the ConsoleDriver 30 /** 31 * Properties for the ConsoleTrafficDriver 32 32 */ 33 33 private static Properties ConsoleDriverProperties; … … 57 57 58 58 // Construct the console driver using the highways model 59 Console Driver driver = new ConsoleDriver(highways);59 ConsoleTrafficDriver driver = new ConsoleTrafficDriver(highways); 60 60 driver.runConsole(); 61 61 } else { … … 92 92 * @param highways 93 93 */ 94 public Console Driver(Highways highways) {94 public ConsoleTrafficDriver(Highways highways) { 95 95 // set highways model 96 96 this.highways = highways; … … 98 98 // set input validation lists 99 99 routeNumInputList = generateRouteNumInputList(); 100 dotColorInputList = new ArrayList<>(Arrays.asList("R", "Y", "G"));101 100 } 102 101 … … 121 120 public void runConsole() { 122 121 Scanner sc = new Scanner(System.in); 122 char choice = 'A'; 123 123 // Run continuously 124 while (true) { 124 while (choice != 'Q') 125 { 125 126 // Get necessary values for colorization of highways 126 127 Integer routeNumber = getRouteNumber(sc); … … 129 130 Double range = getRange(sc, postmile); 130 131 DOTCOLOR dotcolor = getDotColor(sc); 131 132 132 133 // apply colorization to highways 133 applyColorToHighwayStretch(routeNumber, direction, postmile, range, dotcolor); 134 } 135 } 136 137 /** 138 * Applies specified color to the specified highway stretch. Route number and 139 * direction specify the highway. Postmile and range specify the stretch of 140 * specified highway. Dot color is the color to be applied to the stretch. 141 * 142 * @param routeNumber highway route number 143 * @param direction highway direction 144 * @param postmile origin postmile value 145 * @param range range from origin postmile 146 * @param dotColor the color to be applied to specified highway stretch 147 */ 148 public void applyColorToHighwayStretch(Integer routeNumber, DIRECTION direction, 149 Double postmile, Double range, DOTCOLOR dotColor) { 150 System.out.println("Applying " + dotColor.name() + " dots to highway " 151 + routeNumber + " " + direction.name() + " at postmile " 152 + postmile + " with a range of " + range + " miles..."); 153 154 // Get the highway by route number 155 Highway highway = highways.getHighwayByRouteNumber(routeNumber); 156 157 // start value for highway section, and end value for highway section 158 // by postmile 159 Double startPost; 160 Double endPost; 161 162 // postmiles increase from s to n and w to e 163 164 // if the direction is south or west 165 if(direction.equals(DIRECTION.SOUTH) || direction.equals(DIRECTION.WEST)) 166 { 167 // add range value to startPost to get 168 // the end postmile value of the highway section 169 startPost = postmile; 170 endPost = postmile + range; 171 172 // iterate through the stations, if within the specified highway 173 // stretch, update the station by direction and apply dot color 174 for(Station station : highway.stations) 175 { 176 if(station.postmile >= startPost && station.postmile <= endPost) 177 { 178 station.updateByDirection(direction, dotColor); 134 highways.applyColorToHighwayStretch(routeNumber, direction, postmile, range, dotcolor); 135 136 System.out.println("Add another entry or Send now? (A/S)"); 137 choice = sc.next().toUpperCase().trim().charAt(0); 138 System.out.println(""); 139 if (choice == 'S') 140 { 141 // Send highway model to FEP for transmit to ATMS 142 try { 143 highways.writeToFEP(); 144 } catch (SimulationException ex) { 145 System.out.println("Skipping writeToFEP..."); 179 146 } 180 } 181 } 182 // if the direction is north or east 183 else 184 { 185 //subtract range value from startPost 186 // to get the end postmile value of the highway section 187 startPost = postmile; 188 endPost = postmile - range; 189 190 // iterate through the stations, if within the specified highway 191 // section, update the station by direction and apply dot color 192 for(Station station : highway.stations) 193 { 194 if(station.postmile <= startPost && station.postmile >= endPost) 195 { 196 station.updateByDirection(direction, dotColor); 197 } 198 } 199 } 200 System.out.println(""); 201 // Omit this since it's now running as a task in ATMSBatchDriver 202 // try { 203 // highways.writeToFEP(); 204 // } catch (SimulationException ex) { 205 // System.out.println("Skipping writeToFEP..."); 206 // } 207 } 147 System.out.println("Add another entry or Quit? (A/Q)"); 148 choice = sc.next().toUpperCase().trim().charAt(0); 149 } 150 } 151 } 152 208 153 209 154 /** … … 398 343 // prompt user for color 399 344 System.out.println("Enter a dot color (G/Y/R):"); 400 dotColorInput = sc.next() ;345 dotColorInput = sc.next().toUpperCase(); 401 346 System.out.println(""); 402 347 // validate user's input 403 if( dotColorInputList.contains(dotColorInput))348 if(DOTCOLOR.allLetters.contains(dotColorInput)) 404 349 { 405 350 verified = true; … … 414 359 } 415 360 416 /**417 * Enum for highway status dot colors. Each color has associated volume418 * and occupancy constants.419 *420 * @author John A. Torres, jdalbey421 * @version 10/11/2017422 */423 public static enum DOTCOLOR {424 425 RED(1, 0.06f),426 YELLOW(3,0.059f), // speed = 26427 GREEN(0,0);428 429 // All the first letters of the values, in order.430 private static String allLetters = "RYG";431 432 private int vol; /* volume */433 private float occ; /* occupancy */434 435 private DOTCOLOR(int v, float o)436 {437 vol = v;438 occ = o;439 }440 /**441 * Return the first letter of this enum.442 *443 * @return String first letter of this enum.444 */445 public String getLetter() {446 return this.toString().substring(0, 1);447 }448 449 public int volume()450 {451 return vol;452 }453 public float occupancy()454 {455 return occ;456 }457 /**458 * Returns a dot color given its first character.459 *460 * @param letter the first character of a dot color461 * @return dot color corresponding to letter462 * @pre letter must be one of allLetters463 */464 public static DOTCOLOR toDotColor(String letter) {465 return values()[allLetters.indexOf(letter.charAt(0))];466 }467 }468 361 } -
trunk/src/atmsdriver/model/Highways.java
r176 r180 109 109 return highways; 110 110 } 111 111 /** 112 * Applies specified color to the specified highway stretch. Route number and 113 * direction specify the highway. Postmile and range specify the stretch of 114 * specified highway. Dot color is the color to be applied to the stretch. 115 * 116 * @param routeNumber highway route number 117 * @param direction highway direction 118 * @param postmile origin postmile value 119 * @param range range from origin postmile 120 * @param dotColor the color to be applied to specified highway stretch 121 */ 122 public void applyColorToHighwayStretch(Integer routeNumber, Station.DIRECTION direction, 123 Double postmile, Double range, LoopDetector.DOTCOLOR dotColor) { 124 System.out.println("Applying " + dotColor.name() + " dots to highway " 125 + routeNumber + " " + direction.name() + " at postmile " 126 + postmile + " with a range of " + range + " miles..."); 127 128 // Get the highway by route number 129 Highway highway = getHighwayByRouteNumber(routeNumber); 130 131 // start value for highway section, and end value for highway section 132 // by postmile 133 Double startPost; 134 Double endPost; 135 136 // postmiles increase from s to n and w to e 137 138 // if the direction is south or west 139 if(direction.equals(Station.DIRECTION.SOUTH) || direction.equals(Station.DIRECTION.WEST)) 140 { 141 // add range value to startPost to get 142 // the end postmile value of the highway section 143 startPost = postmile; 144 endPost = postmile + range; 145 146 // iterate through the stations, if within the specified highway 147 // stretch, update the station by direction and apply dot color 148 for(Station station : highway.stations) 149 { 150 if(station.postmile >= startPost && station.postmile <= endPost) 151 { 152 station.updateByDirection(direction, dotColor); 153 } 154 } 155 } 156 // if the direction is north or east 157 else 158 { 159 //subtract range value from startPost 160 // to get the end postmile value of the highway section 161 startPost = postmile; 162 endPost = postmile - range; 163 164 // iterate through the stations, if within the specified highway 165 // section, update the station by direction and apply dot color 166 for(Station station : highway.stations) 167 { 168 if(station.postmile <= startPost && station.postmile >= endPost) 169 { 170 station.updateByDirection(direction, dotColor); 171 } 172 } 173 } 174 System.out.println(""); 175 } 176 112 177 /* 113 178 private ArrayList<FEPLine> loadLines(String highwayMetaFileName) { -
trunk/src/atmsdriver/model/LoopDetector.java
r176 r180 121 121 loopElement.appendChild(spdElement); 122 122 } 123 124 /** 125 * Enum for highway status dot colors. Each color has associated volume 126 * and occupancy constants. 127 * 128 * @author John A. Torres, jdalbey 129 * @version 10/11/2017 130 */ 131 public static enum DOTCOLOR { 132 133 RED(1, 0.06f), // "Stopped" is less than 25mph 134 YELLOW(3,0.059f), // speed = 26 135 GREEN(0,0); 136 137 // All the first letters of the values, in order. 138 public static String allLetters = "RYG"; 139 140 private int vol; /* volume */ 141 private float occ; /* occupancy */ 142 143 private DOTCOLOR(int v, float o) 144 { 145 vol = v; 146 occ = o; 147 } 148 /** 149 * Return the first letter of this enum. 150 * 151 * @return String first letter of this enum. 152 */ 153 public String getLetter() { 154 return this.toString().substring(0, 1); 155 } 156 157 public int volume() 158 { 159 return vol; 160 } 161 public float occupancy() 162 { 163 return occ; 164 } 165 /** 166 * Returns a dot color given its first character. 167 * 168 * @param letter the first character of a dot color 169 * @return dot color corresponding to letter 170 * @pre letter must be one of allLetters 171 */ 172 public static DOTCOLOR toDotColor(String letter) { 173 return values()[allLetters.indexOf(letter.charAt(0))]; 174 } 175 } 176 123 177 } -
trunk/src/atmsdriver/model/Station.java
r168 r180 1 1 package atmsdriver.model; 2 2 3 import atmsdriver.Console Driver;4 import atmsdriver. ConsoleDriver.DOTCOLOR;3 import atmsdriver.ConsoleTrafficDriver; 4 import atmsdriver.model.LoopDetector.DOTCOLOR; 5 5 import java.util.List; 6 6 import org.w3c.dom.Document; … … 174 174 private void outputUpdateMessage(DOTCOLOR dotcolor, String OPP_ML) 175 175 { 176 System.out.printf("Updating route%-3.3s %-5.5s %-3.3s lanes\t %-12.12s "176 System.out.printf("Updating %-3.3s %-5.5s %-3.3s lanes\t %-12.12s " 177 177 + "at postmile %-6.6s to %-7.7s\n", 178 178 Integer.toString(this.routeNumber), this.direction.name(), -
trunk/src/tmcsim/client/ATMSBatchDriver.java
r172 r180 2 2 3 3 import atmsdriver.ATMSDriver; 4 import atmsdriver.Console Driver;4 import atmsdriver.ConsoleTrafficDriver; 5 5 import atmsdriver.ExchangeInfo; 6 6 import atmsdriver.model.Highways; 7 7 import atmsdriver.model.Station; 8 import atmsdriver.model.LoopDetector.DOTCOLOR; 8 9 import java.awt.event.ActionEvent; 9 10 import java.awt.event.ActionListener; … … 121 122 private Map<String, List<String>> incidents; 122 123 123 /** Instance of Console Driver that contains the highway model */124 private Console Driver console;124 /** Instance of ConsoleTrafficDriver that contains the highway model */ 125 private ConsoleTrafficDriver console; 125 126 126 127 /** GUI for this driver */ … … 147 148 "config/vds_data/loop.txt", 148 149 "config/vds_data/highwaysMeta.txt", 149 "192.168.251.46", 8080); //IP address of FEP Sim Linux VM 150 // "localhost", 8080); 151 // Create console driver but don't start run() method 152 console = new ConsoleDriver(highways); 150 // "192.168.251.46", 8080); //IP address of FEP Sim Linux VM 151 "localhost", 8080); 153 152 154 153 connect(cadClientProp.getProperty(PROPERTIES.CAD_SIM_HOST.name).trim(), … … 227 226 double postmile = lineScan.nextDouble(); 228 227 double range = lineScan.nextDouble(); 229 ConsoleDriver.DOTCOLOR dotcolor = ConsoleDriver.DOTCOLOR.toDotColor(lineScan.next());228 DOTCOLOR dotcolor = DOTCOLOR.toDotColor(lineScan.next()); 230 229 // apply colorization to highways 231 console.applyColorToHighwayStretch(routeNumber, dir, postmile, range, dotcolor);230 highways.applyColorToHighwayStretch(routeNumber, dir, postmile, range, dotcolor); 232 231 // Remove this event from the queue, we're done with it. 233 232 eventQueue.remove(); … … 322 321 double range = lineScan.nextDouble(); 323 322 // apply colorization to highways, forcing to green, indicating cleared 324 console.applyColorToHighwayStretch(routeNumber, dir, postmile, range, ConsoleDriver.DOTCOLOR.GREEN);323 highways.applyColorToHighwayStretch(routeNumber, dir, postmile, range, DOTCOLOR.GREEN); 325 324 } 326 325 catch (InputMismatchException ex)
Note: See TracChangeset
for help on using the changeset viewer.
