Warning: Can't use blame annotator:
svn blame failed on trunk/src/atmsdriver/model/LoopDetector.java: ("Can't find a temporary directory: Internal error", 20014)

source: tmcsimulator/trunk/src/atmsdriver/model/LoopDetector.java @ 87

Revision 87, 3.6 KB checked in by jtorres, 9 years ago (diff)

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.

RevLine 
1package atmsdriver.model;
2
3import java.util.ArrayList;
4import java.util.List;
5import org.w3c.dom.Document;
6import org.w3c.dom.Element;
7
8/** A LoopDetector represents a single detector for a single lane in a network.
9 *
10 *  A LoopDetector contains static meta data, and three dynamic attributes: vol,
11 *  occ, and spd.
12 *
13 * @author John A. Torres
14 * @version 09/10/2017
15 */
16public class LoopDetector 
17{
18    /* static data */
19    final private int loopID;
20    final private String loopLocation;
21    final private int laneNum;
22   
23    /* dynamic data */
24    private int vol;
25    private int occ;
26    private int spd;
27   
28    public LoopDetector(int loopID, String loopLocation, int laneNum)
29    {
30        /* Set static data */
31        this.loopID = loopID;
32        this.loopLocation = loopLocation;
33        this.laneNum = laneNum;
34       
35        /* Init dynamic data */
36        this.vol = 0;
37        this.spd = 0;
38        this.occ = 0;
39    }
40   
41    private static enum XML_TAGS
42    {
43        LOOP_ID("Loop_ID"),
44        LOOP_LOCATION("Loop_Location"),
45        LANE_NUM("Lane_Num"),
46        VOL("Vol"),
47        SPD("Spd"),
48        OCC("Occ"),
49        LOOP("Loop");
50       
51        String tag;
52       
53        private XML_TAGS(String n)
54        {
55            tag = n;
56        }
57    }
58   
59    /**
60     * Returns the loop metadata in condensed form.
61     * This is just a quick script function to make a proper highway
62     * metadata configuration file, so that we can read the network
63     * faster.
64     *
65     * @return loop metadata
66     */
67    public String getLoopMeta()
68    {
69        StringBuilder build = new StringBuilder();
70        build.append(Integer.toString(this.loopID));
71        build.append(" ");
72        build.append(Integer.toString(this.laneNum));
73        build.append(" ");
74        build.append(this.loopLocation);
75        build.append("\n");
76        return build.toString();
77    }
78   
79    /**
80     * Updates loop detector dynamic attributes.
81     * @param vol volume
82     * @param occ occupancy
83     * @param spd speed
84     */
85    public void updateLoop(int vol, int occ, int spd)
86    {
87        this.vol = vol;
88        this.occ = occ;
89        this.spd = spd;
90    }
91   
92    public void toXML(Element currElem)
93    {
94        Document theDoc = currElem.getOwnerDocument();
95       
96        Element loopElement = theDoc.createElement(XML_TAGS.LOOP.tag);
97        currElem.appendChild(loopElement);
98       
99        Element loopIDElement = theDoc.createElement(XML_TAGS.LOOP_ID.tag);
100        loopIDElement.appendChild(theDoc.createTextNode(String.valueOf(this.loopID)));
101        loopElement.appendChild(loopIDElement);
102       
103        Element loopLocElement = theDoc.createElement(XML_TAGS.LOOP_LOCATION.tag);
104        loopLocElement.appendChild(theDoc.createTextNode(this.loopLocation));
105        loopElement.appendChild(loopLocElement);
106       
107        Element laneNumElement = theDoc.createElement(XML_TAGS.LANE_NUM.tag);
108        laneNumElement.appendChild(theDoc.createTextNode(String.valueOf(this.laneNum)));
109        loopElement.appendChild(laneNumElement);
110       
111        Element volElement = theDoc.createElement(XML_TAGS.VOL.tag);
112        volElement.appendChild(theDoc.createTextNode(String.valueOf(this.vol)));
113        loopElement.appendChild(volElement);
114       
115        Element occElement = theDoc.createElement(XML_TAGS.OCC.tag);
116        occElement.appendChild(theDoc.createTextNode(String.valueOf(this.occ)));
117        loopElement.appendChild(occElement);
118       
119        Element spdElement = theDoc.createElement(XML_TAGS.SPD.tag);
120        spdElement.appendChild(theDoc.createTextNode(String.valueOf(this.spd)));
121        loopElement.appendChild(spdElement);
122    }
123}
Note: See TracBrowser for help on using the repository browser.