- Timestamp:
- 06/23/2019 10:27:35 AM (7 years ago)
- Location:
- trunk/src
- Files:
-
- 1 added
- 3 deleted
- 10 edited
- 7 copied
-
archive/ATMSDriver.java (deleted)
-
archive/ExchangeInfo.java (deleted)
-
archive/ExchangeReader.java (deleted)
-
atmsdriver/ConsoleTrafficDriver.java (modified) (3 diffs)
-
atmsdriver/GoogleMapAnimator.java (modified) (2 diffs)
-
atmsdriver/TrafficEventsAnimator.java (modified) (2 diffs)
-
atmsdriver/trafficeventseditor/TimeFrames.java (modified) (3 diffs)
-
atmsdriver/trafficeventseditor/TrafficEventsEditor.java (modified) (1 diff)
-
atmsdriver/trafficeventseditor/TrafficLaneEvent.java (modified) (1 diff)
-
tmcsim/application.properties (modified) (1 diff)
-
tmcsim/cadsimulator/managers/TrafficModelManager.java (modified) (5 diffs)
-
tmcsim/cadsimulator/viewer/TrafficModelViewPanel.java (modified) (1 diff)
-
tmcsim/highwaymodel (added)
-
tmcsim/highwaymodel/Highway.java (copied) (copied from trunk/src/atmsdriver/model/Highway.java) (1 diff)
-
tmcsim/highwaymodel/Highways.java (copied) (copied from trunk/src/atmsdriver/model/Highways.java) (9 diffs)
-
tmcsim/highwaymodel/LoopDetector.java (copied) (copied from trunk/src/atmsdriver/model/LoopDetector.java) (9 diffs)
-
tmcsim/highwaymodel/PostmileCoords.java (copied) (copied from trunk/src/atmsdriver/model/PostmileCoords.java) (1 diff)
-
tmcsim/highwaymodel/Station.java (copied) (copied from trunk/src/atmsdriver/model/Station.java) (4 diffs)
-
tmcsim/highwaymodel/StationComparator.java (copied) (copied from trunk/src/atmsdriver/model/StationComparator.java) (1 diff)
-
tmcsim/highwaymodel/TrafficEvent.java (copied) (copied from trunk/src/atmsdriver/model/TrafficEvent.java) (1 diff)
-
tmcsim/utilities/BuildHighwayFile.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/atmsdriver/ConsoleTrafficDriver.java
r255 r422 1 1 package atmsdriver; 2 2 3 import atmsdriver.model.Highways;4 import atmsdriver.model.Station.DIRECTION;5 import atmsdriver.model.Highway;6 import atmsdriver.model.Station;7 import atmsdriver.model.LoopDetector.DOTCOLOR;3 import tmcsim.highwaymodel.Highways; 4 import tmcsim.highwaymodel.Station.DIRECTION; 5 import tmcsim.highwaymodel.Highway; 6 import tmcsim.highwaymodel.Station; 7 import tmcsim.highwaymodel.LoopDetector.DOTCOLOR; 8 8 import java.io.FileInputStream; 9 9 import java.util.ArrayList; … … 49 49 // Create the Highway Model 50 50 Highways highways = new Highways( 51 "config/vds_data/highways_fullmap.txt", 52 ConsoleDriverProperties.getProperty( 53 "FEPWriterHost"), 54 Integer.parseInt(ConsoleDriverProperties.getProperty( 55 "FEPWriterPort"))); 51 "config/vds_data/highways_fullmap.txt"); 56 52 57 53 // Construct the console driver using the highways model … … 139 135 { 140 136 // Send highway model to FEP for transmit to ATMS 141 try { 142 highways.writeToFEP(); 143 } catch (SimulationException ex) { 144 System.out.println("Skipping writeToFEP..."); 145 } 137 highways.toJson(); 146 138 System.out.println("Add another entry or Quit? (A/Q)"); 147 139 choice = sc.next().toUpperCase().trim().charAt(0); -
trunk/src/atmsdriver/GoogleMapAnimator.java
r340 r422 1 1 package atmsdriver; 2 2 3 import atmsdriver.model.Highways;4 import atmsdriver.model.TrafficEvent;3 import tmcsim.highwaymodel.Highways; 4 import tmcsim.highwaymodel.TrafficEvent; 5 5 import java.io.FileInputStream; 6 6 import java.io.FileNotFoundException; … … 67 67 incidents = new HashMap<String, List<TrafficEvent>>(); 68 68 highways = new Highways( 69 "config/vds_data/highways_fullmap.txt", 70 // following aren't used by this application 71 "localhost", 8080); 69 "config/vds_data/highways_fullmap.txt"); 72 70 final String CONFIG_FILE_NAME = "traffic_model_config.properties"; 73 71 String propertiesFile = "config" + System.getProperty("file.separator") -
trunk/src/atmsdriver/TrafficEventsAnimator.java
r246 r422 1 1 package atmsdriver; 2 2 3 import atmsdriver.model.Highways;4 import atmsdriver.model.TrafficEvent;3 import tmcsim.highwaymodel.Highways; 4 import tmcsim.highwaymodel.TrafficEvent; 5 5 import java.io.FileInputStream; 6 6 import java.io.FileNotFoundException; … … 66 66 incidents = new HashMap<String, List<TrafficEvent>>(); 67 67 highways = new Highways( 68 "config/vds_data/highways_fullmap.txt", 69 // following aren't used by this application 70 "localhost", 8080); 68 "config/vds_data/highways_fullmap.txt"); 71 69 final String CONFIG_FILE_NAME = "traffic_model_config.properties"; 72 70 String propertiesFile = "config" + System.getProperty("file.separator") -
trunk/src/atmsdriver/trafficeventseditor/TimeFrames.java
r240 r422 1 /* 2 * To change this license header, choose License Headers in Project Properties. 3 * To change this template file, choose Tools | Templates 4 * and open the template in the editor. 5 */ 1 6 2 package atmsdriver.trafficeventseditor; 7 3 8 import atmsdriver.model.Highway;9 import atmsdriver.model.Highways;10 import atmsdriver.model.LoopDetector;11 import atmsdriver.model.LoopDetector.DOTCOLOR;12 import atmsdriver.model.Station;4 import tmcsim.highwaymodel.Highway; 5 import tmcsim.highwaymodel.Highways; 6 import tmcsim.highwaymodel.LoopDetector; 7 import tmcsim.highwaymodel.LoopDetector.DOTCOLOR; 8 import tmcsim.highwaymodel.Station; 13 9 import java.util.ArrayList; 14 10 import java.util.List; … … 35 31 { 36 32 frames = new ArrayList<>(); 37 highways = new Highways("./config/vds_data/highways_fullmap.txt", 38 "192.168.251.46", 8080); 33 highways = new Highways("./config/vds_data/postmile_coordinates.txt"); 39 34 } 40 35 … … 194 189 void writeToFEP() 195 190 { 196 try 197 { 198 highways.writeToFEP(); 199 } 200 catch (SimulationException ex) 201 { 202 System.out.println("writeToFEP() failed"); 203 } 191 highways.toJson(); 204 192 } 205 193 -
trunk/src/atmsdriver/trafficeventseditor/TrafficEventsEditor.java
r343 r422 1 1 package atmsdriver.trafficeventseditor; 2 2 3 import atmsdriver.model.Highway;4 import atmsdriver.model.LoopDetector;5 import atmsdriver.model.LoopDetector.DOTCOLOR;6 import atmsdriver.model.Station;3 import tmcsim.highwaymodel.Highway; 4 import tmcsim.highwaymodel.LoopDetector; 5 import tmcsim.highwaymodel.LoopDetector.DOTCOLOR; 6 import tmcsim.highwaymodel.Station; 7 7 import timeselector.*; 8 8 import java.io.File; -
trunk/src/atmsdriver/trafficeventseditor/TrafficLaneEvent.java
r238 r422 1 1 package atmsdriver.trafficeventseditor; 2 2 3 import atmsdriver.model.LoopDetector;4 import atmsdriver.model.LoopDetector.DOTCOLOR;5 import atmsdriver.model.Station;3 import tmcsim.highwaymodel.LoopDetector; 4 import tmcsim.highwaymodel.LoopDetector.DOTCOLOR; 5 import tmcsim.highwaymodel.Station; 6 6 7 7 /** -
trunk/src/tmcsim/application.properties
r419 r422 1 # Thu, 20 Jun 2019 14:43:41-07001 #Sun, 23 Jun 2019 11:49:46 -0700 2 2 3 Application.revision=41 73 Application.revision=419 4 4 5 5 Application.buildnumber=140 -
trunk/src/tmcsim/cadsimulator/managers/TrafficModelManager.java
r407 r422 2 2 3 3 import atmsdriver.GoogleMapAnimator; 4 import atmsdriver.model.Highways;5 import atmsdriver.model.LoopDetector;6 import atmsdriver.model.TrafficEvent;4 import tmcsim.highwaymodel.Highways; 5 import tmcsim.highwaymodel.LoopDetector; 6 import tmcsim.highwaymodel.TrafficEvent; 7 7 import java.awt.event.ActionEvent; 8 8 import java.awt.event.ActionListener; … … 129 129 incidents = new HashMap<String, List<TrafficEvent>>(); 130 130 highways = new Highways( 131 props.getProperty(PROPERTIES.HIGHWAYS_MAP_FILE.name), 132 props.getProperty(PROPERTIES.FEPSIM_IP_ADDR.name), 133 8080); 131 props.getProperty(PROPERTIES.HIGHWAYS_MAP_FILE.name)); 134 132 this.theCoordinator = theCoordinator; 135 133 } … … 211 209 timer.start(); 212 210 213 if (props.getProperty(PROPERTIES.OUTPUT_DEST.name).equals("FEP"))214 {215 // Start the FEP thread (to update ATMS every 30 sec). (See class def below)216 Thread wtfep = new WriteToFEPThread();217 wtfep.start();218 }219 else220 {221 Thread wtConsole = new WriteToConsoleThread();222 wtConsole.start();223 }224 211 // Always write to json for google map display 225 212 Thread wtJson = new WriteToJsonThread(); … … 411 398 } 412 399 413 class WriteToConsoleThread extends Thread414 {415 416 public void run()417 {418 System.out.println("WriteToConsole Thread starting.");419 // Run indefinitely420 while (true)421 {422 // Write the highway network status to the Console423 System.out.println(highways.toString());424 // Pause the thread425 try426 {427 Thread.sleep(10000);428 }429 catch (InterruptedException ie)430 {431 ie.printStackTrace();432 }433 }434 435 }436 }437 400 /** Writes the highway model to a GeoJson file for reading 438 401 * by Google Maps. … … 475 438 } 476 439 477 class WriteToFEPThread extends Thread 478 { 479 480 public void run() 481 { 482 System.out.println("WriteToFEP Thread starting."); 483 // Run indefinitely 484 boolean running = true; 485 while (running) 486 { 487 try 488 { 489 // Write the highway network status to the FEP Simulator 490 highways.writeToFEP(); 491 } 492 catch (SimulationException ex) 493 { 494 // Ask user if they want to proceed without FEP Sim connection 495 // int reply = JOptionPane.showConfirmDialog(null, "Failed to connect to FEP Sim, proceed anyway?", "Network Failure", JOptionPane.YES_NO_OPTION); 496 // if (reply == JOptionPane.NO_OPTION) 497 // { 498 // System.exit(0); 499 // } 500 System.out.println("Skipping writeToFEP..."); 501 running = false; 502 } 503 504 // Wait for FEP Sim to process the data we just sent 505 try 506 { 507 Thread.sleep(FEPSIM_INTERVAL); 508 } 509 catch (InterruptedException ie) 510 { 511 ie.printStackTrace(); 512 } 513 } 514 515 } 516 } 440 517 441 } -
trunk/src/tmcsim/cadsimulator/viewer/TrafficModelViewPanel.java
r277 r422 1 1 package tmcsim.cadsimulator.viewer; 2 2 3 import atmsdriver.model.TrafficEvent;3 import tmcsim.highwaymodel.TrafficEvent; 4 4 import java.util.LinkedList; 5 5 import java.util.List; -
trunk/src/tmcsim/highwaymodel/Highway.java
r353 r422 1 package atmsdriver.model;1 package tmcsim.highwaymodel; 2 2 3 import atmsdriver.model.Station.DIRECTION;3 import tmcsim.highwaymodel.Station.DIRECTION; 4 4 import java.util.ArrayList; 5 5 import java.util.HashSet; -
trunk/src/tmcsim/highwaymodel/Highways.java
r398 r422 1 package atmsdriver.model;1 package tmcsim.highwaymodel; 2 2 3 3 import atmsdriver.trafficeventseditor.TrafficLaneEvent; 4 import atmsdriver.model.LoopDetector.DOTCOLOR; 5 import atmsdriver.model.Station.DIRECTION; 4 import tmcsim.highwaymodel.Station.DIRECTION; 6 5 import java.io.File; 7 6 import java.io.FileInputStream; 8 7 import java.io.FileNotFoundException; 9 import java.io.IOException;10 import java.io.PrintWriter;11 import java.io.StringWriter;12 import java.io.Writer;13 import java.net.Socket;14 8 import java.util.ArrayList; 15 9 import java.util.Collections; … … 21 15 import java.util.logging.Level; 22 16 import java.util.logging.Logger; 23 import javax.xml.parsers.DocumentBuilder;24 import javax.xml.parsers.DocumentBuilderFactory;25 import javax.xml.transform.OutputKeys;26 import javax.xml.transform.Transformer;27 import javax.xml.transform.TransformerFactory;28 import javax.xml.transform.dom.DOMSource;29 import javax.xml.transform.stream.StreamResult;30 import org.w3c.dom.Document;31 import org.w3c.dom.Element;32 import tmcsim.common.SimulationException;33 17 34 18 /** 35 * The Highways class aggregates all Highway instances within a geographic36 * region, and all of the FEPLines within an electronic detector network, in the37 * same geographic region. An instance of Highways.java comprises the underlying38 * model for the ATMSDriver application.19 * Highways represents California state highways supervised by CalTrans. 20 * The highways have sensors to detect traffic flow. In the simulation 21 * the traffic flow is artificially created and Highways maintains the 22 * current levels of traffic flow throughout the network. 39 23 * 40 * Highways uses method writeToFEP() to communicate with the FEP Simulator. It 41 * creates a socket client which sends the FEP Simulator a highways status 42 * message over the socket. This message is sent in the format required by the 43 * FEP Simulator. 24 * Highways builds an internal representation of the highway network 25 * from VDS data (obtained from PeMS) The current state of the network 26 * is output to a json file for use by CPTMS. 44 27 * 45 * 46 * @author John A. Torres 28 * @author John A. Torres, jdalbey 47 29 */ 48 30 final public class Highways 49 31 { 50 51 final private String FEPHostName;52 final private int FEPPortNum;53 54 final private List<FEPLine> lines;55 32 final public List<Highway> highways; 56 33 57 public Highways(String highwaysMapFileName, String FEPHostName, int FEPPortNum) 58 { 59 // load FEP Lines 60 lines = loadLines(highwaysMapFileName); 61 // build highways data structure 62 this.highways = buildHighways(); 63 64 // write to FEP host and port number 65 this.FEPHostName = FEPHostName; 66 this.FEPPortNum = FEPPortNum; 67 } 68 69 private ArrayList<Highway> buildHighways() 70 { 34 public Highways(String highwaysMapFileName) 35 { 36 // build highways data structure 37 this.highways = buildHighwayNetwork(highwaysMapFileName); 38 } 39 40 private ArrayList<Highway> buildHighwayNetwork(String highwaysMapFileName) 41 { 42 // NOTE: Could this method be streamlined? Is it necessary to have the 43 // second data structure? 71 44 System.out.println("Building highways..."); 72 45 // The list of highways to return … … 76 49 Map<Integer, ArrayList<Station>> highwayMap = new HashMap<>(); 77 50 78 // iterate through FEPLines and get data to add to the above map79 for (FEPLine line : lines)80 {81 // grab all stations from the current FEPLine82 ArrayList<Station> lineStations = (ArrayList<Station>) line.stations;83 // iterate through each station in the list of stations84 for (Station station : lineStations)85 {51 // Open the postmile file and scan each line 52 File file = new File(highwaysMapFileName); 53 try 54 { 55 Scanner scanner = new Scanner(file); 56 while (scanner.hasNext()) 57 { 58 Station station = loadStation(scanner); 86 59 Integer hwyNum = station.routeNumber; 87 60 // if the map does not contain an entry for the highway, create … … 101 74 } 102 75 } 103 } 104 76 }catch (FileNotFoundException e) { 77 e.printStackTrace(); 78 } 105 79 // get the set of highway numbers 106 80 Set<Integer> hwyKeys = highwayMap.keySet(); … … 229 203 } 230 204 205 231 206 /** 232 * Loads all FEPLines from the specified highways map file. 233 * 234 * @param highwaysMapFileName 235 * @return List of FEPLines 236 */ 237 private ArrayList<FEPLine> loadLines(String highwaysMapFileName) 238 { 239 ArrayList<FEPLine> lines = new ArrayList<>(); 240 try 241 { 242 Scanner sc = new Scanner(new File(highwaysMapFileName)); 243 // first line of file contains number of FEP Lines 244 String firstLine = sc.nextLine(); 245 Scanner linesc = new Scanner(firstLine); 246 int numLines = linesc.nextInt(); 247 linesc.close(); 248 // FOR each FEP Line 249 for (int i = 0; i < numLines; i++) 250 { 251 lines.add(loadLine(sc)); 252 } 253 sc.close(); 254 255 } catch (FileNotFoundException ex) 256 { 257 Logger.getLogger(Highways.class.getName()).log(Level.SEVERE, null, ex); 258 } 259 return lines; 260 } 261 262 /** 263 * Load all the stations for a single FEP Line from the highways map file. 264 * 265 * @param sc scanner at the current FEPLine line 266 * @return FEPLine 267 */ 268 private FEPLine loadLine(Scanner sc) 207 * Loads a single Station from the postmile coordinates file 208 * @param sc scanner at the current station line 209 * @return Station 210 */ 211 private Station loadStation(Scanner sc) 269 212 { 270 213 String line = sc.nextLine(); 271 214 Scanner scline = new Scanner(line); 272 // Get the attributes of this FEP Line 273 int lineNum = scline.nextInt(); 274 int count = scline.nextInt(); 275 int numStations = scline.nextInt(); 215 scline.useDelimiter(","); 276 216 277 // initialze stations array 278 ArrayList<Station> stations = new ArrayList<>(); 279 // Read all the stations for thie FEP Line 280 for (int i = 0; i < numStations; i++) 281 { 282 stations.add(loadStation(sc, lineNum)); 283 } 284 285 return new FEPLine(lineNum, stations, count); 286 } 287 288 /** 289 * Loads a single Station from the highways map file 290 * @param sc scanner at the current station line 291 * @param lineNum the FEPLine number for the station 292 * @return Station 293 */ 294 private Station loadStation(Scanner sc, int lineNum) 295 { 296 String line = sc.nextLine(); 297 Scanner scline = new Scanner(line); 298 299 int ldsID = scline.nextInt(); 300 int drop = scline.nextInt(); 301 int fwy = scline.nextInt(); 302 DIRECTION dir = DIRECTION.toDirection(scline.next()); 303 double postmile = scline.nextDouble(); 304 int numLoops = scline.nextInt(); 305 String location = getStationLoc(line); 217 String route = scline.next(); // FWY DIR POSTMILE 218 scline.next(); // skip lat 219 scline.next(); // skip long 220 String description = scline.next(); // the description of the location 221 222 Scanner rteScan = new Scanner(route); 223 int fwy = rteScan.nextInt(); 224 DIRECTION dir = DIRECTION.toDirection(rteScan.next()); 225 double postmile = rteScan.nextDouble(); 226 306 227 ArrayList<LoopDetector> loops = new ArrayList<>(); 307 for (int i = 0; i < numLoops; i++) 308 { 309 loops.add(loadLoop(sc)); 310 } 311 312 return new Station(lineNum, ldsID, drop, location, loops, fwy, dir, postmile); 313 } 314 315 /** 316 * Loads a single loop from the highways map file 317 * 318 * @param sc scanner at the current loop line 319 * @return LoopDetector 320 */ 321 private LoopDetector loadLoop(Scanner sc) 322 { 323 String line = sc.nextLine(); 324 Scanner scline = new Scanner(line); 325 326 int loopID = scline.nextInt(); 327 String loopLocID = scline.next(); 328 String loopLoc = scline.next(); 329 scline.close(); 330 return new LoopDetector(loopID, loopLocID, loopLoc); 331 } 332 333 /** 334 * Scans the LoopDetector line and grabs the String location from the line. 335 * 336 * @param line the line containing the location 337 * @return A String loop location. 338 */ 339 private String getLoopLoc(String line) 340 { 341 Scanner sc = new Scanner(line); 342 sc.nextInt(); 343 344 // GRABS FROM CURRENT TO END OF LINE 345 sc.useDelimiter("\\z"); 346 String loc = sc.next().trim(); 347 sc.close(); 348 return loc; 349 } 350 351 /** 352 * Scans the Station line and grabs the String location from the line. 353 * 354 * @param line the line containing the location 355 * @return A String station location. 356 */ 357 private String getStationLoc(String line) 358 { 359 Scanner scline = new Scanner(line); 360 scline.nextInt(); 361 scline.nextInt(); 362 scline.nextInt(); 363 scline.next(); 364 scline.nextDouble(); 365 scline.nextInt(); 366 367 // GRABS FROM CURRENT TO END OF LINE 368 scline.useDelimiter("\\z"); 369 String loc = scline.next().trim(); 370 scline.close(); 371 return loc; 372 } 373 374 /** 375 * Creates a socket client that writes the Highways data to the FEP Simulator. 376 * 377 * @throws SimulationException 378 */ 379 public void writeToFEP() throws SimulationException 380 { 381 try 382 { 383 // Create the socket to the FEP Simulator 384 Socket sock = new Socket(FEPHostName, FEPPortNum); 385 PrintWriter out = new PrintWriter(sock.getOutputStream(), true); 386 387 // Print the number of bytes the highways data message contains 388 System.out.println("Highways sending " + this.toCondensedFormat(false).toCharArray().length + 1 + "bytes to FEPSIM."); 389 String outMsg = this.toCondensedFormat(false); 390 // Write the highways data over the socket 391 out.println(outMsg); 392 393 // close the socket 394 sock.close(); 395 } catch (java.net.ConnectException ex) 396 { 397 //Logger.getLogger(Highways.class.getName()).log(Level.SEVERE, null, ex); 398 System.out.println("writeToFEP() can't connect, no data sent to FEP."); 399 throw new SimulationException(SimulationException.BINDING); 400 } catch (IOException ex) 401 { 402 //Logger.getLogger(Highways.class.getName()).log(Level.SEVERE, null, ex); 403 System.out.println("Highway Model failed writing to FEPSim."); 404 throw new SimulationException(SimulationException.BINDING); 405 } 406 } 407 408 /** Returns a string of highways data. If MetaDataOnly is true, you get a full 409 * dump of the highways meta data, which does not include dynamic loop values, 410 * and does include the string location names. If MetaDataOnly is false, 411 * dynamic loop values are included, and unnecessary information like string 412 * location values are not included. 413 * 414 * The FEPSimulator takes in the toCondensedFormat() output, with a MetaDataOnly 415 * value of false, over the socket. 416 * 417 * The MetaDataOnly flag should be used to get a full dump of the highways 418 * information. This was used to get the highways_fullmap.txt output. 419 * 420 * @param MetaDataOnly Whether you want meta data, or a full dump for FEPSim 421 * @return String, highways data in condensed format 422 * 423 * Example toCondensedFormat(MetaDataOnly = false) output: 424 * 425 * 43 // "number of lines" 426 * 32 0 13 // "line id" "count num" "number of stations" 427 * 1210831 1 5 S 0.9 8 // "station id" "drop num" "route num"... 428 * // ..."direction" "postmile" "number of loops" 429 * 1210832 0.0 0 ML_1 // "loop id" "occ" "vol" 430 * 1210833 0.0 0 ML_2 // .. 431 * 1210834 0.0 0 ML_3 // .. 432 * 1210835 0.0 0 ML_4 // .. 433 * 1210836 0.0 0 PASSAGE // .. 434 * 1210837 0.0 0 DEMAND // .. 435 * 1210838 0.0 0 QUEUE // .. 436 * 1210839 0.0 0 RAMP_OFF // .. 437 * ... 438 * 439 * Example toCondensedFormat(MetaDataOnly = true) output: 440 * 441 * 43 // "number of lines" 442 * 32 0 13 // "line id" "count num" "number of stations" 443 * 1210831 1 5 S 0.9 8 CALAFIA // "station id" "drop num" "route num"... 444 * // ..."direction" "postmile"... 445 * // ..."number of loops" "string location" 446 * 1210832 ML_1 // "loop id" "loop location" 447 * 1210833 ML_2 // " " 448 * 1210834 ML_3 // " " 449 * 1210835 ML_4 // " " 450 * 1210836 PASSAGE // " " 451 * 1210837 DEMAND // " " 452 * 1210838 QUEUE // " " 453 * 1210839 RAMP_OFF // " " 454 * ... 455 */ 456 public String toCondensedFormat(boolean MetaDataOnly) 457 { 458 // first line: number of FEPLines 459 StringBuilder build = new StringBuilder(); 460 build.append(lines.size()); 461 build.append("\n"); 462 // append each fep line to the string 463 for(FEPLine line : lines) 464 { 465 build.append(line.toCondensedFormat(MetaDataOnly)); 466 } 467 // return the full condensed format string 468 return build.toString(); 469 } 470 471 /** 472 * Returns the Highways model data in XML format. 473 * Probably obsolete, since we aren't using exchange.xml any longer. 474 * @return highways data in XML format 475 */ 476 public String toXML() 477 { 478 String xml = null; 479 try 480 { 481 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 482 DocumentBuilder builder = factory.newDocumentBuilder(); 483 Document theDoc = builder.newDocument(); 484 485 Element networkElement = theDoc.createElement(XML_TAGS.NETWORK.tag); 486 theDoc.appendChild(networkElement); 487 488 for (FEPLine line : lines) 489 { 490 line.toXML(networkElement); 491 } 492 493 Transformer tf = TransformerFactory.newInstance().newTransformer(); 494 495 tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); 496 tf.setOutputProperty(OutputKeys.INDENT, "yes"); 497 tf.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); 498 499 Writer out = new StringWriter(); 500 tf.transform(new DOMSource(theDoc), new StreamResult(out)); 501 xml = out.toString(); 502 out.close(); 503 } catch (Exception ex) 504 { 505 Logger.getLogger(Highways.class.getName()).log(Level.SEVERE, null, ex); 506 } 507 return xml; 508 509 } 510 228 // For now we'll use just a dummy loop detector 229 LoopDetector detector = new LoopDetector(1,"ML","ML_1"); 230 loops.add(detector); 231 232 return new Station(11, 123, 99, description, loops, fwy, dir, postmile); 233 } 234 511 235 /** 512 236 * Returns a highway by given highway number. … … 531 255 } 532 256 533 /** Return a string representation of the Highways */257 /** Return a string representation of the Highways - for debugging */ 534 258 public String toString() 535 259 { … … 543 267 StringBuilder lineout = new StringBuilder(); 544 268 // Examine every station on this highway and direction 545 for (Station stat : hwy.stations)546 { 547 if (stat .direction.equals(dir))269 for (Station station: hwy.stations) 270 { 271 if (station.direction.equals(dir)) 548 272 { 549 273 //lineout.append("" + dir.getLetter() + stat.postmile); 550 lineout.append(stat .getColor());274 lineout.append(station.getColor().symbol()); 551 275 //lineout.append(" "); 552 276 } … … 616 340 String outString = currentPM.toJson(); 617 341 // replace the color code with the color name 618 String colorName=stat.getColor Name();342 String colorName=stat.getColor().htmlColor(); 619 343 outString = outString.replace("desiredcolor",colorName); 620 344 lineout.append(outString); … … 664 388 } 665 389 666 public void reset() 667 { 668 for(FEPLine line : lines) 669 { 670 for(Station stn : line.stations) 390 /** Reset all the traffic levels to free flowing (green) */ 391 public void reset() 392 { 393 for(Highway hwy: highways) 394 { 395 for(Station stn : hwy.stations) 671 396 { 672 397 for(LoopDetector ld : stn.loops) 673 398 { 674 ld.occ = 0; 675 ld.vol = 0; 399 ld.setAttributes(LoopDetector.DOTCOLOR.GREEN); 676 400 } 677 401 } -
trunk/src/tmcsim/highwaymodel/LoopDetector.java
r343 r422 1 package atmsdriver.model;1 package tmcsim.highwaymodel; 2 2 3 3 import java.util.ArrayList; … … 12 12 * occ, and spd. 13 13 * 14 * Lane Type A string indicating the type of lane. Possible values (and their meaning) are: 15 * 16 * CD (Coll/Dist) 17 * CH (Conventional Highway) 18 * FF (Fwy-Fwy connector) 19 * FR (Off Ramp) 20 * HV (HOV) 21 * ML (Mainline) 22 * OR (On Ramp) 14 23 * @author John A. Torres 15 24 * @version 09/10/2017 … … 28 37 /** 29 38 * Constructs a LoopDetector from loopID, loopLocation, and laneNum 39 * with initially free flowing traffic. 30 40 * 31 41 * @param loopID … … 44 54 } 45 55 56 /** 57 * Setter for loop detector dynamic attributes. Reserved for future use 58 * with "live" highway data. 59 * @param vol volume 60 * @param occ occupancy 61 * @param spd speed not used 62 */ 63 public void setAttributes(int vol, float occ) 64 { 65 this.vol = vol; 66 this.occ = occ; 67 } 68 /** Set the attributes of this detector given a color. 69 * @param DOTCOLOR of the attributes to assign. 70 */ 71 public void setAttributes(DOTCOLOR color) 72 { 73 this.vol = color.volume(); 74 this.occ = color.occupancy(); 75 } 46 76 /** 47 77 * XML tags used for toXML() method. … … 100 130 return build.toString(); 101 131 } 102 103 /**104 * Updates loop detector dynamic attributes.105 * @param vol volume106 * @param occ occupancy107 * @param spd speed108 */109 public void updateLoop(int vol, float occ)110 {111 this.vol = vol;112 this.occ = occ;113 }114 132 115 133 /** … … 144 162 /** 145 163 * Enum for highway status dot colors. Each color has associated volume 146 * and occupancy constants .164 * and occupancy constants, single character symbol, and hml color name. 147 165 * 148 166 * @author John A. Torres, jdalbey … … 151 169 public static enum DOTCOLOR { 152 170 153 RED(1, 0.06f ), // "Stopped" is less than 25mph154 YELLOW(3,0.059f ), // speed = 26155 GREEN(0,0 );171 RED(1, 0.06f,'@',"red"), // "Stopped" is less than 25mph 172 YELLOW(3,0.059f,'+',"yellow"), // speed = 26 173 GREEN(0,0,'-',"lime"); // freeflowing 156 174 157 175 // All the first letters of the values, in order. … … 160 178 private int vol; /* volume */ 161 179 private float occ; /* occupancy */ 162 163 private DOTCOLOR(int v, float o) 180 private char symbol; /* symbolic representation of this color */ 181 private String htmlColor; /* html color name */ 182 183 184 private DOTCOLOR(int v, float o, char symbol, String htmlColor) 164 185 { 165 186 vol = v; 166 187 occ = o; 188 this.symbol = symbol; 189 this.htmlColor = htmlColor; 167 190 } 168 191 /** … … 183 206 return occ; 184 207 } 208 public char symbol() 209 { 210 return symbol; 211 } 212 public String htmlColor() 213 { 214 return htmlColor; 215 } 185 216 /** 186 * Returns a dot colorgiven its first character.217 * Returns a DOTCOLOR given its first character. 187 218 * 188 * @param letter the first character of a dot color189 * @return dot colorcorresponding to letter219 * @param letter the first character of a DOTCOLOR 220 * @return DOTCOLOR corresponding to letter 190 221 * @pre letter must be one of allLetters 191 222 */ -
trunk/src/tmcsim/highwaymodel/PostmileCoords.java
r274 r422 1 1 2 package atmsdriver.model;2 package tmcsim.highwaymodel; 3 3 4 4 import java.util.ArrayList; -
trunk/src/tmcsim/highwaymodel/Station.java
r343 r422 1 package atmsdriver.model;2 3 import atmsdriver.model.LoopDetector.DOTCOLOR;1 package tmcsim.highwaymodel; 2 3 import tmcsim.highwaymodel.LoopDetector.DOTCOLOR; 4 4 import java.util.ArrayList; 5 5 import java.util.List; … … 9 9 /** 10 10 * A Station (VDS or Vehicle Detector Station) represents a group of lane detectors 11 * across all lanes in onedirection at a particular point on a highway. A station is identified11 * across all lanes in ONE direction at a particular point on a highway. A station is identified 12 12 * by its highway number and postmile. A station has an associated direction 13 13 * used to establish which direction is Main and which is Opposite. The MLTotVol … … 194 194 outputUpdateMessage(dotColor, direction.toString()); 195 195 196 // Set the values for all lanes at this station 196 197 for (LoopDetector loop : loops) 197 198 { 198 // THIS DECISION ISN'T NEEDED after JD's BuildHighwayFile pgm 199 // creates a highway map based on VDS instead of Controller (LDS). 200 // if (loop.loopLocation.startsWith(laneDir)) 201 // { 202 // UPDATE LOOP WITH VALUES 203 loop.updateLoop(dotColor.volume(), dotColor.occupancy()); 204 // } 199 // Set loop detector attributes given the desired color 200 loop.setAttributes(dotColor); 205 201 } 206 202 … … 210 206 } 211 207 /** 212 * Return the color for the lanes in a given direction. 213 * @return character representing color of this station's traffic flow 214 * '@' = red, '+' = yellow, '-' = green 215 */ 216 public char getColor() 208 * Compute the color for the lanes in a given direction. 209 * @return DOTCOLOR of this station's traffic flow 210 */ 211 public DOTCOLOR getColor() 217 212 { 218 213 /* For now just use the color of the first lane. 219 * TODO: Average the color in ALL the lanes for the given direction*/214 * TODO: Average the color in ALL the lanes */ 220 215 221 216 String laneDir = ""; 222 217 223 // THIS DECISION ISN'T NEEDED after JD's BuildHighwayFile pgm 224 // creates a highway map based on VDS instead of Controller (LDS). 225 // if (direction.equals(this.direction)) 226 // { 227 // laneDir = "ML"; 228 // } 229 // else if (direction.equals(this.direction.getOpposite())) 230 // { 231 // laneDir = "OS"; 232 // } 233 // Search lanes to find specified direction 234 for (LoopDetector loop : loops) 235 { 236 // THIS DECISION ISN'T NEEDED after JD's BuildHighwayFile pgm 237 // creates a highway map based on VDS instead of Controller (LDS). 238 // if (loop.loopLocation.substring(0,2).equals(laneDir)) 239 // { 240 // Return color according to loop volume of first matching lane 241 if (loop.vol == 1) 242 { 243 return '@'; 244 } 245 if (loop.vol == 3) 246 { 247 return '+'; 248 } 249 if (loop.vol == 0) 250 { 251 return '-'; 252 } 253 // } 254 } 255 // Default case for when the route is not on this direction 256 return ' '; 257 } 258 /** 259 * Return the color name for the traffic volume of this station. 260 */ 261 public String getColorName() 262 { 263 String colorName = ""; 264 switch (this.getColor()) 265 { 266 case '@': colorName = "red";break; 267 case '+': colorName = "yellow"; break; 268 case '-': colorName = "lime";break; 269 case ' ': colorName = "lime";break; 270 } 271 return colorName; 272 } 218 // FOR FUTURE USE we will need to examine all detectors for this station 219 // and perform an average 220 // for (LoopDetector loop : loops) 221 { 222 // for now, Return color according to loop volume of first lane 223 if (loops.get(0).vol == 1) 224 { 225 return DOTCOLOR.RED; 226 } 227 if (loops.get(0).vol == 3) 228 { 229 return DOTCOLOR.YELLOW; 230 } 231 if (loops.get(0).vol == 0) 232 { 233 return DOTCOLOR.GREEN; 234 } 235 } 236 237 // Default case for invalid data 238 return DOTCOLOR.GREEN; 239 } 240 273 241 /** 274 242 * Output for updateByDirection. Logs the update to the console. -
trunk/src/tmcsim/highwaymodel/StationComparator.java
r353 r422 1 package atmsdriver.model;1 package tmcsim.highwaymodel; 2 2 3 3 import java.util.Comparator; -
trunk/src/tmcsim/highwaymodel/TrafficEvent.java
r204 r422 1 1 2 package atmsdriver.model;2 package tmcsim.highwaymodel; 3 3 4 4 import java.text.ParseException; -
trunk/src/tmcsim/utilities/BuildHighwayFile.java
r345 r422 15 15 16 16 /** 17 * OBSOLETE since deprecating ATMS functionality. No longer used. 17 18 * This utility program is used to create the highway map file used as part 18 19 * of the configuration files needed by the simulator.
Note: See TracChangeset
for help on using the changeset viewer.
