- Timestamp:
- 10/28/2017 05:24:02 PM (9 years ago)
- Location:
- trunk/src
- Files:
-
- 1 deleted
- 9 edited
-
atmsdriver/ATMSDriver.java (modified) (9 diffs)
-
atmsdriver/ConsoleTrafficDriver.java (modified) (2 diffs)
-
atmsdriver/FEPLineLoader.java (deleted)
-
atmsdriver/model/FEPLine.java (modified) (4 diffs)
-
atmsdriver/model/Highways.java (modified) (13 diffs)
-
atmsdriver/model/LoopDetector.java (modified) (4 diffs)
-
atmsdriver/model/Station.java (modified) (8 diffs)
-
atmsdriver/model/TrafficEvent.java (modified) (1 diff)
-
tmcsim/application.properties (modified) (1 diff)
-
tmcsim/client/ATMSBatchDriver.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/atmsdriver/ATMSDriver.java
r180 r184 17 17 * @version 09/10/2017 18 18 */ 19 public class ATMSDriver implements Runnable { 19 public class ATMSDriver implements Runnable 20 { 20 21 21 22 /** … … 36 37 * @see ATMSDriver 37 38 */ 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"), 42 42 EXCHANGE_FILE_NAME("ExchangeFileName"), 43 43 FEP_WRITER_HOST("FEPWriterHost"), … … 46 46 public String name; 47 47 48 private PROPERTIES(String n) { 48 private PROPERTIES(String n) 49 { 49 50 name = n; 50 51 } … … 67 68 68 69 @Override 69 public void run() { 70 public void run() 71 { 70 72 // Check for packets and update the simulator 71 while (true) { 73 while (true) 74 { 72 75 // Flush the input file 73 76 ExchangeInfo exInfo = exchangeReader.parse(ATMSDriverProperties 74 77 .getProperty(PROPERTIES.EXCHANGE_FILE_NAME.name)); 75 78 76 try { 79 try 80 { 77 81 highways.writeToFEP(); 78 } catch (SimulationException ex) { 79 System.out.println("Skipping writeToFEP..."); 82 } catch (SimulationException ex) 83 { 84 System.out.println("Skipping writeToFEP..."); 80 85 } 81 86 // Update if exchangeInfo is recieved 82 if (exInfo != null) { 87 if (exInfo != null) 88 { 83 89 // TODO: handle this condition 84 90 Logger.getLogger("ATMSDriver").log(Level.INFO, "exInfo is not null"); … … 86 92 87 93 // Wait for FEP Sim to process the data we just sent 88 try { 94 try 95 { 89 96 Thread.sleep(SLEEP_TIME); 90 } catch (InterruptedException ie) { 97 } catch (InterruptedException ie) 98 { 91 99 ie.printStackTrace(); 92 100 } … … 94 102 } 95 103 96 public ATMSDriver(String propertiesFile) { 104 public ATMSDriver(String propertiesFile) 105 { 97 106 // verify properties file 98 if (!verifyProperties(propertiesFile)) { 107 if (!verifyProperties(propertiesFile)) 108 { 99 109 System.exit(0); 100 110 } … … 102 112 highways = new Highways( 103 113 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), 109 115 ATMSDriverProperties.getProperty(PROPERTIES.FEP_WRITER_HOST.name), 110 116 Integer.parseInt(ATMSDriverProperties.getProperty( … … 113 119 exchangeReader = new ExchangeReader(); 114 120 } 115 121 116 122 /** 117 123 * Verifies that the properties file has all necessary properties. 118 * 124 * 119 125 * @param propertiesFile 120 * @return 126 * @return 121 127 */ 122 private boolean verifyProperties(String propertiesFile) { 128 private boolean verifyProperties(String propertiesFile) 129 { 123 130 // Load the properties file. 124 try { 131 try 132 { 125 133 ATMSDriverProperties = new Properties(); 126 134 ATMSDriverProperties.load(new FileInputStream(propertiesFile)); 127 } catch (Exception e) { 135 } catch (Exception e) 136 { 128 137 ATMSDriverLogger.logp(Level.SEVERE, "ATMSDriver", 129 138 "Constructor", "Exception in reading properties file.", e); … … 136 145 * Runs the ATMS Driver. 137 146 */ 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 { 141 153 // Create and run the ATMSDriver thread 142 154 ATMSDriver atmsDriver = new ATMSDriver(System.getProperty("ATMSDRIVER_PROPERTIES")); 143 155 Thread ATMSDriverThread = new Thread(atmsDriver); 144 156 ATMSDriverThread.start(); 145 157 146 158 // run the console driver, pass it the atmsDriver highways model 147 159 ConsoleTrafficDriver driver = new ConsoleTrafficDriver(atmsDriver.highways); 148 149 } else { 160 161 } else 162 { 150 163 throw new Exception("ATMSDRIVER_PROPERTIES system property not defined."); 151 164 } 152 } catch (Exception e) { 165 } catch (Exception e) 166 { 153 167 ATMSDriverLogger.logp(Level.SEVERE, "ATMSDriver", "Main", 154 168 "Error occured initializing application", e); -
trunk/src/atmsdriver/ConsoleTrafficDriver.java
r180 r184 8 8 import java.io.FileInputStream; 9 9 import java.util.ArrayList; 10 import java.util.Arrays;11 10 import java.util.List; 12 11 import java.util.Properties; … … 48 47 // Create the Highway Model 49 48 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", 53 50 ConsoleDriverProperties.getProperty( 54 51 "FEPWriterHost"), -
trunk/src/atmsdriver/model/FEPLine.java
r103 r184 1 1 package atmsdriver.model; 2 2 3 import java.util.ArrayList; 3 4 import java.util.List; 4 5 import org.w3c.dom.Document; 5 6 import org.w3c.dom.Element; 6 7 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. 12 14 * 13 15 * @author John A. Torres 14 16 * @version 09/10/2017 15 */ 16 public class FEPLine { 17 */ 18 final public class FEPLine 19 { 17 20 /* Static FEPLine meta data */ 18 21 final public int lineNum; 19 22 final public List<Station> stations; 20 23 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) 34 33 { 35 34 this.lineNum = lineNum; 36 35 this.stations = stations; 37 36 this.count = count; 38 this.schedule = schedule;39 this.lineInfo = lineInfo;40 this.systemKey = systemKey;41 this.globalSeq = globalSeq;42 this.scheduleSeq = scheduleSeq;43 37 } 44 38 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 */ 52 43 public String getLineMeta() 53 44 { … … 59 50 build.append(Integer.toString(this.stations.size())); 60 51 build.append("\n"); 61 for (Station station : stations)52 for (Station station : stations) 62 53 { 63 54 build.append(station.getStationMeta()); … … 66 57 } 67 58 59 /** 60 * Returns the FEPLine data in XMLFormat 61 * 62 * @param currElem The current XML <Line> element 63 */ 68 64 public void toXML(Element currElem) 69 65 { 70 66 Document theDoc = currElem.getOwnerDocument(); 71 67 72 68 Element lineElement = theDoc.createElement(XML_TAGS.LINE.tag); 73 69 currElem.appendChild(lineElement); 74 70 75 71 Element lineNumElement = theDoc.createElement(XML_TAGS.LINE_NUM.tag); 76 72 lineNumElement.appendChild(theDoc.createTextNode(String.valueOf(this.lineNum))); 77 73 lineElement.appendChild(lineNumElement); 78 74 79 75 Element countElement = theDoc.createElement(XML_TAGS.COUNT.tag); 80 76 countElement.appendChild(theDoc.createTextNode(String.valueOf(this.count))); 81 77 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 103 79 Element stationsElement = theDoc.createElement(XML_TAGS.STATIONS.tag); 104 80 lineElement.appendChild(stationsElement); 105 for (Station station : stations)81 for (Station station : stations) 106 82 { 107 83 station.toXML(stationsElement); … … 109 85 } 110 86 87 /** 88 * XML Tags used in toXML() 89 */ 111 90 private static enum XML_TAGS 112 91 { 92 113 93 LINE("Line"), 114 94 LINE_NUM("Line_Num"), 115 95 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 123 98 String tag; 124 99 125 100 private XML_TAGS(String n) 126 101 { -
trunk/src/atmsdriver/model/Highways.java
r180 r184 1 1 package atmsdriver.model; 2 2 3 import atmsdriver. FEPLineLoader;3 import atmsdriver.model.Station.DIRECTION; 4 4 import java.io.File; 5 import java.io.File Writer;5 import java.io.FileNotFoundException; 6 6 import java.io.IOException; 7 7 import java.io.PrintWriter; … … 13 13 import java.util.HashMap; 14 14 import java.util.Map; 15 import java.util.Observable; 16 import java.util.Observer; 15 import java.util.Scanner; 17 16 import java.util.Set; 18 17 import java.util.logging.Level; … … 29 28 import tmcsim.common.SimulationException; 30 29 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. 45 45 * 46 46 * @author John A. Torres 47 47 */ 48 public class Highways { 49 50 final private ArrayList<FEPLine> lines; 48 final public class Highways 49 { 50 51 51 final private String FEPHostName; 52 52 final private int FEPPortNum; 53 53 54 final private ArrayList<FEPLine> lines; 54 55 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 65 65 this.FEPHostName = FEPHostName; 66 66 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 { 72 71 System.out.println("Loading highways..."); 73 72 // The list of highways to return 74 73 ArrayList<Highway> highways = new ArrayList<Highway>(); 75 74 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<>(); 78 77 78 // iterate through FEPLines and get data to add to the above map 79 79 for (FEPLine line : lines) 80 80 { 81 // grab all stations from the current FEPLine 81 82 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) 83 85 { 84 86 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)) 87 92 { 88 93 ArrayList<Station> stnList = new ArrayList<>(); 89 94 stnList.add(station); 90 95 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 92 99 else 93 100 { … … 97 104 } 98 105 106 // get the set of highway numbers 99 107 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) 101 111 { 102 112 ArrayList<Station> hwyStations = highwayMap.get(hwyKey); 103 113 Collections.sort(hwyStations); 104 114 System.out.println("Loaded highway " + hwyKey + "..."); 105 highways.add(new Highway(hwyKey, 115 highways.add(new Highway(hwyKey, 106 116 hwyStations)); 107 117 } … … 109 119 return highways; 110 120 } 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 * 116 128 * @param routeNumber highway route number 117 129 * @param direction highway direction … … 120 132 * @param dotColor the color to be applied to specified highway stretch 121 133 */ 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 " 126 139 + postmile + " with a range of " + range + " miles..."); 127 140 128 141 // Get the highway by route number 129 142 Highway highway = getHighwayByRouteNumber(routeNumber); 130 143 131 144 // start value for highway section, and end value for highway section 132 145 // by postmile 133 146 Double startPost; 134 147 Double endPost; 135 148 136 149 // postmiles increase from s to n and w to e 137 138 150 // 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)) 140 152 { 141 153 // add range value to startPost to get … … 143 155 startPost = postmile; 144 156 endPost = postmile + range; 145 157 146 158 // iterate through the stations, if within the specified highway 147 159 // 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) 151 163 { 152 164 station.updateByDirection(direction, dotColor); 153 165 } 154 166 } 155 } 156 // if the direction is north or east 167 } // if the direction is north or east 157 168 else 158 169 { 159 // subtract range value from startPost170 // subtract range value from startPost 160 171 // to get the end postmile value of the highway section 161 172 startPost = postmile; 162 173 endPost = postmile - range; 163 174 164 175 // iterate through the stations, if within the specified highway 165 176 // 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) 169 180 { 170 181 station.updateByDirection(direction, dotColor); … … 174 185 System.out.println(""); 175 186 } 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(); 250 297 251 298 // 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); 280 339 PrintWriter out = new PrintWriter(sock.getOutputStream(), true); 340 341 // Print the number of bytes the highways data message contains 281 342 System.out.println("BYTES: " + this.toXML().toCharArray().length + 1); 343 344 // Write the highways data over the socket 282 345 out.println(this.toXML()); 346 347 // close the socket 283 348 sock.close(); 284 } catch (IOException ex) { 349 } catch (IOException ex) 350 { 285 351 Logger.getLogger(Highways.class.getName()).log(Level.SEVERE, null, ex); 286 352 System.out.println("Highway Model failed writing to FEPSim."); 287 353 throw new SimulationException(SimulationException.BINDING); 288 354 } 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. 303 361 * 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 { 310 366 StringBuilder build = new StringBuilder(); 311 367 build.append(lines.size()); 312 368 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 { 328 383 String xml = null; 329 try { 384 try 385 { 330 386 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 331 387 DocumentBuilder builder = factory.newDocumentBuilder(); … … 335 391 theDoc.appendChild(networkElement); 336 392 337 for (FEPLine line : lines) { 393 for (FEPLine line : lines) 394 { 338 395 line.toXML(networkElement); 339 396 } … … 349 406 xml = out.toString(); 350 407 out.close(); 351 } catch (Exception ex) { 408 } catch (Exception ex) 409 { 352 410 Logger.getLogger(Highways.class.getName()).log(Level.SEVERE, null, ex); 353 411 } … … 356 414 } 357 415 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 { 359 424 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)) 363 428 { 364 429 returnHwy = hwy; … … 369 434 } 370 435 371 private static enum XML_TAGS { 436 /** 437 * XML tags used in writeToXML() 438 */ 439 private static enum XML_TAGS 440 { 372 441 373 442 NETWORK("Network"); … … 375 444 String tag; 376 445 377 private XML_TAGS(String n) { 446 private XML_TAGS(String n) 447 { 378 448 tag = n; 379 449 } -
trunk/src/atmsdriver/model/LoopDetector.java
r180 r184 6 6 import org.w3c.dom.Element; 7 7 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. 9 10 * 10 11 * A LoopDetector contains static meta data, and three dynamic attributes: vol, … … 26 27 private int spd; 27 28 29 /** 30 * Constructs a LoopDetector from loopID, loopLocation, and laneNum 31 * 32 * @param loopID 33 * @param loopLocation 34 * @param laneNum 35 */ 28 36 public LoopDetector(int loopID, String loopLocation, int laneNum) 29 37 { … … 39 47 } 40 48 49 /** 50 * XML tags used for toXML() method. 51 */ 41 52 private static enum XML_TAGS 42 53 { … … 89 100 this.spd = spd; 90 101 } 91 102 103 /** 104 * Returns the LoopDetector data in XMLFormat 105 * 106 * @param currElem The current XML <LoopDetector> element 107 */ 92 108 public void toXML(Element currElem) 93 109 { -
trunk/src/atmsdriver/model/Station.java
r180 r184 1 1 package atmsdriver.model; 2 2 3 import atmsdriver.ConsoleTrafficDriver;4 3 import atmsdriver.model.LoopDetector.DOTCOLOR; 5 4 import java.util.List; … … 8 7 9 8 /** 10 * A Station (LDS or Loop Detector Station) represents a group of lane detectors9 * A Station (LDS or Loop Detector Station) represents a group of lane detectors 11 10 * across all lanes at a particular point on a highway. A station is 12 11 * identified by its highway number and postmile. A station has an associated 13 12 * direction used to establish which direction is Main and which is Opposite. 14 13 * The MLTotVol and OppTotVol for a station can be dynamically updated. 15 * A station has other attributes: lineNum, ldsID, drop, and location used16 * 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. 17 16 * 18 17 * @author John A. Torres … … 54 53 } 55 54 55 /** 56 * Calculates the total ML Volume. 57 * 58 * @return total ML volume. 59 */ 56 60 private int getMLTotVol() 57 61 { … … 67 71 } 68 72 73 /** 74 * Calculates the total OPP Volume 75 * 76 * @return total OPP volume. 77 */ 69 78 private int getOPPTotVol() 70 79 { … … 170 179 } 171 180 } 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 */ 174 192 private void outputUpdateMessage(DOTCOLOR dotcolor, String OPP_ML) 175 193 { … … 181 199 } 182 200 201 /** 202 * XML tags used for toXML() method. 203 */ 183 204 private static enum XML_TAGS 184 205 { … … 203 224 } 204 225 } 205 226 227 /** 228 * Returns the Station data in XMLFormat. 229 * 230 * @param currElem The current XML <Station> element 231 */ 206 232 public void toXML(Element currElem) 207 233 { … … 264 290 public static enum DIRECTION 265 291 { 266 267 292 NORTH, 268 293 SOUTH, -
trunk/src/atmsdriver/model/TrafficEvent.java
r183 r184 58 58 return eventDate.compareTo(o.eventDate); 59 59 } 60 60 61 @Override 61 62 public String toString() -
trunk/src/tmcsim/application.properties
r176 r184 1 # Tue, 24 Oct 2017 14:59:28-07001 #Sat, 28 Oct 2017 18:33:59 -0700 2 2 3 Application.revision=1 743 Application.revision=183 4 4 5 Application.buildnumber= 575 Application.buildnumber=62 -
trunk/src/tmcsim/client/ATMSBatchDriver.java
r183 r184 143 143 incidents = new HashMap<String, List<TrafficEvent>>(); 144 144 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", 148 146 // "192.168.251.46", 8080); //IP address of FEP Sim Linux VM 149 147 "localhost", 8080);
Note: See TracChangeset
for help on using the changeset viewer.
