Changeset 103 in tmcsimulator for trunk/src


Ignore:
Timestamp:
10/12/2017 12:28:28 AM (9 years ago)
Author:
jtorres
Message:

trunk/src/atmsdriver/ConsoleDriver.java: Created console driver for ATMSDriver, completed and very nice. Still need to apply correct vol/occ values to actually change the colors. Still need to write a JUnit test for it. trunk/src/atmsdriver/ATMSDriver.java: Refactored to run the console driver. ATMSDriver runs in thread, console driver runs, and they share the highways instance. Renamed NetworkLoader?.java to FEPLineLoader.java. trunk/src/atmsdriver/model/Highways.java: refactored loadHighways() method to conform to new undirected highway abstraction. trunk/src/atmsdriver/model/Station.java: added updateByDirection(DIRECTION dir) method and supporting utility methods. trunk/test/atmsdriver/model/LoadHighwaysTest.java: Conformed LoadHighways? test to new undirected highway abstraction. trunk/test/atmsdriver/model/StationTest.java: Conformed StationTest?.java to new changes - very minor stuff. Went through all model classes and changed any final privates with a getter method to final public, for good OOP practice and simplicity. Went through ALL FILES and commented everything very well. minor application custom configuration changes. Removed all .class or .o.d files from svn repository

Location:
trunk/src
Files:
8 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/atmsdriver/ATMSDriver.java

    r88 r103  
    22 
    33import atmsdriver.model.Highways; 
    4 import java.io.File; 
    54import java.io.FileInputStream; 
    6 import java.io.FileNotFoundException; 
    7 import java.io.PrintWriter; 
    85import java.util.Properties; 
    96import java.util.logging.Level; 
     
    2522     */ 
    2623    private static Logger ATMSDriverLogger = Logger.getLogger("atmsdriver"); 
    27  
    28     private static final String CONFIG_FILE_NAME = "atms_driver_config.properties"; 
    2924 
    3025    /** 
     
    9590 
    9691    public ATMSDriver(String propertiesFile) { 
    97  
     92        // verify properties file 
    9893        if (!verifyProperties(propertiesFile)) { 
    9994            System.exit(0); 
    10095        } 
    101  
     96        // create the highways model 
    10297        highways = new Highways( 
    10398                ATMSDriverProperties.getProperty( 
     
    110105                Integer.parseInt(ATMSDriverProperties.getProperty( 
    111106                                PROPERTIES.FEP_WRITER_PORT.name))); 
    112          
     107        // create the exchange reader 
    113108        exchangeReader = new ExchangeReader(); 
    114109    } 
    115  
     110     
     111    /** 
     112     * Verifies that the properties file has all necessary properties. 
     113     *  
     114     * @param propertiesFile 
     115     * @return  
     116     */ 
    116117    private boolean verifyProperties(String propertiesFile) { 
    117118        // Load the properties file. 
     
    133134        try { 
    134135            if (System.getProperty("ATMSDRIVER_PROPERTIES") != null) { 
    135                 new Thread(new ATMSDriver(System.getProperty( 
    136                         "ATMSDRIVER_PROPERTIES"))).start(); 
     136                // Create and run the ATMSDriver thread 
     137                ATMSDriver atmsDriver = new ATMSDriver(System.getProperty("ATMSDRIVER_PROPERTIES")); 
     138                Thread ATMSDriverThread = new Thread(atmsDriver); 
     139                ATMSDriverThread.start(); 
     140                 
     141                // run the console driver, pass it the atmsDriver highways model 
     142                ConsoleDriver driver = new ConsoleDriver(atmsDriver.highways); 
     143                 
    137144            } else { 
    138145                throw new Exception("ATMSDRIVER_PROPERTIES system property not defined."); 
  • trunk/src/atmsdriver/ConsoleDriver.java

    r97 r103  
    11package atmsdriver; 
    22 
     3import atmsdriver.model.Highways; 
     4import atmsdriver.model.Station.DIRECTION; 
     5import atmsdriver.model.Highway; 
     6import atmsdriver.model.Station; 
     7import java.util.ArrayList; 
     8import java.util.Arrays; 
     9import java.util.List; 
     10import java.util.Scanner; 
     11 
    312/** 
    4  *  A console application to drive the ATMS Server. 
    5  * @author jdalbey 
     13 * A console application to drive the ATMS Server. 
     14 * 
     15 * @author jdalbey, John A. Torres 
     16 * @version 10/11/2017 
    617 */ 
    7 public class ConsoleDriver 
    8 { 
    9 // 
    10 //Given 
    11 // <Highway Number> <Dir> <Postmile> <Range> <DotColor>  
    12 // 
    13 //IF default direction of Highway Number = Dir THEN 
    14 //    Set StartPost = Postmile 
    15 //    Set EndPost = Postmile + Range 
    16 //ELSE 
    17 //    Set StartPost = Postmile - Range 
    18 //    Set EndPost = Postmile 
    19 //END IF 
    20 // 
    21 //FOR each Station in Highway Number LOOP 
    22 // 
    23 //    IF Station.Postmile within range of StartPost:EndPost THEN 
    24 //        IF default direction of Highway Number = Dir THEN 
    25 //            Set ML color to DotColor 
    26 //        ELSE 
    27 //            Set OPP color to DotColor 
    28 //        END IF 
    29 //    END IF 
    30 // 
    31 //END LOOP 
    32 // 
    33 //     
     18public final class ConsoleDriver { 
     19    // highways model 
     20    private final Highways highways; 
     21     
     22    // lists used for user input validation 
     23    private final List<Integer> routeNumInputList; 
     24    private final List<String> dotColorInputList; 
     25 
     26    /** 
     27     * Constructor. Sets the highways model and generates the input validation 
     28     * lists, and then runs the console driver application. 
     29     * @param highways  
     30     */ 
     31    public ConsoleDriver(Highways highways) { 
     32        // set highways model 
     33        this.highways = highways; 
     34         
     35        // set input validation lists 
     36        routeNumInputList = generateRouteNumInputList(); 
     37        dotColorInputList = new ArrayList<>(Arrays.asList("R", "Y", "G")); 
     38         
     39        // run the console driver 
     40        runConsole(); 
     41    } 
     42     
     43    /** 
     44     * Generates the route number list, used for user input validation. 
     45     * @return list of route numbers. 
     46     */ 
     47    private ArrayList<Integer> generateRouteNumInputList() 
     48    { 
     49        ArrayList<Integer> routeNums = new ArrayList<>(); 
     50        // add the route number for each highway to the list 
     51        for(Highway hwy : highways.highways) 
     52        { 
     53            routeNums.add(hwy.routeNumber); 
     54        } 
     55        return routeNums; 
     56    } 
     57 
     58    /** 
     59     * Runs the console driver application. 
     60     */ 
     61    public void runConsole() { 
     62        Scanner sc = new Scanner(System.in); 
     63        // Run continuously 
     64        while (true) { 
     65            // Get necessary values for colorization of highways 
     66            Integer routeNumber = getRouteNumber(sc); 
     67            DIRECTION direction = getDirection(sc, routeNumber); 
     68            Double postmile = getPostmile(sc, routeNumber, direction); 
     69            Integer range = getRange(sc, postmile); 
     70            DOTCOLOR dotcolor = getDotColor(sc); 
     71             
     72            // apply colorization to highways 
     73            applyColorToHighwayStretch(routeNumber, direction, postmile, range, dotcolor); 
     74        } 
     75    } 
     76     
     77    /** 
     78     * Applies specified color to the specified highway stretch. Route number and 
     79     * direction specify the highway. Postmile and range specify the stretch of 
     80     * specified highway. Dot color is the color to be applied to the stretch. 
     81     *  
     82     * @param routeNumber highway route number 
     83     * @param direction highway direction 
     84     * @param postmile origin postmile value 
     85     * @param range range from origin postmile 
     86     * @param dotColor the color to be applied to specified highway stretch 
     87     */ 
     88    private void applyColorToHighwayStretch(Integer routeNumber, DIRECTION direction,  
     89            Double postmile, Integer range, DOTCOLOR dotColor) { 
     90        System.out.println("Applying " + dotColor.name() + " dots to highway "  
     91                + routeNumber + " " + direction.name() + " at postmile "  
     92                + postmile + " with a range of " + range + " miles..."); 
     93         
     94        // Get the highway by route number 
     95        Highway highway = highways.getHighwayByRouteNumber(routeNumber); 
     96         
     97        // start value for highway section, and end value for highway section 
     98        // by postmile 
     99        Double startPost; 
     100        Double endPost; 
     101         
     102        // postmiles increase from s to n and w to e 
     103         
     104        // if the direction is south or west 
     105        if(direction.equals(DIRECTION.SOUTH) || direction.equals(DIRECTION.WEST)) 
     106        { 
     107            // add range value to startPost to get 
     108            // the end postmile value of the highway section 
     109            startPost = postmile; 
     110            endPost = postmile + range; 
     111             
     112            // iterate through the stations, if within the specified highway 
     113            // stretch, update the station by direction and apply dot color 
     114            for(Station station : highway.stations) 
     115            { 
     116                if(station.postmile > startPost && station.postmile < endPost) 
     117                { 
     118                    station.updateByDirection(direction, dotColor); 
     119                } 
     120            } 
     121        } 
     122        // if the direction is north or east  
     123        else 
     124        { 
     125            //subtract range value from startPost 
     126            // to get the end postmile value of the highway section 
     127            startPost = postmile; 
     128            endPost = postmile - range; 
     129             
     130            // iterate through the stations, if within the specified highway 
     131            // section, update the station by direction and apply dot color 
     132            for(Station station : highway.stations) 
     133            { 
     134                if(station.postmile < startPost && station.postmile > endPost) 
     135                { 
     136                    station.updateByDirection(direction, dotColor); 
     137                } 
     138            } 
     139        } 
     140        System.out.println(""); 
     141    } 
     142     
     143    /** 
     144     * Gets the highway route number from user and validates the input. 
     145     *  
     146     * @param sc stdIn scanner 
     147     * @return highway route number 
     148     */ 
     149    private Integer getRouteNumber(Scanner sc) { 
     150        Integer routeNum = null; 
     151        Boolean verified = false; 
     152         
     153        // validation loop 
     154        while(!verified) 
     155        { 
     156            // Prints out available route numbers to user to select from 
     157            System.out.print("Available route numbers: ["); 
     158            for(Integer rtNum : routeNumInputList) 
     159            { 
     160                System.out.print(rtNum.toString() + ", "); 
     161            } 
     162            System.out.print("]"); 
     163            System.out.println(""); 
     164             
     165            // Prompt user to input a route number 
     166            System.out.println("Enter a route number: "); 
     167            routeNum = sc.nextInt(); 
     168            System.out.println(""); 
     169             
     170            // validate the user's input 
     171            if(routeNumInputList.contains(routeNum)) 
     172            { 
     173                verified = true; 
     174            } 
     175            else 
     176            { 
     177                System.out.println("Invalid route number, please re-enter: "); 
     178            } 
     179        } 
     180         
     181        return routeNum; 
     182    } 
     183     
     184    /** 
     185     * Gets the highway direction from the user and validates the input. 
     186     *  
     187     * @param sc stdIn scanner 
     188     * @return highway direction 
     189     */ 
     190    private DIRECTION getDirection(Scanner sc, Integer routeNum) { 
     191        DIRECTION direction; 
     192        String directionInput = null; 
     193        Boolean verified = false; 
     194         
     195        // validation loop 
     196        while(!verified) 
     197        { 
     198            // Get available directions for route 
     199            ArrayList<DIRECTION> availDirs = new ArrayList<>(); 
     200            for(Station stn : highways.getHighwayByRouteNumber(routeNum).stations) 
     201            { 
     202                if(!availDirs.contains(stn.direction)) 
     203                { 
     204                    availDirs.add(stn.direction); 
     205                } 
     206            } 
     207             
     208            // prompt user for input 
     209            System.out.print("Available directions for highway " + routeNum + ": ["); 
     210            for(DIRECTION dir : availDirs) 
     211            { 
     212                System.out.print(dir.getLetter() + ", "); 
     213            } 
     214            System.out.print("]"); 
     215            System.out.println(""); 
     216            System.out.println("Enter a direction:"); 
     217            directionInput = sc.next(); 
     218            System.out.println(""); 
     219             
     220            // validate the user's input 
     221            if(availDirs.contains(DIRECTION.toDirection(directionInput))) 
     222            { 
     223                verified = true; 
     224            } 
     225            else 
     226            { 
     227                System.out.println("Invalid direction, please re-enter: "); 
     228            } 
     229        } 
     230         
     231        return DIRECTION.toDirection(directionInput); 
     232    } 
     233     
     234    /** 
     235     * Gets the starting/origin postmile value for the highway section from the  
     236     * user and validates the input. 
     237     *  
     238     * @param sc stdIn scanner 
     239     * @param routeNumber highway route number 
     240     * @param dir highway direction 
     241     * @return highway section start/origin postmile value 
     242     */ 
     243    private Double getPostmile(Scanner sc, Integer routeNumber, DIRECTION dir) { 
     244        Double postmile = null; 
     245        Boolean verified = false; 
     246         
     247        // validation loop 
     248        while(!verified) 
     249        { 
     250            // Get highway, and grab the floor and ceiling for postmile values 
     251            // from the highway stations to present to the user 
     252            Highway hwy = highways.getHighwayByRouteNumber(routeNumber); 
     253            Double floorPostmile = hwy.stations.get(0).postmile; 
     254            Double ceilPostmile = hwy.stations 
     255                    .get(hwy.stations.size() - 1).postmile; 
     256             
     257            // present user with range of postmiles for given highway 
     258            System.out.println("Route " + hwy.routeNumber + " " + dir  
     259                    + " postmile range: [" + floorPostmile + ", "  
     260                    + ceilPostmile + "]"); 
     261             
     262            // prompt user for postmile value 
     263            System.out.println("Enter a postmile value (Integer/Double): "); 
     264            postmile = sc.nextDouble(); 
     265            System.out.println(""); 
     266             
     267            // validate user's input, ensures that the postmile is within given 
     268            // postmile range (floorPostmile, ceilPostmile) 
     269            if(postmile >= floorPostmile && postmile <= ceilPostmile) 
     270            { 
     271                verified = true; 
     272            } 
     273            else 
     274            { 
     275                System.out.println("Postmile must be within postmile range: [" + floorPostmile + ", "  
     276                    + ceilPostmile + "] please re-enter: "); 
     277            } 
     278        } 
     279         
     280        return postmile; 
     281    } 
     282     
     283    /** 
     284     * Gets the range to extend the highway stretch from the start/origin postmile 
     285     * value from the user and validates the input. 
     286     *  
     287     * @param sc stdIn scanner 
     288     * @param postmile origin/start postmile value for highway stretch 
     289     * @return range value 
     290     */ 
     291    private Integer getRange(Scanner sc, Double postmile) { 
     292        Integer range = null; 
     293        Boolean verified = false; 
     294         
     295        // validation loop 
     296        while(!verified) 
     297        { 
     298            // prompt user for range value 
     299            System.out.println("Enter a range value (Integer):"); 
     300            range = sc.nextInt(); 
     301            System.out.println(""); 
     302             
     303            // range must be greater than or equal to 0 
     304            if(range >= 0) 
     305            { 
     306                verified = true; 
     307            } 
     308            else 
     309            { 
     310                System.out.println("Range must be >= 0"); 
     311            } 
     312        } 
     313         
     314        return range; 
     315    } 
     316 
     317    /** 
     318     * Gets the dot color from the user, to be applied to specified highway 
     319     * stretch and validates the user's input. 
     320     *  
     321     * @param sc stdIn scanner 
     322     * @return dot color to be applied to highway stretch 
     323     */ 
     324    private DOTCOLOR getDotColor(Scanner sc) { 
     325        DOTCOLOR dotColor; 
     326        String dotColorInput = null; 
     327        Boolean verified = false; 
     328         
     329        // validationloop 
     330        while(!verified) 
     331        { 
     332            // prompt user for color 
     333            System.out.println("Enter a dot color (G/Y/R):"); 
     334            dotColorInput = sc.next(); 
     335            System.out.println(""); 
     336            // validate user's input 
     337            if(dotColorInputList.contains(dotColorInput)) 
     338            { 
     339                verified = true; 
     340            } 
     341            else 
     342            { 
     343                System.out.println("Invalid dot color, please re-enter: "); 
     344            } 
     345        } 
     346         
     347        return DOTCOLOR.toDotColor(dotColorInput); 
     348    } 
     349     
     350    /** 
     351     * Enum for highway status dot colors. 
     352     * 
     353     * @author John A. Torres 
     354     * @version 10/11/2017 
     355     */ 
     356    public static enum DOTCOLOR { 
     357 
     358        RED, 
     359        YELLOW, 
     360        GREEN; 
     361         
     362        // All the first letters of the values, in order. 
     363        private static String allLetters = "RYG"; 
     364         
     365        /** 
     366         * Return the first letter of this enum. 
     367         * 
     368         * @return String first letter of this enum. 
     369         */ 
     370        public String getLetter() { 
     371            return this.toString().substring(0, 1); 
     372        } 
     373 
     374        /** 
     375         * Returns a dot color given its first character. 
     376         * 
     377         * @param letter the first character of a dot color 
     378         * @return dot color corresponding to letter 
     379         * @pre letter must be one of allLetters 
     380         */ 
     381        public static DOTCOLOR toDotColor(String letter) { 
     382            return values()[allLetters.indexOf(letter.charAt(0))]; 
     383        } 
     384    }   
    34385} 
  • trunk/src/atmsdriver/FEPLineLoader.java

    r90 r103  
    1313import java.util.logging.Logger; 
    1414 
    15 /** The NetworkReader loads all static data for the traffic network through 
    16  *  network lookup files.  
     15/** The FEPLineLoader loads all static data for the FEPLines, using the station 
     16 *  and loop lookup files. 
     17 *  
     18 *  THIS CLASS WILL BE REMOVED AND THE LOADING OF FEPLINES WILL BE THE RESPONSIBILITY 
     19 *  OF THE HIGHWAYS.JAVA CLASS FOR PROPER OOP. JUST USING FOR NOW BECAUSE IT WORKS. 
    1720 *  
    1821 *  The public method getFEPLines() method can be used to get all the FEPLines  
    19   within a network. All other methods are private and are used to construct 
    20   the FEPLines. 
    21   
    22   The "LDSFile" contains Station and FEPLine information. 
    23   ex. 
    24    < Insert file here > 
    25  *  The "loopFile" contains individual LoopDetector information. 
    26  *  ex. 
    27  *   < Insert file here >  
     22 *  within the network. All other methods are private and are used to construct 
     23 *  the FEPLines. 
    2824 * 
    2925 * @author John A. Torres 
    3026 * @version 09/10/2017 
    3127 */ 
    32 public class NetworkLoader { 
     28public class FEPLineLoader { 
    3329    // Two network config files 
    3430    private final File LDSFile; 
     
    4339     * @param loopFile contains individual LoopDetector static data 
    4440     */ 
    45     public NetworkLoader(File LDSFile, File loopFile) 
     41    public FEPLineLoader(File LDSFile, File loopFile) 
    4642    { 
    4743        this.LDSFile = LDSFile; 
     
    176172            } 
    177173        } catch (FileNotFoundException ex) { 
    178             Logger.getLogger(NetworkLoader.class.getName()).log(Level.SEVERE, null, ex); 
     174            Logger.getLogger(FEPLineLoader.class.getName()).log(Level.SEVERE, null, ex); 
    179175        } 
    180176    } 
  • trunk/src/atmsdriver/model/FEPLine.java

    r88 r103  
    44import org.w3c.dom.Document; 
    55import org.w3c.dom.Element; 
    6  
    7  
    86 
    97/** An FEPLine is a simulated line of communication from the FEP to  
     
    1816public class FEPLine { 
    1917    /* Static FEPLine meta data */ 
    20     final private int lineNum; 
    21     final private List<Station> stations; 
     18    final public int lineNum; 
     19    final public List<Station> stations; 
    2220    final private int count; 
    23     // NOT SURE IF NEXT IS FINAL 
     21     
    2422    final private int schedule; 
    2523    final private int lineInfo; 
    2624    final private long systemKey; 
     25     
     26    // THESE WILL NEED TO BE UPDATED MAYBE, NOT SURE, NOT A PRIORITY. SEE METHOD 
     27    // UPDATESEQUENCES() 
    2728    private long globalSeq; 
    2829    private long scheduleSeq; 
     
    4041        this.globalSeq = globalSeq; 
    4142        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; 
    5243    } 
    5344     
  • trunk/src/atmsdriver/model/Highway.java

    r93 r103  
    1010 * @author jdalbey 
    1111 */ 
    12 final class Highway 
     12final public class Highway 
    1313{ 
    1414    /** The identifying number for this highway, e.g., 101 */ 
    15     public final Integer highwayNumber; 
     15    public final Integer routeNumber; 
    1616    /** The ordered list of stations (lane detector stations) on this highway */ 
    1717    public final ArrayList<Station> stations; 
     
    2222     * @param stations ordered list of stations on this highway 
    2323     */ 
    24     public Highway(Integer highwayNum, ArrayList<Station> stations) 
     24    public Highway(Integer routeNumber, ArrayList<Station> stations) 
    2525    { 
    26         this.highwayNumber = highwayNum; 
     26        this.routeNumber = routeNumber; 
    2727        this.stations = stations; 
    2828    } 
  • trunk/src/atmsdriver/model/Highways.java

    r101 r103  
    11package atmsdriver.model; 
    22 
    3 import atmsdriver.NetworkLoader; 
    4 import atmsdriver.model.Station.DIRECTION; 
     3import atmsdriver.FEPLineLoader; 
    54import java.io.File; 
    6 import java.io.FileNotFoundException; 
    75import java.io.FileWriter; 
    86import java.io.IOException; 
     
    1311import java.util.ArrayList; 
    1412import java.util.Collections; 
    15 import java.util.Enumeration; 
    1613import java.util.HashMap; 
    17 import java.util.Hashtable; 
    18 import java.util.List; 
    1914import java.util.Map; 
    2015import java.util.Observable; 
    2116import java.util.Observer; 
    22 import java.util.Scanner; 
    2317import java.util.Set; 
    2418import java.util.logging.Level; 
     
    3428import org.w3c.dom.Element; 
    3529 
    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. 
    3744 * 
    3845 * @author John A. Torres 
    3946 */ 
    40 public class Highways implements Observer { 
     47public class Highways { 
    4148 
    4249    final private ArrayList<FEPLine> lines; 
    4350    final private String FEPHostName; 
    4451    final private int FEPPortNum; 
    45     final private ArrayList<Highway> highways; 
    46     private Map<Integer, List<Station>> HiwayMap = new HashMap<Integer, List<Station>>(); 
    4752     
    48     // NEED FINISH final private ArrayList<Highway> highways; 
     53    final public ArrayList<Highway> highways; 
     54     
    4955    public Highways(String ldsFileName, String loopsFileName, 
    5056            String highwayMetaFileName, String FEPHostName, int FEPPortNum) { 
     
    5460         */ 
    5561 
    56         NetworkLoader ldr = new NetworkLoader(new File(ldsFileName), new File(loopsFileName)); 
     62        FEPLineLoader ldr = new FEPLineLoader(new File(ldsFileName), new File(loopsFileName)); 
    5763        this.lines = (ArrayList<FEPLine>) ldr.getFEPLines(); 
    5864        this.FEPHostName = FEPHostName; 
     
    6167        //writeHighwaysMeta("hard.txt"); 
    6268    } 
    63  
    64     public ArrayList<Highway> getHighways() 
    65     { 
    66         return this.highways; 
    67     } 
    68      
    6969     
    7070    private ArrayList<Highway> loadHighways() { 
     
    7272        // The list of highways to return 
    7373        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<>(); 
    7677         
    7778        for (FEPLine line : lines) 
    7879        { 
    79             ArrayList<Station> lineStations = (ArrayList<Station>) line.getStations(); 
     80            ArrayList<Station> lineStations = (ArrayList<Station>) line.stations; 
    8081            for(Station station : lineStations) 
    8182            { 
    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)) 
    8786                { 
    8887                    ArrayList<Station> stnList = new ArrayList<>(); 
    8988                    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); 
    9490                } 
    9591                else 
    9692                { 
    97                     highwayTable.get(check).add(station); 
     93                    highwayMap.get(hwyNum).add(station); 
    9894                } 
    9995            } 
    10096        } 
    10197         
    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) 
    104100        { 
    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,  
    112105                    hwyStations)); 
    113106        } 
     107        System.out.println(""); 
    114108        return highways; 
    115109    } 
     110     
    116111    /* 
    117112     private ArrayList<FEPLine> loadLines(String highwayMetaFileName) { 
     
    215210 
    216211    public void writeToFEP() { 
    217                     System.out.println(this.toXML().toCharArray().length); 
    218  
    219212        try { 
    220213            Socket sock = new Socket(FEPHostName, FEPPortNum); 
     
    293286    } 
    294287 
    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; 
    298299    } 
    299300 
  • trunk/src/atmsdriver/model/LoopDetector.java

    r87 r103  
    1717{ 
    1818    /* static data */ 
    19     final private int loopID; 
    20     final private String loopLocation; 
    21     final private int laneNum; 
     19    final public int loopID; 
     20    final public String loopLocation; 
     21    final public int laneNum; 
    2222     
    2323    /* dynamic data */ 
  • trunk/src/atmsdriver/model/Station.java

    r94 r103  
    11package atmsdriver.model; 
    22 
     3import atmsdriver.ConsoleDriver; 
     4import atmsdriver.ConsoleDriver.DOTCOLOR; 
    35import java.util.List; 
    46import org.w3c.dom.Document; 
     
    2123 
    2224    /* Static Station meta data */ 
    23     final private int lineNum; 
    24     final private int ldsID; // double check 
    25     final private int drop; 
    26     final private String location; 
    27     final private List<LoopDetector> loops; 
    28     final private int highwayNum; 
    29     final private double postmile; 
    30     final private DIRECTION 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; 
    3133 
    3234    /* Dynamic Station data */ 
     
    4648        this.postmile = postmile; 
    4749        this.direction = direction; 
    48         this.highwayNum = hwy; 
     50        this.routeNumber = hwy; 
    4951 
    5052        this.MLTotVol = 0; 
    5153        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; 
    6254    } 
    6355 
     
    7668        build.append(Integer.toString(this.drop)); 
    7769        build.append(" "); 
    78         build.append(Integer.toString(this.highwayNum)); 
     70        build.append(Integer.toString(this.routeNumber)); 
    7971        build.append(" "); 
    8072        build.append(this.direction.getLetter()); 
     
    9183        } 
    9284        return build.toString(); 
    93     } 
    94  
    95     public double getPostmile() 
    96     { 
    97         return postmile; 
    9885    } 
    9986 
     
    117104 
    118105        // get difference of values 
    119         double otherStationPostmile = ((Station) otherStation).getPostmile(); 
     106        double otherStationPostmile = ((Station) otherStation).postmile; 
    120107        double val = this.postmile - otherStationPostmile; 
    121108 
     
    134121    } 
    135122 
     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     
    136168    private static enum XML_TAGS 
    137169    { 
     
    189221 
    190222        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))); 
    192224        stationElement.appendChild(freewayElement); 
    193225 
  • trunk/src/tmcsim/application.properties

    r101 r103  
    1 #Wed, 11 Oct 2017 17:25:07 -0700 
     1#Thu, 12 Oct 2017 01:19:36 -0700 
    22 
    3 Application.revision=97 
     3Application.revision=101 
    44 
    5 Application.buildnumber=50 
     5Application.buildnumber=51 
Note: See TracChangeset for help on using the changeset viewer.