Changeset 87 in tmcsimulator for trunk/src/atmsdriver/ATMSDriver.java


Ignore:
Timestamp:
10/10/2017 01:09:50 AM (9 years ago)
Author:
jtorres
Message:

merged branches/trunk into regular tmcsim/trunk. Changed Network.java to Highways.java. Highways.java: added writeToFEP(), updateSequences(), loadHighways(), and writeHighwaysMeta(). writeToFEP() is a socket client that communicates with FEPSimulator socket server. updateSequences() updates global and schedule sequences per the existing UCI plugin code and may not be necessary. loadHighways() loads the ArrayList? of Highways used in highways class, in sorted order. Stations are now implementing comparable to sort by postmile. writeHighwaysMeta() is an attempt at writing the highways meta data in condensed form, because loading time in NetworkLoader? is super long. We will eventually get rid of NetworkLoader? and do it within the Highways class for good OOP practice. There are new properties in atms_driver_properties.properties in config to support all these changes. Highway.java: new class, represents a highway which is a sorted ArrayList? of stations. This is a good checkpoint, for persistent green dots and all is working within the triangle. There is much commented out code in Highways.java which does not quite work. This commented code is an attempt at writing the condensed form highway meta data to improve loading times as described above.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/atmsdriver/ATMSDriver.java

    r79 r87  
    11package atmsdriver; 
    22 
    3 import atmsdriver.model.Network; 
     3import atmsdriver.model.Highways; 
    44import java.io.File; 
    55import java.io.FileInputStream; 
     6import java.io.FileNotFoundException; 
     7import java.io.PrintWriter; 
    68import java.util.Properties; 
    79import java.util.logging.Level; 
     
    911 
    1012/** 
     13 * ATMS Driver reads the current simulation traffic conditions from the 
     14 * EXCHANGE.XML file and constructs the Highway Network status info in the 
     15 * format required by the FEP. It then sends this XML data over a socket to the 
     16 * FEP Simulator. 
    1117 * 
    1218 * @author John A. Torres 
     
    1521public class ATMSDriver implements Runnable { 
    1622 
    17     /** ATMSDriver Error logger. */ 
     23    /** 
     24     * ATMSDriver Error logger. 
     25     */ 
    1826    private static Logger ATMSDriverLogger = Logger.getLogger("atmsdriver"); 
    1927 
    2028    private static final String CONFIG_FILE_NAME = "atms_driver_config.properties"; 
    2129 
    22     /** Properties object for the CADClient class. */ 
     30    /** 
     31     * Properties object for the CADClient class. 
     32     */ 
    2333    private Properties ATMSDriverProperties; 
    2434 
     
    3141     */ 
    3242    private static enum PROPERTIES { 
    33  
    3443        LDS_FILE_NAME("LDSFileName"), 
    35         LOOP_FILE_NAME("LoopFileName"), 
    36         NETWORK_FILE_NAME("NetworkFileName"), 
    37         EXCHANGE_FILE_NAME("ExchangeFileName"); 
     44        LOOPS_FILE_NAME("LoopsFileName"), 
     45        HIGHWAY_META_FILE("HighwayMetaFileName"), 
     46        EXCHANGE_FILE_NAME("ExchangeFileName"), 
     47        FEP_WRITER_HOST("FEPWriterHost"), 
     48        FEP_WRITER_PORT("FEPWriterPort"); 
    3849 
    3950        public String name; 
     
    4455    } 
    4556 
    46     /** Network model. */ 
    47     final private Network network; 
    48      
    49     /** Sleep Time (10 seconds). **/ 
    50     private static final int SLEEP_TIME = 10000; 
    51      
    52     /** Exchange Reader */ 
     57    /** 
     58     * Highways in traffic network 
     59     */ 
     60    final private Highways highways; 
     61 
     62    /** 
     63     * Sleep Time (30 seconds). * 
     64     */ 
     65    private static final int SLEEP_TIME = 30000; 
     66 
     67    /** 
     68     * Exchange Reader 
     69     */ 
    5370    private ExchangeReader exchangeReader; 
    54      
     71 
    5572    @Override 
    5673    public void run() { 
    5774        // Check for packets and update the simulator 
    58         for (;;) { 
     75        while (true) { 
    5976            // Flush the input file 
    6077            ExchangeInfo exInfo = exchangeReader.parse(ATMSDriverProperties 
    6178                    .getProperty(PROPERTIES.EXCHANGE_FILE_NAME.name)); 
    62             network.toXML(); 
    63             // Update if packet is recieved 
     79 
     80            System.out.println(highways.toXML()); 
     81            highways.writeToFEP(); 
     82            // Update if exchangeInfo is recieved 
    6483            if (exInfo != null) { 
    65                 System.out.println("Grabbed"); 
     84                // TODO: handle this condition 
     85                Logger.getLogger("ATMSDriver").log(Level.INFO, "exInfo is not null"); 
    6686            } 
    6787 
    68             // Sleep 
     88            // Wait for FEP Sim to process the data we just sent 
    6989            try { 
    7090                Thread.sleep(SLEEP_TIME); 
    7191            } catch (InterruptedException ie) { 
    72                  
     92                ie.printStackTrace(); 
    7393            } 
    7494        } 
     
    81101        } 
    82102 
    83         network = new Network( 
    84                 new File(ATMSDriverProperties.getProperty( 
    85                                 PROPERTIES.LDS_FILE_NAME.name)), 
    86                 new File(ATMSDriverProperties.getProperty( 
    87                                 PROPERTIES.LOOP_FILE_NAME.name)), 
    88                 new File(ATMSDriverProperties.getProperty( 
    89                                 PROPERTIES.NETWORK_FILE_NAME.name))); 
    90         network.toXML(); 
     103        highways = new Highways( 
     104                ATMSDriverProperties.getProperty( 
     105                                PROPERTIES.LDS_FILE_NAME.name), 
     106                ATMSDriverProperties.getProperty( 
     107                                PROPERTIES.LOOPS_FILE_NAME.name), 
     108                ATMSDriverProperties.getProperty( 
     109                                PROPERTIES.HIGHWAY_META_FILE.name), 
     110                ATMSDriverProperties.getProperty(PROPERTIES.FEP_WRITER_HOST.name), 
     111                Integer.parseInt(ATMSDriverProperties.getProperty( 
     112                                PROPERTIES.FEP_WRITER_PORT.name))); 
     113         
    91114        exchangeReader = new ExchangeReader(); 
    92115    } 
     
    106129 
    107130    /** 
    108      * Runs the Paramics simulator. 
     131     * Runs the ATMS Driver. 
    109132     */ 
    110133    public static void main(String[] args) { 
Note: See TracChangeset for help on using the changeset viewer.