source: tmcsimulator/trunk/test/atmsdriver/TrafficModelEventDriver.java @ 343

Revision 343, 4.1 KB checked in by jdalbey, 7 years ago (diff)

Fix defect #117. Update HighwaysTest?.java for new highway model.

Line 
1package atmsdriver;
2
3import atmsdriver.model.Highways;
4import atmsdriver.model.TrafficEvent;
5import java.io.FileInputStream;
6import java.io.FileNotFoundException;
7import java.rmi.RemoteException;
8import java.util.HashMap;
9import java.util.LinkedList;
10import java.util.List;
11import java.util.Map;
12import java.util.Properties;
13import java.util.Scanner;
14import java.util.logging.Level;
15import java.util.logging.Logger;
16import javax.swing.JOptionPane;
17import javax.swing.JWindow;
18import tmcsim.cadsimulator.managers.TrafficModelManager;
19import tmcsim.common.SimulationException;
20
21/**
22 * OBSOLETE: An interactive version is now available:
23 *    atmsdriver.TrafficEventsAnimator.java
24 * Read and process all Traffic Events in a file and show
25 * resulting highway network.
26 * A console display of the highway network is output
27 * for each event.
28 * This application is used by Traffic Event authors to assist
29 * in verifying the correctness of their data file.
30 * Because the output is sent immediately to the console the
31 * author doesn't have to sit through simulation time to
32 * observe dots changing on ATMS client.
33 * @author jdalbey
34 */
35public class TrafficModelEventDriver 
36{
37    /**
38     * Error logger.
39     */
40    private static Logger logger = Logger.getLogger("trafficmodeleventdriver");
41
42    /**
43     * Highways in traffic network
44     */
45    final private Highways highways;
46
47    /**
48     * LinkedList of batch events
49     */
50    private LinkedList<TrafficEvent> eventQueue;
51    /**
52     * Map of incidents to events
53     */
54    private Map<String, List<TrafficEvent>> incidents;
55
56    /**
57     * Constructor. Load highways and events.
58     *
59     */
60    public TrafficModelEventDriver() throws RemoteException, SimulationException
61    {
62        // Initialize the highway model
63        incidents = new HashMap<String, List<TrafficEvent>>();
64        highways = new Highways(
65                "config/vds_data/highways_fullmap.txt",
66                // following aren't used by this application
67                "localhost", 8080);
68        final String CONFIG_FILE_NAME = "traffic_model_config.properties";
69        String propertiesFile = "config" + System.getProperty("file.separator") 
70                 + CONFIG_FILE_NAME;
71        Properties props = TrafficModelManager.loadProperties(propertiesFile);
72
73        FileInputStream fis = null;
74        try
75        {
76            fis = new FileInputStream(props.getProperty("Events_File"));
77        } catch (FileNotFoundException ex)
78        {
79            Logger.getLogger(TrafficModelManager.class.getName()).log(Level.SEVERE, null, 
80                    "Missing Traffic Events file " + props.getProperty("Events_File"));
81            System.exit(-1);
82        }
83        Scanner fileScanner = new Scanner(fis);       
84        // Read all lines from the file of events and put in a queue
85        eventQueue = TrafficModelManager.readBatchFile(fileScanner);
86    }
87    public void run()
88    {
89        // If we have any events left to process
90        while (!eventQueue.isEmpty())
91        {
92            // Get next event
93            TrafficEvent nextEvent = eventQueue.peek();
94            System.out.println("LAUNCHING EVENT: " + nextEvent.toString());
95            // apply colorization to highways
96            highways.applyColorToHighwayStretch(nextEvent.routeNumber, nextEvent.dir,
97                    nextEvent.postmile, nextEvent.range, nextEvent.color);
98            System.out.println(highways.toString());
99            // Remove this event from the queue, we're done with it.
100            eventQueue.remove();
101        }
102    }
103
104    /**
105     * local main to launch the app.
106     *
107     * @param args Command line arguments.
108     */
109    public static void main(String[] args)
110    {
111        try
112        {
113            TrafficModelEventDriver driver = new TrafficModelEventDriver();
114            driver.run();
115        }
116        catch (Exception e)
117        {
118            logger.logp(Level.SEVERE, "Traffic Model Event Driver", "Main",
119                    "Error initializing application.");
120
121            JOptionPane.showMessageDialog(new JWindow(), e.getMessage(),
122                    "Error - Program Exiting", JOptionPane.ERROR_MESSAGE);
123
124            System.exit(-1);
125        }
126
127    }
128
129}
Note: See TracBrowser for help on using the repository browser.