- Timestamp:
- 10/31/2017 02:08:33 PM (9 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
-
atmsdriver/model/TrafficEvent.java (modified) (3 diffs)
-
tmcsim/cadsimulator/managers/TrafficModelManager.java (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/atmsdriver/model/TrafficEvent.java
r197 r204 6 6 import java.util.Date; 7 7 import java.util.Scanner; 8 8 9 9 10 /** … … 27 28 public final double range; 28 29 public final String rawString; 30 29 31 private final static SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); 30 32 … … 61 63 return rawString; 62 64 } 65 @Override 66 public boolean equals(Object other) 67 { 68 Boolean result = false; 69 if (other == null) return false; 70 if ( other instanceof TrafficEvent ) 71 { 72 TrafficEvent that = (TrafficEvent) other; 73 result = that.incident.equals(this.incident) 74 && that.eventTime.equals(this.eventTime) 75 && ((int) that.postmile) == ((int) this.postmile) 76 && that.dir == this.dir 77 && that.color == this.color; 78 } 79 return result; 80 } 63 81 } -
trunk/src/tmcsim/cadsimulator/managers/TrafficModelManager.java
r197 r204 47 47 * Error Logger. 48 48 */ 49 private static Logger atmsLogger = Logger.getLogger("tmcsim.cadsimulator.managers");49 private static Logger logger = Logger.getLogger("tmcsim.cadsimulator.managers"); 50 50 51 51 /** … … 56 56 private static enum PROPERTIES 57 57 { 58 /**59 *60 */61 58 HIGHWAYS_MAP_FILE("Highways_Map_File"), 62 /**63 *64 */65 59 FEPSIM_IP_ADDR("FEPSim_IP_addr"), 66 /**67 *68 */69 60 EVENTS_FILE("Events_File"), 70 61 OUTPUT_DEST("Output_Destination"); … … 82 73 * Properties Object. 83 74 */ 84 private Properties atmsProperties = null;75 private Properties props = null; 85 76 /** 86 77 * Highways in traffic network … … 113 104 throws SimulationException 114 105 { 115 if (!loadProperties(propertiesFile)) 116 { 117 System.exit(0); 118 } 119 // final Coordinator theCoordinator = theCoordinator; 106 props = loadProperties(propertiesFile); 120 107 // Initialize the highway model 121 108 incidents = new HashMap<String, List<TrafficEvent>>(); 122 109 highways = new Highways( 123 atmsProperties.getProperty(PROPERTIES.HIGHWAYS_MAP_FILE.name), 124 //"config/vds_data/highways_fullmap.txt", 125 // "192.168.251.46", 8080); //IP address of FEP Sim Linux VM 126 atmsProperties.getProperty(PROPERTIES.FEPSIM_IP_ADDR.name), 110 props.getProperty(PROPERTIES.HIGHWAYS_MAP_FILE.name), 111 props.getProperty(PROPERTIES.FEPSIM_IP_ADDR.name), 127 112 8080); 128 113 129 // READ THE BATCH FILE OF COMMANDS and put in a queue 130 eventQueue = readBatchFile(); 131 // Launch the display 114 // Read the text file of events and put in a queue 115 FileInputStream fis = null; 116 try 117 { 118 fis = new FileInputStream(props.getProperty(PROPERTIES.EVENTS_FILE.name)); 119 } catch (FileNotFoundException ex) 120 { 121 Logger.getLogger(TrafficModelManager.class.getName()).log(Level.SEVERE, null, 122 "Missing Traffic Events file " + props.getProperty(PROPERTIES.EVENTS_FILE.name)); 123 System.exit(-1); 124 } 125 // Read all lines from the file of events 126 Scanner fileScanner = new Scanner(fis); 127 eventQueue = readBatchFile(fileScanner); 128 // Extract the incidents and create a map 129 incidents = createIncidentMap(eventQueue); 130 // Launch the GUI display 132 131 theView = new TrafficModelViewer(this, new ArrayList<String>(incidents.keySet())); 133 132 theView.setVisible(true); … … 147 146 { 148 147 long simtime = theCoordinator.getCurrentSimulationTime(); 149 currentClock = format Interval(simtime);148 currentClock = formatTimeInSeconds(simtime); 150 149 // For Debugging, show the ATMS time 151 150 // long ATMStime = theCoorInt.getATMStime(); … … 159 158 { 160 159 Logger.getLogger(TrafficModelManager.class.getName()).log(Level.SEVERE, null, ex); 161 System.out.println("Invalid simulation clock time found in ATMSDriverClient");160 System.out.println("Invalid simulation clock time found"); 162 161 System.exit(-1); 163 162 } 164 //System.out.println("Current clock: " + currentClock);165 163 } 166 164 catch (RemoteException ex) … … 175 173 TrafficEvent nextEvent = eventQueue.peek(); 176 174 Date eventTime = nextEvent.eventDate; 177 //System.out.println("Next event will be launched at: " + formatter.format(eventTime));178 175 // Check the queue of events to see if the first 179 176 // item should be launched. IF so, … … 195 192 timer.start(); 196 193 197 if ( atmsProperties.getProperty(PROPERTIES.OUTPUT_DEST.name).equals("FEP"))194 if (props.getProperty(PROPERTIES.OUTPUT_DEST.name).equals("FEP")) 198 195 { 199 196 // Start the FEP thread (to update ATMS every 30 sec). (See class def below) … … 210 207 211 208 /** 212 * This method verifies that the CAD Simulator Host and Port values are not 213 * null. Also, if a CAD Position or User ID do not exist in the properties 214 * file, the user is prompted to enter values. These values are written to 215 * the properties file. If the user cancels the process of entering these 216 * values, the verification fails. 209 * This method verifies that the needed configuration properties are not 210 * null. 217 211 * 218 212 * @param propertiesFile File path (absolute or relative) to the properties 219 213 * file containing configuration data. 220 * @return T rue if the properties file is valid, false if not.214 * @return The Properties loaded 221 215 * @throws SimulationException if there is an exception in verifying the 222 * properties file , or if the user cancels input.223 */ 224 p rivate booleanloadProperties(String propertiesFile)216 * properties file 217 */ 218 public static Properties loadProperties(String propertiesFile) 225 219 throws SimulationException 226 220 { 221 Properties props; 227 222 // Load the properties file. 228 223 try 229 224 { 230 atmsProperties = new Properties();231 atmsProperties.load(new FileInputStream(propertiesFile));225 props = new Properties(); 226 props.load(new FileInputStream(propertiesFile)); 232 227 233 228 } catch (Exception e) 234 229 { 235 atmsLogger.logp(Level.SEVERE, "TrafficModelManager", "Constructor", 236 "Exception in parsing properties file.", e); 237 throw new SimulationException(SimulationException.INITIALIZE_ERROR, 238 e); 239 } 240 230 throw new SimulationException(SimulationException.INITIALIZE_ERROR); 231 } 241 232 242 233 // Ensure that the properties file does not have null values for the 243 234 // required information. 244 if (atmsProperties.getProperty(PROPERTIES.HIGHWAYS_MAP_FILE.name) == null 245 || atmsProperties.getProperty(PROPERTIES.FEPSIM_IP_ADDR.name) == null 246 || atmsProperties.getProperty(PROPERTIES.EVENTS_FILE.name) == null 247 || atmsProperties.getProperty(PROPERTIES.OUTPUT_DEST.name) == null) 248 { 249 atmsLogger.logp(Level.SEVERE, "TrafficModelManager", 250 "Constructor", "Null value in properties file."); 235 if (props.getProperty(PROPERTIES.HIGHWAYS_MAP_FILE.name) == null 236 || props.getProperty(PROPERTIES.FEPSIM_IP_ADDR.name) == null 237 || props.getProperty(PROPERTIES.EVENTS_FILE.name) == null 238 || props.getProperty(PROPERTIES.OUTPUT_DEST.name) == null) 239 { 240 System.out.println("Missing property value in "+propertiesFile); 251 241 throw new SimulationException(SimulationException.INITIALIZE_ERROR); 252 242 } 253 243 254 return true;244 return props; 255 245 } 256 246 /** 257 247 * Read a file of traffic events. 248 * @param filename the name of the events file 258 249 * @return the chronologically ordered list of events 259 250 */ 260 // Method is package private to facilitate unit testing. 261 LinkedList<TrafficEvent> readBatchFile() 262 { 263 FileInputStream fis; 251 public static LinkedList<TrafficEvent> readBatchFile(Scanner scan) 252 { 264 253 LinkedList<TrafficEvent> eventList = new LinkedList<TrafficEvent>(); 265 try266 {267 fis = new FileInputStream(268 //"config/vds_data/atmsBatchEvents.txt");269 atmsProperties.getProperty(PROPERTIES.EVENTS_FILE.name));270 // Read all lines from the file of events271 Scanner scan = new Scanner(fis);272 254 while (scan.hasNext()) 273 255 { … … 281 263 evt = new TrafficEvent(line); 282 264 eventList.add(evt); 283 String incident = evt.incident;284 // Add the line to the list for the corresponding incident285 List evtList;286 if (incidents.containsKey(evt.incident))287 {288 evtList = incidents.get(evt.incident);289 }290 else291 {292 evtList = new ArrayList<String>();293 }294 evtList.add(evt);295 // and put it back in the map296 incidents.put(incident, evtList);297 265 } 298 266 catch (ParseException ex) … … 304 272 } 305 273 } 306 }307 catch (FileNotFoundException ex)308 {309 Logger.getLogger(TrafficModelManager.class.getName()).log(Level.SEVERE, null, ex);310 }311 274 System.out.println("Events file read, " + eventList.size() + " events queued."); 312 275 // Put the events in chronological order … … 315 278 } 316 279 280 static Map<String, List<TrafficEvent>> createIncidentMap(LinkedList<TrafficEvent> eventList) 281 { 282 Map<String, List<TrafficEvent>> incidents = new HashMap<String, List<TrafficEvent>>(); 283 for (TrafficEvent evt: eventList) 284 { 285 // Add the line to the list for the corresponding incident 286 List evtList; 287 if (incidents.containsKey(evt.incident)) 288 { 289 evtList = incidents.get(evt.incident); 290 } 291 else 292 { 293 evtList = new ArrayList<String>(); 294 } 295 evtList.add(evt); 296 // and put it back in the map 297 incidents.put(evt.incident, evtList); 298 } 299 return incidents; 300 } 301 317 302 /** 318 303 * Clear an incident. For each event associated with an incident, turn the … … 349 334 * Format a time in seconds as HH:MM:SS 350 335 * 351 * @param l352 * @return 353 */ 354 p rivate String formatInterval(final long l)355 { 356 final long hr = TimeUnit.SECONDS.toHours( l);357 final long min = TimeUnit.SECONDS.toMinutes( l- TimeUnit.HOURS.toSeconds(hr));358 final long sec = TimeUnit.SECONDS.toSeconds( l- TimeUnit.HOURS.toSeconds(hr) - TimeUnit.MINUTES.toSeconds(min));336 * @param seconds 337 * @return HH:MM:SS formatted string 338 */ 339 public static String formatTimeInSeconds(final long seconds) 340 { 341 final long hr = TimeUnit.SECONDS.toHours(seconds); 342 final long min = TimeUnit.SECONDS.toMinutes(seconds - TimeUnit.HOURS.toSeconds(hr)); 343 final long sec = TimeUnit.SECONDS.toSeconds(seconds - TimeUnit.HOURS.toSeconds(hr) - TimeUnit.MINUTES.toSeconds(min)); 359 344 return String.format("%02d:%02d:%02d", hr, min, sec); 360 345 } … … 384 369 catch (Exception e) 385 370 { 386 atmsLogger.logp(Level.SEVERE, "SimulationManager", "Main",371 logger.logp(Level.SEVERE, "SimulationManager", "Main", 387 372 "Error initializing application."); 388 373 … … 409 394 try 410 395 { 411 Thread.sleep( 1000);396 Thread.sleep(5000); 412 397 } 413 398 catch (InterruptedException ie)
Note: See TracChangeset
for help on using the changeset viewer.
