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


Ignore:
Timestamp:
03/23/2019 05:40:52 PM (7 years ago)
Author:
jdalbey
Message:

Fix defect #117. Update HighwaysTest?.java for new highway model.

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

Legend:

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

    r237 r343  
    33import atmsdriver.model.Station.DIRECTION; 
    44import java.util.ArrayList; 
     5import java.util.HashSet; 
    56import java.util.List; 
     7import java.util.Set; 
     8import java.util.SortedSet; 
     9import java.util.TreeSet; 
    610 
    711/** 
     
    1822    /** The ordered list of stations (lane detector stations) on this highway */ 
    1923    public final List<Station> stations; 
    20          
     24    /** The directions for this highway, either N/S or E/W */ 
     25    public final Set<DIRECTION> availDirs = new TreeSet<DIRECTION>(); 
     26     
    2127    /** Construct a highway  
    2228     *  
     
    2834        this.routeNumber = routeNumber; 
    2935        this.stations = stations; 
    30     } 
    31      
    32     /** 
    33      *  
    34      */ 
    35     public List<DIRECTION> getDirections() 
    36     { 
    37                     // Get available directions for route 
    38             ArrayList<DIRECTION> availDirs = new ArrayList<>(); 
     36        // Get available directions for route 
     37        if (stations != null) 
     38        { 
    3939            for(Station stn : stations) 
    4040            { 
    41                 if(!availDirs.contains(stn.direction)) 
    42                 { 
    43                     availDirs.add(stn.direction); 
    44                 } 
     41                availDirs.add(stn.direction); 
    4542            } 
    46             return availDirs; 
     43        } 
    4744    } 
    4845     
  • trunk/src/atmsdriver/model/Highways.java

    r306 r343  
    4343 * FEP Simulator. 
    4444 * 
    45  * Currently, there is no driving logic within the highways class. It is only 
    46  * done through an instance of the ConsoleDriver.java class. Eventually, it will 
    47  * receive incident data (from exchange.xml or better yet, directly from the 
    48  * TMCSimulator itself) and drive the highways using resident logic. 
    4945 * 
    5046 * @author John A. Torres 
     
    124120    } 
    125121 
     122    /** Search for a station with the given attributes  
     123     *  
     124     * @param routeNumber 
     125     * @param direction 
     126     * @param postmile 
     127     * @return the desired station, or null if not found. 
     128     */ 
     129    public Station findStation(Integer routeNumber, Station.DIRECTION direction, 
     130            Double postmile) 
     131    { 
     132        // Get the highway by route number 
     133        Highway highway = getHighwayByRouteNumber(routeNumber); 
     134        if (highway == null) 
     135        { 
     136            Logger.getLogger(Highways.class.getName()).log(Level.SEVERE,   
     137                    "Highway "+routeNumber+" not found in findStation()", ""); 
     138            return null; 
     139        } 
     140        //Search the stations on this highway for a match 
     141        for (Station station : highway.stations) 
     142        { 
     143            if (station.matches(direction, postmile)) 
     144            { 
     145                return station; 
     146            } 
     147        } 
     148        return null; 
     149    } 
    126150    /** 
    127151     * Applies specified color to the specified highway stretch. Route number 
     
    158182        // postmiles increase from s to n and w to e 
    159183        // if the direction is south or west 
    160         if (direction.equals(Station.DIRECTION.SOUTH) || direction.equals(Station.DIRECTION.WEST)) 
     184        if (direction.equals(Station.DIRECTION.NORTH) || direction.equals(Station.DIRECTION.EAST)) 
    161185        { 
    162186            // add range value to startPost to get 
     
    440464    /** 
    441465     * Returns the Highways model data in XML format. 
    442      *  
     466     * Probably obsolete, since we aren't using exchange.xml any longer. 
    443467     * @return highways data in XML format 
    444468     */ 
     
    507531        { 
    508532            // Consider each route direction 
    509             for (DIRECTION dir: DIRECTION.values()) 
     533            for (DIRECTION dir: hwy.availDirs) 
    510534            { 
    511535                String rowLabel = ""+String.format("%3s ",hwy.routeNumber)+dir.getLetter()+' '; 
     
    514538                for (Station stat: hwy.stations) 
    515539                { 
     540                    if (stat.direction.equals(dir)) 
     541                    { 
    516542                    //lineout.append("" + dir.getLetter() + stat.postmile); 
    517543                    lineout.append(stat.getColor()); 
    518544                    //lineout.append("  "); 
     545                    } 
     546                    else  
     547                    { 
     548                        lineout.append("."); 
     549                    } 
    519550                } 
    520551                // See if there were stations for this direction 
  • trunk/src/atmsdriver/model/LoopDetector.java

    r242 r343  
    9494        { 
    9595            build.append(this.loopLocationID); 
     96            build.append(" "); 
    9697        } 
    9798        build.append(this.loopLocation); 
  • trunk/src/atmsdriver/model/Station.java

    r285 r343  
    88 
    99/** 
    10  * A Station (LDS or Loop Detector Station) represents a group of lane detectors 
    11  * across all lanes at a particular point on a highway. A station is identified 
     10 * A Station (VDS or Vehicle Detector Station) represents a group of lane detectors 
     11 * across all lanes in one direction at a particular point on a highway. A station is identified 
    1212 * by its highway number and postmile. A station has an associated direction 
    1313 * used to establish which direction is Main and which is Opposite. The MLTotVol 
    1414 * and OppTotVol for a station can be dynamically updated. A station has other 
    15  * attributes: lineNum, ldsID, drop, and location which are used by the FEP. A 
     15 * attributes: lineNum, vdsID, drop, and location which are used by the FEP. A 
    1616 * station can be compared to other stations by its postmile. 
    1717 * 
    18  * @author John A. Torres 
    19  * @version 9/10/2017 
     18 * @author John A. Torres, jdalbey 
     19 * @version 9/10/2017, 3/22/2019 
    2020 */ 
    21 public class Station implements Comparable 
     21public final class Station implements Comparable 
    2222{ 
    2323 
    2424    /* Static Station meta data */ 
    2525    final public int lineID; 
    26     final public int ldsID; // double check 
     26    final public int vdsID; // double check 
    2727    final public int drop; 
    2828    final public String location; 
     
    3737 
    3838    /* Constructor */ 
    39     public Station(int lineID, int ldsID, int drop, 
     39    public Station(int lineID, int vdsID, int drop, 
    4040            String location, List<LoopDetector> loops, int hwy, 
    4141            DIRECTION direction, double postmile) 
    4242    { 
    4343        this.lineID = lineID; 
    44         this.ldsID = ldsID; 
     44        this.vdsID = vdsID; 
    4545        this.drop = drop; 
    4646        this.loops = loops; 
     
    109109    { 
    110110        StringBuilder build = new StringBuilder(); 
    111         build.append(Integer.toString(this.ldsID)); 
     111        build.append(Integer.toString(this.vdsID)); 
    112112        build.append(" "); 
    113113        build.append(Integer.toString(this.drop)); 
     
    170170 
    171171    /** 
     172     * See if this station matches the specified attributes. 
     173     * @param dir 
     174     * @param postmile 
     175     * @return true if this station's attributes match the given ones. 
     176     */ 
     177    public boolean matches(DIRECTION dir, double postmile) 
     178    { 
     179        double val = this.postmile - postmile; 
     180        return (Math.abs(val) < 0.01) && this.direction.equals(dir); 
     181    } 
     182    /** 
    172183     * Determine which lane fields to update based on given direction and update 
    173184     * all the loop detectors with the given color. 
     
    178189    public void updateByDirection(DIRECTION direction, DOTCOLOR dotColor) 
    179190    { 
    180         String laneDir = "OS"; 
     191        // Is this station going in the desired direction? 
    181192        if (direction.equals(this.direction)) 
    182193        { 
    183             laneDir = "ML"; 
    184         } 
    185         outputUpdateMessage(dotColor, laneDir); 
    186  
    187         for (LoopDetector loop : loops) 
    188         { 
    189             // THIS DECISION ISN'T NEEDED after JD's BuildHighwayFile pgm 
    190             // creates a highway map based on VDS instead of Controller (LDS). 
    191 //            if (loop.loopLocation.startsWith(laneDir)) 
    192 //            { 
    193                 // UPDATE LOOP WITH VALUES 
    194                 loop.updateLoop(dotColor.volume(), dotColor.occupancy()); 
    195 //            } 
    196         } 
    197  
    198         this.MLTotVol = getMLTotVol(); 
    199         this.OppTotVol = getOPPTotVol(); 
    200     } 
    201      
     194            outputUpdateMessage(dotColor, direction.toString()); 
     195 
     196            for (LoopDetector loop : loops) 
     197            { 
     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    //            } 
     205            } 
     206 
     207            this.MLTotVol = getMLTotVol(); 
     208            this.OppTotVol = getOPPTotVol(); 
     209        } 
     210    } 
    202211    /** 
    203212     * Return the color for the lanes in a given direction. 
     
    316325 
    317326        Element ldsIDElement = theDoc.createElement(XML_TAGS.LDS_ID.tag); 
    318         ldsIDElement.appendChild(theDoc.createTextNode(String.valueOf(this.ldsID))); 
     327        ldsIDElement.appendChild(theDoc.createTextNode(String.valueOf(this.vdsID))); 
    319328        stationElement.appendChild(ldsIDElement); 
    320329 
     
    422431    public String toString() 
    423432    { 
    424         return Integer.toString(this.ldsID); 
     433        return Integer.toString(this.vdsID)+this.getColor(); 
    425434    } 
    426435} 
Note: See TracChangeset for help on using the changeset viewer.