Changeset 184 in tmcsimulator for trunk


Ignore:
Timestamp:
10/28/2017 05:24:02 PM (9 years ago)
Author:
jtorres
Message:

highways.java: converted to immutable, removed use of FEPLineLoader and added loadLines(), loadLine(), loadStation(), and loadLoop() methods. Renamed loadHighways() to configureHighways(), renamed writeHighwaysMeta() to getHighwaysMeta() which now returns a String containing metadata instead of opening a file and writing to it, which is more flexible. FEPLineLoader.java: deleted, no longer need it. FEPLine.java: converted to immutable, removed unnecessary member variables and adjusted all methods accordingly. Station.java: MLTotVol() and OppTotVol?() are now being updated at end of updateByDirection(). ATMSDriver.java: Now using one config file: highways_fullmap.txt, as opposed to the older lds.txt and loop.txt files. config/vds_data: added highways_fullmap.txt. config/atms_driver_config.properties, atms_driver_config_local.properties: updated config to reflect use of highways_fullmap.txt instead of old loop.txt and lds.txt configuration. ATMSBatchDriver.java: conformed highways initialization in constructor to reflect use of highways_fullmap.txt

Location:
trunk
Files:
1 added
1 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/config/atms_driver_config.properties

    r101 r184  
    1 LDSFileName = config/vds_data/lds.txt 
    2 LoopsFileName = config/vds_data/loop.txt 
    3 HighwayMetaFileName = config/vds_data/highwaysMeta.txt 
    4 NetworkFileName = networkFile.txt 
     1HighwaysMapFileName = config/vds_data/highways_fullmap.txt 
    52ExchangeFileName = exchange.xml 
    63FEPWriterHost = 192.168.251.46 
  • trunk/config/atms_driver_config_local.properties

    r101 r184  
    1 LDSFileName = config/vds_data/lds.txt 
    2 LoopsFileName = config/vds_data/loop.txt 
    3 HighwayMetaFileName = config/vds_data/highwaysMeta.txt 
    4 NetworkFileName = networkFile.txt 
     1HighwaysMapFileName = config/vds_data/highwaysMeta.txt 
    52ExchangeFileName = exchange.xml 
    63FEPWriterHost = localhost 
  • trunk/src/atmsdriver/ATMSDriver.java

    r180 r184  
    1717 * @version 09/10/2017 
    1818 */ 
    19 public class ATMSDriver implements Runnable { 
     19public class ATMSDriver implements Runnable 
     20{ 
    2021 
    2122    /** 
     
    3637     * @see ATMSDriver 
    3738     */ 
    38     private static enum PROPERTIES { 
    39         LDS_FILE_NAME("LDSFileName"), 
    40         LOOPS_FILE_NAME("LoopsFileName"), 
    41         HIGHWAY_META_FILE("HighwayMetaFileName"), 
     39    private static enum PROPERTIES 
     40    { 
     41        HIGHWAYS_MAP_FILE_NAME("HighwaysMapFileName"), 
    4242        EXCHANGE_FILE_NAME("ExchangeFileName"), 
    4343        FEP_WRITER_HOST("FEPWriterHost"), 
     
    4646        public String name; 
    4747 
    48         private PROPERTIES(String n) { 
     48        private PROPERTIES(String n) 
     49        { 
    4950            name = n; 
    5051        } 
     
    6768 
    6869    @Override 
    69     public void run() { 
     70    public void run() 
     71    { 
    7072        // Check for packets and update the simulator 
    71         while (true) { 
     73        while (true) 
     74        { 
    7275            // Flush the input file 
    7376            ExchangeInfo exInfo = exchangeReader.parse(ATMSDriverProperties 
    7477                    .getProperty(PROPERTIES.EXCHANGE_FILE_NAME.name)); 
    7578 
    76             try { 
     79            try 
     80            { 
    7781                highways.writeToFEP(); 
    78             } catch (SimulationException ex) { 
    79                             System.out.println("Skipping writeToFEP..."); 
     82            } catch (SimulationException ex) 
     83            { 
     84                System.out.println("Skipping writeToFEP..."); 
    8085            } 
    8186            // Update if exchangeInfo is recieved 
    82             if (exInfo != null) { 
     87            if (exInfo != null) 
     88            { 
    8389                // TODO: handle this condition 
    8490                Logger.getLogger("ATMSDriver").log(Level.INFO, "exInfo is not null"); 
     
    8692 
    8793            // Wait for FEP Sim to process the data we just sent 
    88             try { 
     94            try 
     95            { 
    8996                Thread.sleep(SLEEP_TIME); 
    90             } catch (InterruptedException ie) { 
     97            } catch (InterruptedException ie) 
     98            { 
    9199                ie.printStackTrace(); 
    92100            } 
     
    94102    } 
    95103 
    96     public ATMSDriver(String propertiesFile) { 
     104    public ATMSDriver(String propertiesFile) 
     105    { 
    97106        // verify properties file 
    98         if (!verifyProperties(propertiesFile)) { 
     107        if (!verifyProperties(propertiesFile)) 
     108        { 
    99109            System.exit(0); 
    100110        } 
     
    102112        highways = new Highways( 
    103113                ATMSDriverProperties.getProperty( 
    104                                 PROPERTIES.LDS_FILE_NAME.name), 
    105                 ATMSDriverProperties.getProperty( 
    106                                 PROPERTIES.LOOPS_FILE_NAME.name), 
    107                 ATMSDriverProperties.getProperty( 
    108                                 PROPERTIES.HIGHWAY_META_FILE.name), 
     114                        PROPERTIES.HIGHWAYS_MAP_FILE_NAME.name), 
    109115                ATMSDriverProperties.getProperty(PROPERTIES.FEP_WRITER_HOST.name), 
    110116                Integer.parseInt(ATMSDriverProperties.getProperty( 
     
    113119        exchangeReader = new ExchangeReader(); 
    114120    } 
    115      
     121 
    116122    /** 
    117123     * Verifies that the properties file has all necessary properties. 
    118      *  
     124     * 
    119125     * @param propertiesFile 
    120      * @return  
     126     * @return 
    121127     */ 
    122     private boolean verifyProperties(String propertiesFile) { 
     128    private boolean verifyProperties(String propertiesFile) 
     129    { 
    123130        // Load the properties file. 
    124         try { 
     131        try 
     132        { 
    125133            ATMSDriverProperties = new Properties(); 
    126134            ATMSDriverProperties.load(new FileInputStream(propertiesFile)); 
    127         } catch (Exception e) { 
     135        } catch (Exception e) 
     136        { 
    128137            ATMSDriverLogger.logp(Level.SEVERE, "ATMSDriver", 
    129138                    "Constructor", "Exception in reading properties file.", e); 
     
    136145     * Runs the ATMS Driver. 
    137146     */ 
    138     public static void main(String[] args) { 
    139         try { 
    140             if (System.getProperty("ATMSDRIVER_PROPERTIES") != null) { 
     147    public static void main(String[] args) 
     148    { 
     149        try 
     150        { 
     151            if (System.getProperty("ATMSDRIVER_PROPERTIES") != null) 
     152            { 
    141153                // Create and run the ATMSDriver thread 
    142154                ATMSDriver atmsDriver = new ATMSDriver(System.getProperty("ATMSDRIVER_PROPERTIES")); 
    143155                Thread ATMSDriverThread = new Thread(atmsDriver); 
    144156                ATMSDriverThread.start(); 
    145                  
     157 
    146158                // run the console driver, pass it the atmsDriver highways model 
    147159                ConsoleTrafficDriver driver = new ConsoleTrafficDriver(atmsDriver.highways); 
    148                  
    149             } else { 
     160 
     161            } else 
     162            { 
    150163                throw new Exception("ATMSDRIVER_PROPERTIES system property not defined."); 
    151164            } 
    152         } catch (Exception e) { 
     165        } catch (Exception e) 
     166        { 
    153167            ATMSDriverLogger.logp(Level.SEVERE, "ATMSDriver", "Main", 
    154168                    "Error occured initializing application", e); 
  • trunk/src/atmsdriver/ConsoleTrafficDriver.java

    r180 r184  
    88import java.io.FileInputStream; 
    99import java.util.ArrayList; 
    10 import java.util.Arrays; 
    1110import java.util.List; 
    1211import java.util.Properties; 
     
    4847                // Create the Highway Model 
    4948                Highways highways = new Highways( 
    50                     "config/vds_data/lds.txt", 
    51                     "config/vds_data/loop.txt", 
    52                     "config/vds_data/highwaysMeta.txt", 
     49                    "config/vds_data/highways_fullmap.txt", 
    5350                    ConsoleDriverProperties.getProperty( 
    5451                        "FEPWriterHost"), 
  • trunk/src/atmsdriver/model/FEPLine.java

    r103 r184  
    11package atmsdriver.model; 
    22 
     3import java.util.ArrayList; 
    34import java.util.List; 
    45import org.w3c.dom.Document; 
    56import org.w3c.dom.Element; 
    67 
    7 /** An FEPLine is a simulated line of communication from the FEP to  
    8  *  LoopDetectorStations in the traffic network. 
    9  *  
    10  *  An FEPLine contains static meta data and a list of LoopDetectorStations. 
    11  *  A single FEPLine contains multiple LoopDetectorStations. 
     8/** 
     9 * An FEPLine is a simulated line of communication from the FEP to 
     10 * Stations in the highways network. 
     11 * 
     12 * An FEPLine contains static line meta data and a list of Stations. A 
     13 * single FEPLine contains multiple Stations. 
    1214 * 
    1315 * @author John A. Torres 
    1416 * @version 09/10/2017 
    15  */  
    16 public class FEPLine { 
     17 */ 
     18final public class FEPLine 
     19{ 
    1720    /* Static FEPLine meta data */ 
    1821    final public int lineNum; 
    1922    final public List<Station> stations; 
    2023    final private int count; 
    21      
    22     final private int schedule; 
    23     final private int lineInfo; 
    24     final private long systemKey; 
    25      
    26     // THESE WILL NEED TO BE UPDATED MAYBE, NOT SURE, NOT A PRIORITY. SEE METHOD 
    27     // UPDATESEQUENCES() 
    28     private long globalSeq; 
    29     private long scheduleSeq; 
    30      
    31     public FEPLine(int lineNum, List<Station> stations, int count, 
    32             int schedule, int lineInfo, long systemKey, long globalSeq, 
    33             long scheduleSeq) 
     24 
     25    /** 
     26     * Constructs an FEPLine from given line number, list of stations, and count. 
     27     *  
     28     * @param lineNum 
     29     * @param stations 
     30     * @param count  
     31     */ 
     32    FEPLine(int lineNum, ArrayList<Station> stations, int count) 
    3433    { 
    3534        this.lineNum = lineNum; 
    3635        this.stations = stations; 
    3736        this.count = count; 
    38         this.schedule = schedule; 
    39         this.lineInfo = lineInfo; 
    40         this.systemKey = systemKey; 
    41         this.globalSeq = globalSeq; 
    42         this.scheduleSeq = scheduleSeq; 
    4337    } 
    4438     
    45     // NEED TO CHECK NUMBERS? DO WE EVEN NEED THIS? 
    46     public void updateSequences() 
    47     {         
    48         this.scheduleSeq += 1; 
    49         this.globalSeq += 51; 
    50     } 
    51      
     39    /** 
     40     * Returns the FEPLine meta data in string format 
     41     * @return FEPLine metadata 
     42     */ 
    5243    public String getLineMeta() 
    5344    { 
     
    5950        build.append(Integer.toString(this.stations.size())); 
    6051        build.append("\n"); 
    61         for(Station station : stations) 
     52        for (Station station : stations) 
    6253        { 
    6354            build.append(station.getStationMeta()); 
     
    6657    } 
    6758     
     59    /** 
     60     * Returns the FEPLine data in XMLFormat 
     61     *  
     62     * @param currElem The current XML <Line> element 
     63     */ 
    6864    public void toXML(Element currElem) 
    6965    { 
    7066        Document theDoc = currElem.getOwnerDocument(); 
    71          
     67 
    7268        Element lineElement = theDoc.createElement(XML_TAGS.LINE.tag); 
    7369        currElem.appendChild(lineElement); 
    74          
     70 
    7571        Element lineNumElement = theDoc.createElement(XML_TAGS.LINE_NUM.tag); 
    7672        lineNumElement.appendChild(theDoc.createTextNode(String.valueOf(this.lineNum))); 
    7773        lineElement.appendChild(lineNumElement); 
    78          
     74 
    7975        Element countElement = theDoc.createElement(XML_TAGS.COUNT.tag); 
    8076        countElement.appendChild(theDoc.createTextNode(String.valueOf(this.count))); 
    8177        lineElement.appendChild(countElement); 
    82          
    83         Element scheduleElement = theDoc.createElement(XML_TAGS.SCHEDULE.tag); 
    84         scheduleElement.appendChild(theDoc.createTextNode(String.valueOf(this.schedule))); 
    85         lineElement.appendChild(scheduleElement); 
    86          
    87         Element lineInfoElement = theDoc.createElement(XML_TAGS.LINE_INFO.tag); 
    88         lineInfoElement.appendChild(theDoc.createTextNode(String.valueOf(this.lineInfo))); 
    89         lineElement.appendChild(lineInfoElement); 
    90          
    91         Element systemKeyElement = theDoc.createElement(XML_TAGS.SYSTEM_KEY.tag); 
    92         systemKeyElement.appendChild(theDoc.createTextNode(String.valueOf(this.systemKey))); 
    93         lineElement.appendChild(systemKeyElement); 
    94          
    95         Element globalSeqElement = theDoc.createElement(XML_TAGS.GLOBAL_SEQ.tag); 
    96         globalSeqElement.appendChild(theDoc.createTextNode(String.valueOf(this.globalSeq))); 
    97         lineElement.appendChild(globalSeqElement); 
    98          
    99         Element scheduleSeqElement = theDoc.createElement(XML_TAGS.SCHEDULE_SEQ.tag); 
    100         scheduleSeqElement.appendChild(theDoc.createTextNode(String.valueOf(this.scheduleSeq))); 
    101         lineElement.appendChild(scheduleSeqElement); 
    102          
     78 
    10379        Element stationsElement = theDoc.createElement(XML_TAGS.STATIONS.tag); 
    10480        lineElement.appendChild(stationsElement); 
    105         for(Station station : stations) 
     81        for (Station station : stations) 
    10682        { 
    10783            station.toXML(stationsElement); 
     
    10985    } 
    11086     
     87    /** 
     88     * XML Tags used in toXML() 
     89     */ 
    11190    private static enum XML_TAGS 
    11291    { 
     92 
    11393        LINE("Line"), 
    11494        LINE_NUM("Line_Num"), 
    11595        STATIONS("Stations"), 
    116         COUNT("Count"), 
    117         SCHEDULE("Schedule"), 
    118         LINE_INFO("Line_Info"), 
    119         SYSTEM_KEY("System_Key"), 
    120         GLOBAL_SEQ("Global_Seq"), 
    121         SCHEDULE_SEQ("Schedule_Seq"); 
    122          
     96        COUNT("Count"); 
     97 
    12398        String tag; 
    124          
     99 
    125100        private XML_TAGS(String n) 
    126101        { 
  • trunk/src/atmsdriver/model/Highways.java

    r180 r184  
    11package atmsdriver.model; 
    22 
    3 import atmsdriver.FEPLineLoader; 
     3import atmsdriver.model.Station.DIRECTION; 
    44import java.io.File; 
    5 import java.io.FileWriter; 
     5import java.io.FileNotFoundException; 
    66import java.io.IOException; 
    77import java.io.PrintWriter; 
     
    1313import java.util.HashMap; 
    1414import java.util.Map; 
    15 import java.util.Observable; 
    16 import java.util.Observer; 
     15import java.util.Scanner; 
    1716import java.util.Set; 
    1817import java.util.logging.Level; 
     
    2928import tmcsim.common.SimulationException; 
    3029 
    31 /** The Highways class aggregates all Highway instances within a geographic 
    32  *  region, and all of the FEPLines within an electronic detector  
    33  *  network, in the same geographic region. An instance of Highways.java  
    34  *  comprises the underlying model for the ATMSDriver application. 
    35  *  
    36  *  Highways uses method writeToFEP() to communicate with the FEP Simulator.  
    37  *  It creates a socket client which sends the FEP Simulator a highways status 
    38  *  message over the socket. This message is in the XML format required by the  
    39  *  FEP Simulator, which is provided by the resident toXML() method. 
    40  *  
    41  *  Currently, there is no driving logic within the highways class. It is only 
    42  *  done through an instance of the ConsoleDriver.java class. Eventually, it 
    43  *  will receive incident data (from exchange.xml or better yet, directly from  
    44  *  the TMCSimulator itself) and drive the highways using resident logic. 
     30/** 
     31 * The Highways class aggregates all Highway instances within a geographic 
     32 * region, and all of the FEPLines within an electronic detector network, in the 
     33 * same geographic region. An instance of Highways.java comprises the underlying 
     34 * model for the ATMSDriver application. 
     35 * 
     36 * Highways uses method writeToFEP() to communicate with the FEP Simulator. It 
     37 * creates a socket client which sends the FEP Simulator a highways status 
     38 * message over the socket. This message is sent in the format required by the 
     39 * FEP Simulator. 
     40 * 
     41 * Currently, there is no driving logic within the highways class. It is only 
     42 * done through an instance of the ConsoleDriver.java class. Eventually, it will 
     43 * receive incident data (from exchange.xml or better yet, directly from the 
     44 * TMCSimulator itself) and drive the highways using resident logic. 
    4545 * 
    4646 * @author John A. Torres 
    4747 */ 
    48 public class Highways { 
    49  
    50     final private ArrayList<FEPLine> lines; 
     48final public class Highways 
     49{ 
     50 
    5151    final private String FEPHostName; 
    5252    final private int FEPPortNum; 
    5353     
     54    final private ArrayList<FEPLine> lines; 
    5455    final public ArrayList<Highway> highways; 
    55      
    56     public Highways(String ldsFileName, String loopsFileName, 
    57             String highwayMetaFileName, String FEPHostName, int FEPPortNum) { 
    58         /* 
    59          lines = loadLines(highwayMetaFileName); 
    60          System.out.println("SIZE: " + toXML().toCharArray().length); 
    61          */ 
    62  
    63         FEPLineLoader ldr = new FEPLineLoader(new File(ldsFileName), new File(loopsFileName)); 
    64         this.lines = (ArrayList<FEPLine>) ldr.getFEPLines(); 
     56 
     57    public Highways(String highwaysMapFileName, String FEPHostName, int FEPPortNum) 
     58    { 
     59        // load FEP Lines 
     60        lines = loadLines(highwaysMapFileName); 
     61        // configure and load highways 
     62        this.highways = configureHighways(); 
     63         
     64        // write to FEP host and port number 
    6565        this.FEPHostName = FEPHostName; 
    6666        this.FEPPortNum = FEPPortNum; 
    67         this.highways = loadHighways(); 
    68         //writeHighwaysMeta("hard.txt"); 
    69     } 
    70      
    71     private ArrayList<Highway> loadHighways() { 
     67    } 
     68 
     69    private ArrayList<Highway> configureHighways() 
     70    { 
    7271        System.out.println("Loading highways..."); 
    7372        // The list of highways to return 
    7473        ArrayList<Highway> highways = new ArrayList<Highway>(); 
    7574         
    76         Map<Integer, ArrayList<Station>> 
    77                 highwayMap = new HashMap<>(); 
     75        // map of hwy number to its list of stations 
     76        Map<Integer, ArrayList<Station>> highwayMap = new HashMap<>(); 
    7877         
     78        // iterate through FEPLines and get data to add to the above map 
    7979        for (FEPLine line : lines) 
    8080        { 
     81            // grab all stations from the current FEPLine 
    8182            ArrayList<Station> lineStations = (ArrayList<Station>) line.stations; 
    82             for(Station station : lineStations) 
     83            // iterate through each station in the list of stations 
     84            for (Station station : lineStations) 
    8385            { 
    8486                Integer hwyNum = station.routeNumber; 
    85  
    86                 if(!highwayMap.containsKey(hwyNum)) 
     87                 
     88                // if the map does not contain an entry for the highway, create 
     89                // a new entry (key/value pair) for the highway and instantiate 
     90                // the empty list of stations 
     91                if (!highwayMap.containsKey(hwyNum)) 
    8792                { 
    8893                    ArrayList<Station> stnList = new ArrayList<>(); 
    8994                    stnList.add(station); 
    9095                    highwayMap.put(hwyNum, stnList); 
    91                 } 
     96                }  
     97                // if the map does have an entry for the highway, add the current 
     98                // station to its list of stations 
    9299                else 
    93100                { 
     
    97104        } 
    98105         
     106        // get the set of highway numbers 
    99107        Set<Integer> hwyKeys = highwayMap.keySet(); 
    100         for(Integer hwyKey : hwyKeys) 
     108        // get the highway number and associated stations and create a new hwy 
     109        // and add the hwy to this.highways 
     110        for (Integer hwyKey : hwyKeys) 
    101111        { 
    102112            ArrayList<Station> hwyStations = highwayMap.get(hwyKey); 
    103113            Collections.sort(hwyStations); 
    104114            System.out.println("Loaded highway " + hwyKey + "..."); 
    105             highways.add(new Highway(hwyKey,  
     115            highways.add(new Highway(hwyKey, 
    106116                    hwyStations)); 
    107117        } 
     
    109119        return highways; 
    110120    } 
    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      *  
     121 
     122    /** 
     123     * Applies specified color to the specified highway stretch. Route number 
     124     * and direction specify the highway. Postmile and range specify the stretch 
     125     * of specified highway. Dot color is the color to be applied to the 
     126     * stretch. 
     127     * 
    116128     * @param routeNumber highway route number 
    117129     * @param direction highway direction 
     
    120132     * @param dotColor the color to be applied to specified highway stretch 
    121133     */ 
    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 "  
     134    public void applyColorToHighwayStretch(Integer routeNumber, Station.DIRECTION direction, 
     135            Double postmile, Double range, LoopDetector.DOTCOLOR dotColor) 
     136    { 
     137        System.out.println("Applying " + dotColor.name() + " dots to highway " 
     138                + routeNumber + " " + direction.name() + " at postmile " 
    126139                + postmile + " with a range of " + range + " miles..."); 
    127          
     140 
    128141        // Get the highway by route number 
    129142        Highway highway = getHighwayByRouteNumber(routeNumber); 
    130          
     143 
    131144        // start value for highway section, and end value for highway section 
    132145        // by postmile 
    133146        Double startPost; 
    134147        Double endPost; 
    135          
     148 
    136149        // postmiles increase from s to n and w to e 
    137          
    138150        // if the direction is south or west 
    139         if(direction.equals(Station.DIRECTION.SOUTH) || direction.equals(Station.DIRECTION.WEST)) 
     151        if (direction.equals(Station.DIRECTION.SOUTH) || direction.equals(Station.DIRECTION.WEST)) 
    140152        { 
    141153            // add range value to startPost to get 
     
    143155            startPost = postmile; 
    144156            endPost = postmile + range; 
    145              
     157 
    146158            // iterate through the stations, if within the specified highway 
    147159            // 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) 
     160            for (Station station : highway.stations) 
     161            { 
     162                if (station.postmile >= startPost && station.postmile <= endPost) 
    151163                { 
    152164                    station.updateByDirection(direction, dotColor); 
    153165                } 
    154166            } 
    155         } 
    156         // if the direction is north or east  
     167        } // if the direction is north or east  
    157168        else 
    158169        { 
    159             //subtract range value from startPost 
     170            // subtract range value from startPost 
    160171            // to get the end postmile value of the highway section 
    161172            startPost = postmile; 
    162173            endPost = postmile - range; 
    163              
     174 
    164175            // iterate through the stations, if within the specified highway 
    165176            // 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) 
     177            for (Station station : highway.stations) 
     178            { 
     179                if (station.postmile <= startPost && station.postmile >= endPost) 
    169180                { 
    170181                    station.updateByDirection(direction, dotColor); 
     
    174185        System.out.println(""); 
    175186    } 
    176  
    177     /* 
    178      private ArrayList<FEPLine> loadLines(String highwayMetaFileName) { 
    179      ArrayList<FEPLine> lines = new ArrayList<>(); 
    180      try { 
    181      Scanner sc = new Scanner(new File(highwayMetaFileName)); 
    182      String firstLine = sc.nextLine(); 
    183  
    184      Scanner linesc = new Scanner(firstLine); 
    185      int numLines = linesc.nextInt(); 
    186      linesc.close(); 
    187  
    188      for (int i = 0; i < numLines; i++) { 
    189      System.out.println("CURR: " + i); 
    190      lines.add(loadLine(sc)); 
    191      } 
    192      sc.close(); 
    193  
    194      } catch (FileNotFoundException ex) { 
    195      Logger.getLogger(Highways.class.getName()).log(Level.SEVERE, null, ex); 
    196      } 
    197      return lines; 
    198      } 
    199  
    200      private FEPLine loadLine(Scanner sc) { 
    201      String line = sc.nextLine(); 
    202      System.out.println(line); 
    203      Scanner scline = new Scanner(line); 
    204  
    205      int lineNum = scline.nextInt(); 
    206      int count = scline.nextInt(); 
    207      int numStations = scline.nextInt(); 
    208      ArrayList<Station> stations = new ArrayList<>(); 
    209      for (int i = 0; i < numStations; i++) { 
    210      stations.add(loadStation(sc, lineNum)); 
    211      } 
    212  
    213      return new FEPLine(lineNum, stations, count); 
    214      } 
    215  
    216      private Station loadStation(Scanner sc, int lineNum) { 
    217      String line = sc.nextLine(); 
    218      System.out.println(line); 
    219      Scanner scline = new Scanner(line); 
    220      int ldsID = scline.nextInt(); 
    221      int drop = scline.nextInt(); 
    222      int fwy = scline.nextInt(); 
    223      DIRECTION dir = DIRECTION.getEnum(scline.next()); 
    224      double postmile = scline.nextDouble(); 
    225      int numLoops = scline.nextInt(); 
    226      String location = getStationLoc(line); 
    227      ArrayList<LoopDetector> loops = new ArrayList<>(); 
    228      for (int i = 0; i < numLoops; i++) { 
    229      loops.add(loadLoop(sc)); 
    230      } 
    231  
    232      return new Station(lineNum, ldsID, drop, location, loops, fwy, dir, postmile); 
    233      } 
    234  
    235      private LoopDetector loadLoop(Scanner sc) { 
    236      String line = sc.nextLine(); 
    237      Scanner scline = new Scanner(line); 
    238  
    239      int loopID = scline.nextInt(); 
    240      int laneNum = scline.nextInt(); 
    241      String loopLoc = getLoopLoc(line); // NEED GET LOOPLOC 
    242      scline.close(); 
    243      return new LoopDetector(loopID, loopLoc, laneNum); 
    244      } 
    245  
    246      private String getLoopLoc(String line) { 
    247      Scanner sc = new Scanner(line); 
    248      sc.nextInt(); 
    249      sc.nextInt(); 
     187     
     188    /** 
     189     * Loads all FEPLines from the specified highways map file. 
     190     *  
     191     * @param highwaysMapFileName 
     192     * @return List of FEPLines 
     193     */ 
     194    private ArrayList<FEPLine> loadLines(String highwaysMapFileName) 
     195    { 
     196        ArrayList<FEPLine> lines = new ArrayList<>(); 
     197        try 
     198        { 
     199            Scanner sc = new Scanner(new File(highwaysMapFileName)); 
     200            String firstLine = sc.nextLine(); 
     201 
     202            Scanner linesc = new Scanner(firstLine); 
     203            int numLines = linesc.nextInt(); 
     204            linesc.close(); 
     205 
     206            for (int i = 0; i < numLines; i++) 
     207            { 
     208                lines.add(loadLine(sc)); 
     209            } 
     210            sc.close(); 
     211 
     212        } catch (FileNotFoundException ex) 
     213        { 
     214            Logger.getLogger(Highways.class.getName()).log(Level.SEVERE, null, ex); 
     215        } 
     216        return lines; 
     217    } 
     218     
     219    /** 
     220     * Loads a single FEP Line from the highways map file. 
     221     *  
     222     * @param sc scanner at the current FEPLine line 
     223     * @return FEPLine 
     224     */ 
     225    private FEPLine loadLine(Scanner sc) 
     226    { 
     227        String line = sc.nextLine(); 
     228        Scanner scline = new Scanner(line); 
     229 
     230        int lineNum = scline.nextInt(); 
     231        int count = scline.nextInt(); 
     232        int numStations = scline.nextInt(); 
     233        ArrayList<Station> stations = new ArrayList<>(); 
     234        for (int i = 0; i < numStations; i++) 
     235        { 
     236            stations.add(loadStation(sc, lineNum)); 
     237        } 
     238 
     239        return new FEPLine(lineNum, stations, count); 
     240    } 
     241     
     242    /** 
     243     * Loads a single Station from the highways map file 
     244     * @param sc scanner at the current station line 
     245     * @param lineNum the FEPLine number for the station 
     246     * @return Station 
     247     */ 
     248    private Station loadStation(Scanner sc, int lineNum) 
     249    { 
     250        String line = sc.nextLine(); 
     251        Scanner scline = new Scanner(line); 
     252        int ldsID = scline.nextInt(); 
     253        int drop = scline.nextInt(); 
     254        int fwy = scline.nextInt(); 
     255        DIRECTION dir = DIRECTION.toDirection(scline.next()); 
     256        double postmile = scline.nextDouble(); 
     257        int numLoops = scline.nextInt(); 
     258        String location = getStationLoc(line); 
     259        ArrayList<LoopDetector> loops = new ArrayList<>(); 
     260        for (int i = 0; i < numLoops; i++) 
     261        { 
     262            loops.add(loadLoop(sc)); 
     263        } 
     264 
     265        return new Station(lineNum, ldsID, drop, location, loops, fwy, dir, postmile); 
     266    } 
     267     
     268    /** 
     269     * Loads a single loop from the highways map file 
     270     * 
     271     * @param sc scanner at the current loop line 
     272     * @return LoopDetector 
     273     */ 
     274    private LoopDetector loadLoop(Scanner sc) 
     275    { 
     276        String line = sc.nextLine(); 
     277        Scanner scline = new Scanner(line); 
     278 
     279        int loopID = scline.nextInt(); 
     280        int laneNum = scline.nextInt(); 
     281        String loopLoc = getLoopLoc(line); // NEED GET LOOPLOC 
     282        scline.close(); 
     283        return new LoopDetector(loopID, loopLoc, laneNum); 
     284    } 
     285 
     286    /** 
     287     * Scans the LoopDetector line and grabs the String location from the line. 
     288     *  
     289     * @param line the line containing the location 
     290     * @return A String loop location. 
     291     */ 
     292    private String getLoopLoc(String line) 
     293    { 
     294        Scanner sc = new Scanner(line); 
     295        sc.nextInt(); 
     296        sc.nextInt(); 
    250297 
    251298     // GRABS FROM CURRENT TO END OF LINE 
    252           
    253      sc.useDelimiter("\\z"); 
    254      String loc = sc.next().trim(); 
    255      sc.close(); 
    256      return loc; 
    257      } 
    258  
    259      // Returns the loction given the whole line from the lookup file 
    260      private String getStationLoc(String line) { 
    261      Scanner scline = new Scanner(line); 
    262      scline.nextInt(); 
    263      scline.nextInt(); 
    264      scline.nextInt(); 
    265      scline.next(); 
    266      scline.nextDouble(); 
    267      scline.nextInt(); 
    268  
    269      // GRABS FROM CURRENT TO END OF LINE 
    270      scline.useDelimiter("\\z"); 
    271      String loc = scline.next().trim(); 
    272      scline.close(); 
    273      return loc; 
    274      } 
    275      */ 
    276  
    277     public void writeToFEP() throws SimulationException { 
    278         try { 
    279             Socket sock = new Socket(FEPHostName /*"192.168.251.130"*/, 8080); 
     299        sc.useDelimiter("\\z"); 
     300        String loc = sc.next().trim(); 
     301        sc.close(); 
     302        return loc; 
     303    } 
     304 
     305    /** 
     306     * Scans the Station line and grabs the String location from the line. 
     307     *  
     308     * @param line the line containing the location 
     309     * @return A String station location. 
     310     */ 
     311    private String getStationLoc(String line) 
     312    { 
     313        Scanner scline = new Scanner(line); 
     314        scline.nextInt(); 
     315        scline.nextInt(); 
     316        scline.nextInt(); 
     317        scline.next(); 
     318        scline.nextDouble(); 
     319        scline.nextInt(); 
     320 
     321        // GRABS FROM CURRENT TO END OF LINE 
     322        scline.useDelimiter("\\z"); 
     323        String loc = scline.next().trim(); 
     324        scline.close(); 
     325        return loc; 
     326    } 
     327     
     328    /**  
     329     * Creates a socket client that writes the Highways data to the FEP Simulator. 
     330     *  
     331     * @throws SimulationException  
     332     */ 
     333    public void writeToFEP() throws SimulationException 
     334    { 
     335        try 
     336        { 
     337            // Create the socket to the FEP Simulator 
     338            Socket sock = new Socket(FEPHostName, FEPPortNum); 
    280339            PrintWriter out = new PrintWriter(sock.getOutputStream(), true); 
     340             
     341            // Print the number of bytes the highways data message contains 
    281342            System.out.println("BYTES: " + this.toXML().toCharArray().length + 1); 
     343             
     344            // Write the highways data over the socket 
    282345            out.println(this.toXML()); 
     346             
     347            // close the socket 
    283348            sock.close(); 
    284         } catch (IOException ex) { 
     349        } catch (IOException ex) 
     350        { 
    285351            Logger.getLogger(Highways.class.getName()).log(Level.SEVERE, null, ex); 
    286352            System.out.println("Highway Model failed writing to FEPSim."); 
    287353            throw new SimulationException(SimulationException.BINDING); 
    288354        } 
    289         updateSequences(); 
    290     } 
    291  
    292     // CHECK: DO WE EVEN NEED TO DO THIS? 
    293     private void updateSequences() { 
    294         for (FEPLine line : lines) { 
    295             line.updateSequences(); 
    296         } 
    297     } 
    298  
    299     /** 
    300      * Returns the network metadata in condensed form. This is just a quick 
    301      * script function to make a proper highway metadata configuration file, so 
    302      * that we can read the network faster. 
     355    } 
     356 
     357    /** 
     358     * Returns the highways metadata in condensed form. This function took the  
     359     * highways model and wrote it into condensed form. It is also useful for 
     360     * testing. 
    303361     * 
    304      * @return Network metadata 
    305      */ 
    306     public void writeHighwaysMeta(String fileName) { 
    307  
    308         try { 
    309             FileWriter fw = new FileWriter(new File(fileName)); 
     362     * @return the highways meta data string 
     363     */ 
     364    public String getHighwaysMeta() 
     365    { 
    310366            StringBuilder build = new StringBuilder(); 
    311367            build.append(lines.size()); 
    312368            build.append("\n"); 
    313             System.out.println(lines.size()); 
    314             fw.write(build.toString()); 
    315             int count = 1; 
    316             for (FEPLine line : lines) { 
    317                 System.out.println("Writing num: " + count); 
    318                 count++; 
    319                 fw.write(line.getLineMeta()); 
    320  
    321             } 
    322         } catch (IOException ex) { 
    323             Logger.getLogger(Highways.class.getName()).log(Level.SEVERE, null, ex); 
    324         } 
    325     } 
    326  
    327     public String toXML() { 
     369            for (FEPLine line : lines) 
     370            { 
     371                build.append(line.getLineMeta()); 
     372            } 
     373            return build.toString(); 
     374    } 
     375 
     376    /** 
     377     * Returns the Highways model data in XML format. 
     378     *  
     379     * @return highways data in XML format 
     380     */ 
     381    public String toXML() 
     382    { 
    328383        String xml = null; 
    329         try { 
     384        try 
     385        { 
    330386            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
    331387            DocumentBuilder builder = factory.newDocumentBuilder(); 
     
    335391            theDoc.appendChild(networkElement); 
    336392 
    337             for (FEPLine line : lines) { 
     393            for (FEPLine line : lines) 
     394            { 
    338395                line.toXML(networkElement); 
    339396            } 
     
    349406            xml = out.toString(); 
    350407            out.close(); 
    351         } catch (Exception ex) { 
     408        } catch (Exception ex) 
     409        { 
    352410            Logger.getLogger(Highways.class.getName()).log(Level.SEVERE, null, ex); 
    353411        } 
     
    356414    } 
    357415 
    358     public Highway getHighwayByRouteNumber(Integer routeNum) { 
     416    /** 
     417     * Returns a highway by given highway number. 
     418     *  
     419     * @param routeNum 
     420     * @return Highway with specified route number 
     421     */ 
     422    public Highway getHighwayByRouteNumber(Integer routeNum) 
     423    { 
    359424        Highway returnHwy = null; 
    360         for(Highway hwy : highways) 
    361         { 
    362             if(hwy.routeNumber.equals(routeNum)) 
     425        for (Highway hwy : highways) 
     426        { 
     427            if (hwy.routeNumber.equals(routeNum)) 
    363428            { 
    364429                returnHwy = hwy; 
     
    369434    } 
    370435 
    371     private static enum XML_TAGS { 
     436    /** 
     437     * XML tags used in writeToXML() 
     438     */ 
     439    private static enum XML_TAGS 
     440    { 
    372441 
    373442        NETWORK("Network"); 
     
    375444        String tag; 
    376445 
    377         private XML_TAGS(String n) { 
     446        private XML_TAGS(String n) 
     447        { 
    378448            tag = n; 
    379449        } 
  • trunk/src/atmsdriver/model/LoopDetector.java

    r180 r184  
    66import org.w3c.dom.Element; 
    77 
    8 /** A LoopDetector represents a single detector for a single lane in a network. 
     8/**  
     9 *  A LoopDetector represents a single detector for a single lane in a network. 
    910 *  
    1011 *  A LoopDetector contains static meta data, and three dynamic attributes: vol, 
     
    2627    private int spd; 
    2728     
     29    /** 
     30     * Constructs a LoopDetector from loopID, loopLocation, and laneNum 
     31     *  
     32     * @param loopID 
     33     * @param loopLocation 
     34     * @param laneNum  
     35     */ 
    2836    public LoopDetector(int loopID, String loopLocation, int laneNum) 
    2937    { 
     
    3947    } 
    4048     
     49    /** 
     50     * XML tags used for toXML() method. 
     51     */ 
    4152    private static enum XML_TAGS 
    4253    { 
     
    89100        this.spd = spd; 
    90101    } 
    91      
     102 
     103    /** 
     104     * Returns the LoopDetector data in XMLFormat 
     105     *  
     106     * @param currElem The current XML <LoopDetector> element 
     107     */ 
    92108    public void toXML(Element currElem) 
    93109    { 
  • trunk/src/atmsdriver/model/Station.java

    r180 r184  
    11package atmsdriver.model; 
    22 
    3 import atmsdriver.ConsoleTrafficDriver; 
    43import atmsdriver.model.LoopDetector.DOTCOLOR; 
    54import java.util.List; 
     
    87 
    98/** 
    10  *A Station (LDS or Loop Detector Station) represents a group of lane detectors 
     9 * A Station (LDS or Loop Detector Station) represents a group of lane detectors 
    1110 * across all lanes at a particular point on a highway.  A station is 
    1211 * identified by its highway number and postmile.  A station has an associated 
    1312 * direction used to establish which direction is Main and which is Opposite. 
    1413 * The MLTotVol and OppTotVol for a station can be dynamically updated. 
    15  * A station has other attributes: lineNum, ldsID, drop, and location used 
    16  * by the FEP.  A station can be compared to other stations by its postmile. 
     14 * A station has other attributes: lineNum, ldsID, drop, and location which are 
     15 * used by the FEP.  A station can be compared to other stations by its postmile. 
    1716 * 
    1817 * @author John A. Torres 
     
    5453    } 
    5554     
     55    /** 
     56     * Calculates the total ML Volume. 
     57     *  
     58     * @return total ML volume. 
     59     */ 
    5660    private int getMLTotVol() 
    5761    { 
     
    6771    } 
    6872     
     73    /** 
     74     * Calculates the total OPP Volume 
     75     *  
     76     * @return total OPP volume. 
     77     */ 
    6978    private int getOPPTotVol() 
    7079    { 
     
    170179            } 
    171180        } 
    172     } 
    173     
     181         
     182        this.MLTotVol = getMLTotVol(); 
     183        this.OppTotVol = getOPPTotVol(); 
     184    } 
     185     
     186    /** 
     187     * Output for updateByDirection. Logs the update to the console. 
     188     *  
     189     * @param dotcolor 
     190     * @param OPP_ML  
     191     */ 
    174192    private void outputUpdateMessage(DOTCOLOR dotcolor, String OPP_ML) 
    175193    { 
     
    181199    } 
    182200     
     201    /** 
     202     * XML tags used for toXML() method. 
     203     */ 
    183204    private static enum XML_TAGS 
    184205    { 
     
    203224        } 
    204225    } 
    205  
     226     
     227    /** 
     228     * Returns the Station data in XMLFormat. 
     229     *  
     230     * @param currElem The current XML <Station> element 
     231     */ 
    206232    public void toXML(Element currElem) 
    207233    { 
     
    264290    public static enum DIRECTION 
    265291    { 
    266  
    267292        NORTH, 
    268293        SOUTH, 
  • trunk/src/atmsdriver/model/TrafficEvent.java

    r183 r184  
    5858        return eventDate.compareTo(o.eventDate); 
    5959    } 
     60     
    6061    @Override 
    6162    public String toString() 
  • trunk/src/tmcsim/application.properties

    r176 r184  
    1 #Tue, 24 Oct 2017 14:59:28 -0700 
     1#Sat, 28 Oct 2017 18:33:59 -0700 
    22 
    3 Application.revision=174 
     3Application.revision=183 
    44 
    5 Application.buildnumber=57 
     5Application.buildnumber=62 
  • trunk/src/tmcsim/client/ATMSBatchDriver.java

    r183 r184  
    143143        incidents = new HashMap<String, List<TrafficEvent>>(); 
    144144        highways = new Highways( 
    145                 "config/vds_data/lds.txt", 
    146                 "config/vds_data/loop.txt", 
    147                 "config/vds_data/highwaysMeta.txt", 
     145                "config/vds_data/highways_fullmap.txt", 
    148146                //        "192.168.251.46", 8080);  //IP address of FEP Sim Linux VM 
    149147                "localhost", 8080); 
Note: See TracChangeset for help on using the changeset viewer.