Changeset 180 in tmcsimulator for trunk/src/atmsdriver/model


Ignore:
Timestamp:
10/27/2017 01:38:13 PM (9 years ago)
Author:
jdalbey
Message:

ATMSDriver.java Refactored for cleaner design. DotColor? enum moved to LoopDetector? class. ConsoleDriver? renamed ConsoleTrafficDriver? (and associated project configurations updated), build.xml package-jars target updated, ConsoleTrafficDriver? logic improved to allow more user control, runtraffic.bash script created for automating traffic display tests.

Location:
trunk/src/atmsdriver/model
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/atmsdriver/model/Highways.java

    r176 r180  
    109109        return highways; 
    110110    } 
    111      
     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     *  
     116     * @param routeNumber highway route number 
     117     * @param direction highway direction 
     118     * @param postmile origin postmile value 
     119     * @param range range from origin postmile 
     120     * @param dotColor the color to be applied to specified highway stretch 
     121     */ 
     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 "  
     126                + postmile + " with a range of " + range + " miles..."); 
     127         
     128        // Get the highway by route number 
     129        Highway highway = getHighwayByRouteNumber(routeNumber); 
     130         
     131        // start value for highway section, and end value for highway section 
     132        // by postmile 
     133        Double startPost; 
     134        Double endPost; 
     135         
     136        // postmiles increase from s to n and w to e 
     137         
     138        // if the direction is south or west 
     139        if(direction.equals(Station.DIRECTION.SOUTH) || direction.equals(Station.DIRECTION.WEST)) 
     140        { 
     141            // add range value to startPost to get 
     142            // the end postmile value of the highway section 
     143            startPost = postmile; 
     144            endPost = postmile + range; 
     145             
     146            // iterate through the stations, if within the specified highway 
     147            // 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) 
     151                { 
     152                    station.updateByDirection(direction, dotColor); 
     153                } 
     154            } 
     155        } 
     156        // if the direction is north or east  
     157        else 
     158        { 
     159            //subtract range value from startPost 
     160            // to get the end postmile value of the highway section 
     161            startPost = postmile; 
     162            endPost = postmile - range; 
     163             
     164            // iterate through the stations, if within the specified highway 
     165            // 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) 
     169                { 
     170                    station.updateByDirection(direction, dotColor); 
     171                } 
     172            } 
     173        } 
     174        System.out.println(""); 
     175    } 
     176 
    112177    /* 
    113178     private ArrayList<FEPLine> loadLines(String highwayMetaFileName) { 
  • trunk/src/atmsdriver/model/LoopDetector.java

    r176 r180  
    121121        loopElement.appendChild(spdElement); 
    122122    } 
     123     
     124    /** 
     125     * Enum for highway status dot colors. Each color has associated volume 
     126     * and occupancy constants. 
     127     * 
     128     * @author John A. Torres, jdalbey 
     129     * @version 10/11/2017 
     130     */ 
     131    public static enum DOTCOLOR { 
     132 
     133        RED(1, 0.06f),    // "Stopped" is less than 25mph 
     134        YELLOW(3,0.059f), // speed = 26 
     135        GREEN(0,0); 
     136         
     137        // All the first letters of the values, in order. 
     138        public static String allLetters = "RYG"; 
     139         
     140        private int vol;  /* volume */ 
     141        private float occ;  /* occupancy */       
     142         
     143        private DOTCOLOR(int v, float o) 
     144        { 
     145            vol = v; 
     146            occ = o; 
     147        } 
     148        /** 
     149         * Return the first letter of this enum. 
     150         * 
     151         * @return String first letter of this enum. 
     152         */ 
     153        public String getLetter() { 
     154            return this.toString().substring(0, 1); 
     155        } 
     156 
     157        public int volume() 
     158        { 
     159            return vol; 
     160        } 
     161        public float occupancy() 
     162        { 
     163            return occ; 
     164        } 
     165        /** 
     166         * Returns a dot color given its first character. 
     167         * 
     168         * @param letter the first character of a dot color 
     169         * @return dot color corresponding to letter 
     170         * @pre letter must be one of allLetters 
     171         */ 
     172        public static DOTCOLOR toDotColor(String letter) { 
     173            return values()[allLetters.indexOf(letter.charAt(0))]; 
     174        } 
     175    }   
     176     
    123177} 
  • trunk/src/atmsdriver/model/Station.java

    r168 r180  
    11package atmsdriver.model; 
    22 
    3 import atmsdriver.ConsoleDriver; 
    4 import atmsdriver.ConsoleDriver.DOTCOLOR; 
     3import atmsdriver.ConsoleTrafficDriver; 
     4import atmsdriver.model.LoopDetector.DOTCOLOR; 
    55import java.util.List; 
    66import org.w3c.dom.Document; 
     
    174174    private void outputUpdateMessage(DOTCOLOR dotcolor, String OPP_ML) 
    175175    { 
    176         System.out.printf("Updating route %-3.3s %-5.5s %-3.3s lanes\t %-12.12s " 
     176        System.out.printf("Updating %-3.3s %-5.5s %-3.3s lanes\t %-12.12s " 
    177177                + "at postmile %-6.6s to %-7.7s\n",  
    178178                Integer.toString(this.routeNumber), this.direction.name(),  
Note: See TracChangeset for help on using the changeset viewer.