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

Revision 184, 5.4 KB checked in by jtorres, 9 years ago (diff)

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

Line 
1package atmsdriver.model;
2
3import java.util.ArrayList;
4import java.util.List;
5import org.w3c.dom.Document;
6import org.w3c.dom.Element;
7
8/**
9 *  A LoopDetector represents a single detector for a single lane in a network.
10 *
11 *  A LoopDetector contains static meta data, and three dynamic attributes: vol,
12 *  occ, and spd.
13 *
14 * @author John A. Torres
15 * @version 09/10/2017
16 */
17public class LoopDetector 
18{
19    /* static data */
20    final public int loopID;
21    final public String loopLocation;
22    final public int laneNum;
23   
24    /* dynamic data */
25    public int vol;
26    public float occ;
27    private int spd;
28   
29    /**
30     * Constructs a LoopDetector from loopID, loopLocation, and laneNum
31     *
32     * @param loopID
33     * @param loopLocation
34     * @param laneNum
35     */
36    public LoopDetector(int loopID, String loopLocation, int laneNum)
37    {
38        /* Set static data */
39        this.loopID = loopID;
40        this.loopLocation = loopLocation;
41        this.laneNum = laneNum;
42       
43        /* Init dynamic data */
44        this.vol = 0;
45        this.spd = 0;
46        this.occ = 0;
47    }
48   
49    /**
50     * XML tags used for toXML() method.
51     */
52    private static enum XML_TAGS
53    {
54        LOOP_ID("Loop_ID"),
55        LOOP_LOCATION("Loop_Location"),
56        LANE_NUM("Lane_Num"),
57        VOL("Vol"),
58        SPD("Spd"),
59        OCC("Occ"),
60        LOOP("Loop");
61       
62        String tag;
63       
64        private XML_TAGS(String n)
65        {
66            tag = n;
67        }
68    }
69   
70    /**
71     * Returns the loop metadata in condensed form.
72     * This is just a quick script function to make a proper highway
73     * metadata configuration file, so that we can read the network
74     * faster.
75     *
76     * @return loop metadata
77     */
78    public String getLoopMeta()
79    {
80        StringBuilder build = new StringBuilder();
81        build.append(Integer.toString(this.loopID));
82        build.append(" ");
83        build.append(Integer.toString(this.laneNum));
84        build.append(" ");
85        build.append(this.loopLocation);
86        build.append("\n");
87        return build.toString();
88    }
89   
90    /**
91     * Updates loop detector dynamic attributes.
92     * @param vol volume
93     * @param occ occupancy
94     * @param spd speed
95     */
96    public void updateLoop(int vol, float occ, int spd)
97    {
98        this.vol = vol;
99        this.occ = occ;
100        this.spd = spd;
101    }
102
103    /**
104     * Returns the LoopDetector data in XMLFormat
105     *
106     * @param currElem The current XML <LoopDetector> element
107     */
108    public void toXML(Element currElem)
109    {
110        Document theDoc = currElem.getOwnerDocument();
111       
112        Element loopElement = theDoc.createElement(XML_TAGS.LOOP.tag);
113        currElem.appendChild(loopElement);
114       
115        Element loopIDElement = theDoc.createElement(XML_TAGS.LOOP_ID.tag);
116        loopIDElement.appendChild(theDoc.createTextNode(String.valueOf(this.loopID)));
117        loopElement.appendChild(loopIDElement);
118       
119        Element loopLocElement = theDoc.createElement(XML_TAGS.LOOP_LOCATION.tag);
120        loopLocElement.appendChild(theDoc.createTextNode(this.loopLocation));
121        loopElement.appendChild(loopLocElement);
122       
123        Element laneNumElement = theDoc.createElement(XML_TAGS.LANE_NUM.tag);
124        laneNumElement.appendChild(theDoc.createTextNode(String.valueOf(this.laneNum)));
125        loopElement.appendChild(laneNumElement);
126       
127        Element volElement = theDoc.createElement(XML_TAGS.VOL.tag);
128        volElement.appendChild(theDoc.createTextNode(String.valueOf(this.vol)));
129        loopElement.appendChild(volElement);
130       
131        Element occElement = theDoc.createElement(XML_TAGS.OCC.tag);
132        occElement.appendChild(theDoc.createTextNode(String.valueOf(this.occ)));
133        loopElement.appendChild(occElement);
134       
135        Element spdElement = theDoc.createElement(XML_TAGS.SPD.tag);
136        spdElement.appendChild(theDoc.createTextNode(String.valueOf(this.spd)));
137        loopElement.appendChild(spdElement);
138    }
139   
140    /**
141     * Enum for highway status dot colors. Each color has associated volume
142     * and occupancy constants.
143     *
144     * @author John A. Torres, jdalbey
145     * @version 10/11/2017
146     */
147    public static enum DOTCOLOR {
148
149        RED(1, 0.06f),    // "Stopped" is less than 25mph
150        YELLOW(3,0.059f), // speed = 26
151        GREEN(0,0);
152       
153        // All the first letters of the values, in order.
154        public static String allLetters = "RYG";
155       
156        private int vol;  /* volume */
157        private float occ;  /* occupancy */     
158       
159        private DOTCOLOR(int v, float o)
160        {
161            vol = v;
162            occ = o;
163        }
164        /**
165         * Return the first letter of this enum.
166         *
167         * @return String first letter of this enum.
168         */
169        public String getLetter() {
170            return this.toString().substring(0, 1);
171        }
172
173        public int volume()
174        {
175            return vol;
176        }
177        public float occupancy()
178        {
179            return occ;
180        }
181        /**
182         * Returns a dot color given its first character.
183         *
184         * @param letter the first character of a dot color
185         * @return dot color corresponding to letter
186         * @pre letter must be one of allLetters
187         */
188        public static DOTCOLOR toDotColor(String letter) {
189            return values()[allLetters.indexOf(letter.charAt(0))];
190        }
191    } 
192   
193}
Note: See TracBrowser for help on using the repository browser.