Changeset 204 in tmcsimulator for trunk/test/atmsdriver/TrafficModelEventDriver.java
- Timestamp:
- 10/31/2017 02:08:33 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/atmsdriver/TrafficModelEventDriver.java
r194 r204 6 6 import java.io.FileNotFoundException; 7 7 import java.rmi.RemoteException; 8 import java.text.ParseException;9 import java.text.SimpleDateFormat;10 import java.util.ArrayList;11 import java.util.Collections;12 8 import java.util.HashMap; 13 9 import java.util.LinkedList; 14 10 import java.util.List; 15 11 import java.util.Map; 12 import java.util.Properties; 16 13 import java.util.Scanner; 17 14 import java.util.logging.Level; … … 19 16 import javax.swing.JOptionPane; 20 17 import javax.swing.JWindow; 18 import tmcsim.cadsimulator.managers.TrafficModelManager; 19 import tmcsim.common.SimulationException; 21 20 22 21 /** 23 * Skeleton for ATMS Driver that reads a "batch" file of highway status update 24 * commands. A console display of the highway network is output 22 * Read and process all Traffic Events in a file and show 23 * resulting highway network. 24 * A console display of the highway network is output 25 25 * for each event. 26 * This application is used by Traffic Event authors to assist 27 * in verifying the correctness of their data file. 28 * Because the output is sent immediately to the console the 29 * author doesn't have to sit through simulation time to 30 * observe dots changing on ATMS client. 26 31 * @author jdalbey 27 32 */ … … 51 56 * 52 57 */ 53 public TrafficModelEventDriver() throws RemoteException 58 public TrafficModelEventDriver() throws RemoteException, SimulationException 54 59 { 55 60 // Initialize the highway model … … 57 62 highways = new Highways( 58 63 "config/vds_data/highways_fullmap.txt", 59 // "192.168.251.46", 8080); //IP address of FEP Sim Linux VM64 // following aren't used by this application 60 65 "localhost", 8080); 66 final String CONFIG_FILE_NAME = "traffic_model_config.properties"; 67 String propertiesFile = "config" + System.getProperty("file.separator") 68 + CONFIG_FILE_NAME; 69 Properties props = TrafficModelManager.loadProperties(propertiesFile); 61 70 62 // READ THE BATCH FILE OF COMMANDS and put in a queue 63 readBatchFile(); 71 FileInputStream fis = null; 72 try 73 { 74 fis = new FileInputStream(props.getProperty("Events_File")); 75 } catch (FileNotFoundException ex) 76 { 77 Logger.getLogger(TrafficModelManager.class.getName()).log(Level.SEVERE, null, 78 "Missing Traffic Events file " + props.getProperty("Events_File")); 79 System.exit(-1); 80 } 81 Scanner fileScanner = new Scanner(fis); 82 // Read all lines from the file of events and put in a queue 83 eventQueue = TrafficModelManager.readBatchFile(fileScanner); 64 84 } 65 85 public void run() … … 78 98 eventQueue.remove(); 79 99 } 80 }81 82 private void readBatchFile()83 {84 FileInputStream fis;85 try86 {87 fis = new FileInputStream("config/vds_data/atmsBatchEvents.txt");88 eventQueue = new LinkedList<TrafficEvent>();89 // Read all lines from the file of events90 Scanner scan = new Scanner(fis);91 while (scan.hasNext())92 {93 // Read a line and add it to the event queue94 String line = scan.nextLine().trim();95 if (line.charAt(0) != '#')96 {97 TrafficEvent evt;98 try99 {100 evt = new TrafficEvent(line);101 eventQueue.add(evt);102 String incident = evt.incident;103 // Add the line to the list for the corresponding incident104 List evtList;105 if (incidents.containsKey(evt.incident))106 {107 evtList = incidents.get(evt.incident);108 }109 else110 {111 evtList = new ArrayList<String>();112 }113 evtList.add(evt);114 // and put it back in the map115 incidents.put(incident, evtList);116 }117 catch (ParseException ex)118 {119 Logger.getLogger(TrafficModelEventDriver.class.getName()).log(Level.SEVERE, null, ex);120 System.out.println("Wrong format data in batch event file: " + line + " \nskipping.");121 System.out.println("Skipping badly formatted event.");122 }123 }124 }125 }126 catch (FileNotFoundException ex)127 {128 Logger.getLogger(TrafficModelEventDriver.class.getName()).log(Level.SEVERE, null, ex);129 }130 System.out.println("Events file read, " + eventQueue.size() + " events queued.");131 // Put the events in chronological order132 Collections.sort(eventQueue);133 100 } 134 101
Note: See TracChangeset
for help on using the changeset viewer.
