Changeset 87 in tmcsimulator for trunk/src/atmsdriver/model/Station.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/model/Station.java

    r84 r87  
    55import org.w3c.dom.Element; 
    66 
    7 /** A Station is a simulation of a station in a traffic network. 
    8  *   
    9  *  A Station (LDS) contains static meta data about the station, and 
    10   two dynamic attributes, MLTotVol and OppTotVol.  
    11   
    12   A single LDS contains multiple LoopDetectors, which 
    13   contain data for a single lane on one direction of the freeway. A LDS 
    14   is specific to a single freeway, direction, and postmile. 
     7/** 
     8 * A Station is a simulation of a station in a traffic network. 
     9 * 
     10 * A Station (LDS) contains static meta data about the station, and two dynamic 
     11 * attributes, MLTotVol and OppTotVol.  * 
     12 * A single LDS contains multiple LoopDetectors, which contain data for a single 
     13 * lane on one direction of the freeway. A LDS is specific to a single freeway, 
     14 * direction, and postmile. 
    1515 * 
    1616 * @author John A. Torres 
     
    1919public class Station implements Comparable { 
    2020    /* Static Station meta data */ 
     21 
    2122    final private int lineNum; 
    2223    final private int ldsID; // double check 
     
    2728    final private double postmile; 
    2829    final private DIRECTION direction; 
    29      
     30 
    3031    /* Dynamic Station data */ 
    3132    private int MLTotVol; 
    3233    private int OppTotVol; 
    33      
     34 
    3435    /* Constructor */ 
    3536    public Station(int lineNum, int ldsID, int drop, 
    36             String location, List<LoopDetector> loops, int fwy,  
    37             DIRECTION direction, double postmile) 
    38     { 
     37            String location, List<LoopDetector> loops, int fwy, 
     38            DIRECTION direction, double postmile) { 
    3939        this.lineNum = lineNum; 
    4040        this.ldsID = ldsID; 
     
    4545        this.direction = direction; 
    4646        this.freeway = fwy; 
    47          
     47 
    4848        this.MLTotVol = 0; 
    4949        this.OppTotVol = 0; 
    5050    } 
    5151 
     52    /** 
     53     * Returns the station metadata in condensed form. This is just a quick 
     54     * script function to make a proper highway metadata configuration file, so 
     55     * that we can read the network faster. 
     56     * 
     57     * @return station metadata 
     58     */ 
     59    public String getStationMeta() { 
     60        StringBuilder build = new StringBuilder(); 
     61        build.append(Integer.toString(this.ldsID)); 
     62        build.append(" "); 
     63        build.append(Integer.toString(this.drop)); 
     64        build.append(" "); 
     65        build.append(Integer.toString(this.freeway)); 
     66        build.append(" "); 
     67        build.append(this.direction.name); 
     68        build.append(" "); 
     69        build.append(Double.toString(this.postmile)); 
     70        build.append(" "); 
     71        build.append(Integer.toString(loops.size())); 
     72        build.append(" "); 
     73        build.append(this.location); 
     74        build.append("\n"); 
     75        for (LoopDetector loop : loops) { 
     76            build.append(loop.getLoopMeta()); 
     77        } 
     78        return build.toString(); 
     79    } 
     80 
     81    public double getPostmile() { 
     82        return postmile; 
     83    } 
     84 
    5285    @Override 
    53     public int compareTo(Object o) { 
    54          
    55     } 
    56      
    57     private static enum XML_TAGS 
    58     { 
     86    public int compareTo(Object otherStation) { 
     87        // check that Object is of type Station, if not throw exception 
     88        if (!(otherStation instanceof Station)) { 
     89            throw new ClassCastException("A Station object expected."); 
     90        } 
     91 
     92        // get difference of values 
     93        double otherStationPostmile = ((Station) otherStation).getPostmile(); 
     94        double val = this.postmile - otherStationPostmile; 
     95 
     96        // set appropriate comparable return value 
     97        int retval = 0; 
     98        if (val > 0) { 
     99            retval = 1; 
     100        } else if (val < 0) { 
     101            retval = -1; 
     102        } 
     103 
     104        return retval; 
     105    } 
     106 
     107    private static enum XML_TAGS { 
     108 
    59109        STATION("Station"), 
    60110        LDS_ID("LDS_ID"), 
     
    68118        ML_TOT_VOL("ML_Tot_Vol"), 
    69119        OPP_TOT_VOL("Opp_Tot_Vol"); 
    70          
     120 
    71121        String tag; 
    72          
    73         private XML_TAGS(String n) 
    74         { 
     122 
     123        private XML_TAGS(String n) { 
    75124            tag = n; 
    76125        } 
    77126    } 
    78      
    79     public void toXML(Element currElem) 
    80     { 
     127 
     128    public void toXML(Element currElem) { 
    81129        Document theDoc = currElem.getOwnerDocument(); 
    82          
     130 
    83131        Element stationElement = theDoc.createElement(XML_TAGS.STATION.tag); 
    84132        currElem.appendChild(stationElement); 
    85          
     133 
    86134        Element ldsIDElement = theDoc.createElement(XML_TAGS.LDS_ID.tag); 
    87135        ldsIDElement.appendChild(theDoc.createTextNode(String.valueOf(this.ldsID))); 
    88136        stationElement.appendChild(ldsIDElement); 
    89          
     137 
    90138        Element lineNumElement = theDoc.createElement(XML_TAGS.LINE_NUM.tag); 
    91139        lineNumElement.appendChild(theDoc.createTextNode(String.valueOf(this.lineNum))); 
    92140        stationElement.appendChild(lineNumElement); 
    93          
     141 
    94142        Element dropElement = theDoc.createElement(XML_TAGS.DROP.tag); 
    95143        dropElement.appendChild(theDoc.createTextNode(String.valueOf(this.drop))); 
    96144        stationElement.appendChild(dropElement); 
    97          
     145 
    98146        Element locationElement = theDoc.createElement(XML_TAGS.LOCATION.tag); 
    99147        locationElement.appendChild(theDoc.createTextNode(this.location)); 
    100148        stationElement.appendChild(locationElement); 
    101          
     149 
    102150        Element postMileElement = theDoc.createElement(XML_TAGS.POST_MILE.tag); 
    103151        postMileElement.appendChild(theDoc.createTextNode(String.valueOf(this.postmile))); 
    104152        stationElement.appendChild(postMileElement); 
    105          
     153 
    106154        Element directionElement = theDoc.createElement(XML_TAGS.DIRECTION.tag); 
    107155        directionElement.appendChild(theDoc.createTextNode(this.direction.name)); 
    108156        stationElement.appendChild(directionElement); 
    109          
     157 
    110158        Element freewayElement = theDoc.createElement(XML_TAGS.FREEWAY.tag); 
    111159        freewayElement.appendChild(theDoc.createTextNode(String.valueOf(this.freeway))); 
    112160        stationElement.appendChild(freewayElement); 
    113          
     161 
    114162        Element mlElement = theDoc.createElement(XML_TAGS.ML_TOT_VOL.tag); 
    115163        mlElement.appendChild(theDoc.createTextNode(String.valueOf(this.MLTotVol))); 
    116164        stationElement.appendChild(mlElement); 
    117          
     165 
    118166        Element oppElement = theDoc.createElement(XML_TAGS.OPP_TOT_VOL.tag); 
    119167        oppElement.appendChild(theDoc.createTextNode(String.valueOf(this.OppTotVol))); 
    120168        stationElement.appendChild(oppElement); 
    121          
     169 
    122170        Element loopsElement = theDoc.createElement(XML_TAGS.LOOPS.tag); 
    123171        stationElement.appendChild(loopsElement); 
    124          
    125         for(LoopDetector loop : loops) 
    126         { 
     172 
     173        for (LoopDetector loop : loops) { 
    127174            loop.toXML(loopsElement); 
    128175        } 
    129176    } 
    130      
     177 
    131178    /** 
    132179     * Enum for freeway direction. 
    133      *  
     180     * 
    134181     * @author John A. Torres 
    135182     * @version 9/10/2017 
    136183     */ 
    137     public static enum DIRECTION 
    138     { 
     184    public static enum DIRECTION { 
     185 
    139186        NORTH("N"), 
    140187        SOUTH("S"), 
    141188        EAST("E"), 
    142189        WEST("W"); 
    143          
     190 
    144191        String name; 
    145          
    146         DIRECTION(String name) 
    147         { 
     192 
     193        DIRECTION(String name) { 
    148194            this.name = name; 
    149195        } 
    150          
     196 
    151197        /** 
    152198         * Returns the direction enum, given a string value. 
     199         * 
    153200         * @param name str value for enum 
    154201         * @return enum for given str value 
    155202         */ 
    156         public static DIRECTION getEnum(String name) 
    157         { 
    158             switch(name) 
    159             { 
     203        public static DIRECTION getEnum(String name) { 
     204            switch (name) { 
    160205                case "S": 
    161206                    return SOUTH; 
Note: See TracChangeset for help on using the changeset viewer.