Changeset 103 in tmcsimulator for trunk/src/atmsdriver/model
- Timestamp:
- 10/12/2017 12:28:28 AM (9 years ago)
- Location:
- trunk/src/atmsdriver/model
- Files:
-
- 5 edited
-
FEPLine.java (modified) (3 diffs)
-
Highway.java (modified) (2 diffs)
-
Highways.java (modified) (8 diffs)
-
LoopDetector.java (modified) (1 diff)
-
Station.java (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/atmsdriver/model/FEPLine.java
r88 r103 4 4 import org.w3c.dom.Document; 5 5 import org.w3c.dom.Element; 6 7 8 6 9 7 /** An FEPLine is a simulated line of communication from the FEP to … … 18 16 public class FEPLine { 19 17 /* Static FEPLine meta data */ 20 final p rivateint lineNum;21 final p rivateList<Station> stations;18 final public int lineNum; 19 final public List<Station> stations; 22 20 final private int count; 23 // NOT SURE IF NEXT IS FINAL21 24 22 final private int schedule; 25 23 final private int lineInfo; 26 24 final private long systemKey; 25 26 // THESE WILL NEED TO BE UPDATED MAYBE, NOT SURE, NOT A PRIORITY. SEE METHOD 27 // UPDATESEQUENCES() 27 28 private long globalSeq; 28 29 private long scheduleSeq; … … 40 41 this.globalSeq = globalSeq; 41 42 this.scheduleSeq = scheduleSeq; 42 }43 44 public int getLineNumber()45 {46 return this.lineNum;47 }48 49 public List<Station> getStations()50 {51 return this.stations;52 43 } 53 44 -
trunk/src/atmsdriver/model/Highway.java
r93 r103 10 10 * @author jdalbey 11 11 */ 12 final class Highway12 final public class Highway 13 13 { 14 14 /** The identifying number for this highway, e.g., 101 */ 15 public final Integer highwayNumber;15 public final Integer routeNumber; 16 16 /** The ordered list of stations (lane detector stations) on this highway */ 17 17 public final ArrayList<Station> stations; … … 22 22 * @param stations ordered list of stations on this highway 23 23 */ 24 public Highway(Integer highwayNum, ArrayList<Station> stations)24 public Highway(Integer routeNumber, ArrayList<Station> stations) 25 25 { 26 this. highwayNumber = highwayNum;26 this.routeNumber = routeNumber; 27 27 this.stations = stations; 28 28 } -
trunk/src/atmsdriver/model/Highways.java
r101 r103 1 1 package atmsdriver.model; 2 2 3 import atmsdriver.NetworkLoader; 4 import atmsdriver.model.Station.DIRECTION; 3 import atmsdriver.FEPLineLoader; 5 4 import java.io.File; 6 import java.io.FileNotFoundException;7 5 import java.io.FileWriter; 8 6 import java.io.IOException; … … 13 11 import java.util.ArrayList; 14 12 import java.util.Collections; 15 import java.util.Enumeration;16 13 import java.util.HashMap; 17 import java.util.Hashtable;18 import java.util.List;19 14 import java.util.Map; 20 15 import java.util.Observable; 21 16 import java.util.Observer; 22 import java.util.Scanner;23 17 import java.util.Set; 24 18 import java.util.logging.Level; … … 34 28 import org.w3c.dom.Element; 35 29 36 /** 30 /** The Highways class aggregates all Highway instances within a geographic 31 * region, and all of the FEPLines within an electronic detector 32 * network, in the same geographic region. An instance of Highways.java 33 * comprises the underlying model for the ATMSDriver application. 34 * 35 * Highways uses method writeToFEP() to communicate with the FEP Simulator. 36 * It creates a socket client which sends the FEP Simulator a highways status 37 * message over the socket. This message is in the XML format required by the 38 * FEP Simulator, which is provided by the resident toXML() method. 39 * 40 * Currently, there is no driving logic within the highways class. It is only 41 * done through an instance of the ConsoleDriver.java class. Eventually, it 42 * will receive incident data (from exchange.xml or better yet, directly from 43 * the TMCSimulator itself) and drive the highways using resident logic. 37 44 * 38 45 * @author John A. Torres 39 46 */ 40 public class Highways implements Observer{47 public class Highways { 41 48 42 49 final private ArrayList<FEPLine> lines; 43 50 final private String FEPHostName; 44 51 final private int FEPPortNum; 45 final private ArrayList<Highway> highways;46 private Map<Integer, List<Station>> HiwayMap = new HashMap<Integer, List<Station>>();47 52 48 // NEED FINISH final private ArrayList<Highway> highways; 53 final public ArrayList<Highway> highways; 54 49 55 public Highways(String ldsFileName, String loopsFileName, 50 56 String highwayMetaFileName, String FEPHostName, int FEPPortNum) { … … 54 60 */ 55 61 56 NetworkLoader ldr = new NetworkLoader(new File(ldsFileName), new File(loopsFileName));62 FEPLineLoader ldr = new FEPLineLoader(new File(ldsFileName), new File(loopsFileName)); 57 63 this.lines = (ArrayList<FEPLine>) ldr.getFEPLines(); 58 64 this.FEPHostName = FEPHostName; … … 61 67 //writeHighwaysMeta("hard.txt"); 62 68 } 63 64 public ArrayList<Highway> getHighways()65 {66 return this.highways;67 }68 69 69 70 70 private ArrayList<Highway> loadHighways() { … … 72 72 // The list of highways to return 73 73 ArrayList<Highway> highways = new ArrayList<Highway>(); 74 Hashtable<Hashtable<Integer, DIRECTION>, ArrayList<Station>> 75 highwayTable = new Hashtable<>(); 74 75 Map<Integer, ArrayList<Station>> 76 highwayMap = new HashMap<>(); 76 77 77 78 for (FEPLine line : lines) 78 79 { 79 ArrayList<Station> lineStations = (ArrayList<Station>) line. getStations();80 ArrayList<Station> lineStations = (ArrayList<Station>) line.stations; 80 81 for(Station station : lineStations) 81 82 { 82 Integer hwyNum = station.getHighwayNumber(); 83 DIRECTION dir = station.getDirection(); 84 Hashtable<Integer, DIRECTION> check = new Hashtable<>(); 85 check.put(hwyNum, dir); 86 if(highwayTable.get(check) == null) 83 Integer hwyNum = station.routeNumber; 84 85 if(!highwayMap.containsKey(hwyNum)) 87 86 { 88 87 ArrayList<Station> stnList = new ArrayList<>(); 89 88 stnList.add(station); 90 Hashtable<Hashtable<Integer, DIRECTION>, ArrayList<Station>> 91 newEntry = new Hashtable(); 92 newEntry.put(check, stnList); 93 highwayTable.putAll(newEntry); 89 highwayMap.put(hwyNum, stnList); 94 90 } 95 91 else 96 92 { 97 highway Table.get(check).add(station);93 highwayMap.get(hwyNum).add(station); 98 94 } 99 95 } 100 96 } 101 97 102 Set< Hashtable<Integer, DIRECTION>> hwyKeys = highwayTable.keySet();103 for( Hashtable<Integer, DIRECTION>hwyKey : hwyKeys)98 Set<Integer> hwyKeys = highwayMap.keySet(); 99 for(Integer hwyKey : hwyKeys) 104 100 { 105 Enumeration<Integer> hwyNumEnum = hwyKey.keys(); 106 Integer hwyNum = hwyNumEnum.nextElement(); 107 ArrayList<Station> hwyStations = highwayTable.get(hwyKey); 108 DIRECTION hwyDir = hwyKey.get(hwyNum); 109 Collections.sort(highwayTable.get(hwyKey)); 110 System.out.println("Adding highway: " + hwyNum + " " + hwyDir.toString().charAt(0)); 111 highways.add(new Highway(hwyNum, 101 ArrayList<Station> hwyStations = highwayMap.get(hwyKey); 102 Collections.sort(hwyStations); 103 System.out.println("Loaded highway " + hwyKey + "..."); 104 highways.add(new Highway(hwyKey, 112 105 hwyStations)); 113 106 } 107 System.out.println(""); 114 108 return highways; 115 109 } 110 116 111 /* 117 112 private ArrayList<FEPLine> loadLines(String highwayMetaFileName) { … … 215 210 216 211 public void writeToFEP() { 217 System.out.println(this.toXML().toCharArray().length);218 219 212 try { 220 213 Socket sock = new Socket(FEPHostName, FEPPortNum); … … 293 286 } 294 287 295 @Override 296 public void update(Observable o, Object arg) { 297 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. 288 public Highway getHighwayByRouteNumber(Integer routeNum) { 289 Highway returnHwy = null; 290 for(Highway hwy : highways) 291 { 292 if(hwy.routeNumber.equals(routeNum)) 293 { 294 returnHwy = hwy; 295 break; 296 } 297 } 298 return returnHwy; 298 299 } 299 300 -
trunk/src/atmsdriver/model/LoopDetector.java
r87 r103 17 17 { 18 18 /* static data */ 19 final p rivateint loopID;20 final p rivateString loopLocation;21 final p rivateint laneNum;19 final public int loopID; 20 final public String loopLocation; 21 final public int laneNum; 22 22 23 23 /* dynamic data */ -
trunk/src/atmsdriver/model/Station.java
r94 r103 1 1 package atmsdriver.model; 2 2 3 import atmsdriver.ConsoleDriver; 4 import atmsdriver.ConsoleDriver.DOTCOLOR; 3 5 import java.util.List; 4 6 import org.w3c.dom.Document; … … 21 23 22 24 /* Static Station meta data */ 23 final p rivateint lineNum;24 final p rivateint ldsID; // double check25 final p rivateint drop;26 final p rivateString location;27 final p rivateList<LoopDetector> loops;28 final p rivate int highwayNum;29 final p rivatedouble postmile;30 final p rivateDIRECTION direction;25 final public int lineNum; 26 final public int ldsID; // double check 27 final public int drop; 28 final public String location; 29 final public List<LoopDetector> loops; 30 final public int routeNumber; 31 final public double postmile; 32 final public DIRECTION direction; 31 33 32 34 /* Dynamic Station data */ … … 46 48 this.postmile = postmile; 47 49 this.direction = direction; 48 this. highwayNum= hwy;50 this.routeNumber = hwy; 49 51 50 52 this.MLTotVol = 0; 51 53 this.OppTotVol = 0; 52 }53 54 public int getHighwayNumber()55 {56 return this.highwayNum;57 }58 59 public DIRECTION getDirection()60 {61 return this.direction;62 54 } 63 55 … … 76 68 build.append(Integer.toString(this.drop)); 77 69 build.append(" "); 78 build.append(Integer.toString(this. highwayNum));70 build.append(Integer.toString(this.routeNumber)); 79 71 build.append(" "); 80 72 build.append(this.direction.getLetter()); … … 91 83 } 92 84 return build.toString(); 93 }94 95 public double getPostmile()96 {97 return postmile;98 85 } 99 86 … … 117 104 118 105 // get difference of values 119 double otherStationPostmile = ((Station) otherStation). getPostmile();106 double otherStationPostmile = ((Station) otherStation).postmile; 120 107 double val = this.postmile - otherStationPostmile; 121 108 … … 134 121 } 135 122 123 public void updateByDirection(DIRECTION direction, DOTCOLOR dotColor) { 124 if(direction.equals(this.direction)) 125 { 126 updateML(dotColor); 127 } 128 else 129 { 130 updateOPP(dotColor); 131 } 132 } 133 134 private void updateML(DOTCOLOR dotcolor) 135 { 136 outputUpdateMessage(dotcolor, "ML"); 137 138 for(LoopDetector loop : loops) 139 { 140 if(loop.loopLocation.startsWith("ML")) 141 { 142 // UPDATE LOOP WITH VALUES 143 } 144 } 145 } 146 147 private void updateOPP(DOTCOLOR dotcolor) 148 { 149 outputUpdateMessage(dotcolor, "OPP"); 150 for(LoopDetector loop : loops) 151 { 152 if(loop.loopLocation.startsWith("OP")) 153 { 154 // UPDATE LOOP WITH VALUES 155 } 156 } 157 } 158 159 private void outputUpdateMessage(DOTCOLOR dotcolor, String OPP_ML) 160 { 161 System.out.printf("Updating route %-3.3s %-5.5s %-3.3s lanes\t %-12.12s " 162 + "at postmile %-6.6s to %-7.7s\n", 163 Integer.toString(this.routeNumber), this.direction.name(), 164 OPP_ML, this.location, Double.toString(this.postmile), 165 dotcolor.name()); 166 } 167 136 168 private static enum XML_TAGS 137 169 { … … 189 221 190 222 Element freewayElement = theDoc.createElement(XML_TAGS.FREEWAY.tag); 191 freewayElement.appendChild(theDoc.createTextNode(String.valueOf(this. highwayNum)));223 freewayElement.appendChild(theDoc.createTextNode(String.valueOf(this.routeNumber))); 192 224 stationElement.appendChild(freewayElement); 193 225
Note: See TracChangeset
for help on using the changeset viewer.
