Package eas.users.ocScenarios.traffic

Source Code of eas.users.ocScenarios.traffic.TrafficParameters

/*
* File name:        Parameters.java (package eas.users.ocScenario.cars)
* Author(s):        Lukas König
* Java version:     7.0
* Generation date:  20.05.2014 (15:23:37)
*
* (c) This file and the EAS (Easy Agent Simulation) framework containing it
* is protected by Creative Commons by-nc-sa license. Any altered or
* further developed versions of this file have to meet the agreements
* stated by the license conditions.
*
* In a nutshell
* -------------
* You are free:
* - to Share -- to copy, distribute and transmit the work
* - to Remix -- to adapt the work
*
* Under the following conditions:
* - Attribution -- You must attribute the work in the manner specified by the
*   author or licensor (but not in any way that suggests that they endorse
*   you or your use of the work).
* - Noncommercial -- You may not use this work for commercial purposes.
* - Share Alike -- If you alter, transform, or build upon this work, you may
*   distribute the resulting work only under the same or a similar license to
*   this one.
*
* + Detailed license conditions (Germany):
*   http://creativecommons.org/licenses/by-nc-sa/3.0/de/
* + Detailed license conditions (unported):
*   http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en
*
* This header must be placed in the beginning of any version of this file.
*/

package eas.users.ocScenarios.traffic;

import java.util.LinkedList;
import java.util.List;

import eas.startSetup.SingleParameter;
import eas.startSetup.parameterDatatypes.Datatypes;
import eas.users.ocScenarios.traffic.strategies.StrategyFactory;

/**
* The program parameters of the cars environment. Cf. example description
* below regarding the functioning of program parameters.
*
* @author Lukas König
*/
public class TrafficParameters {
   
    /*
     * The program parameters connected to the parameter collection.
     * They represent at any time during simulation the correct parameter
     * values stored in the parameter collection.
     */
    
    public static int numStreets = 0;
    public static int numCars = 0;
    public static boolean twoLanes = false;
    public static int carMaxSpeed = 0;
    public static int carMinSpeed = 0;
    public static boolean activateCollStrat = false;
    public static int proportionOfRoundabouts = 0;
    public static int numOfStoredTracePoints;
    public static int roundaboutRadius = 4;
    public static int lightsInterval = 75;
    public static String collisionStrategy = "";
    public static String drivingStrategy = "";
   
    /**
     * This field is set true any time a parameter changes. The environment
     * class reacts by resetting the simulation according to the changed
     * values.
     */
    public static boolean resetRequested = false;
   
    /*
     * Explicit definition of the names of the parameters (optional).
     */
   
    public static String NUM_CARS_PAR_NAME = "numCars";
    public static String NUM_STREETS_PAR_NAME = "numStreets";
    public static String TWO_LANES_PAR_NAME = "twoLanes";
    public static String CAR_MAX_SPEED_PAR_NAME = "carMaxSpeed";
    public static String CAR_MIN_SPEED_PAR_NAME = "carMinSpeed";
    public static String ACTIVATE_COLL_STRAT_PAR_NAME = "activateCollStrat";
    public static String PROPORTION_OF_ROUNDABOUTS_PAR_NAME = "proportionOfRoundabouts";
    public static String NUM_OF_STORED_TRACE_POINTS_PAR_NAME = "numOfStoredTracePoints";
    public static String ROUNDABOUT_RADIUS_PAR_NAME = "roundaboutRadius";
    public static String LIGHTS_INTERVAL_PAR_NAME = "lightsInterval";
   
    private static String CARS_PARAMETERS_CATEGORY_NAME = TrafficEnvironment.class.getSimpleName().toUpperCase();
   
    /**
     * Returns a list of program parameters retrieved by the cars scheduler to
     * be passed on to the parameter collection.
     *
     * @return  A list of program parameters for the cars scenario.
     */
    public static List<SingleParameter> getParameter() {
        LinkedList<SingleParameter> parsList = new LinkedList<>();
       
        /*
         * Simple definition of a program parameter without push service.
         * This parameter has to be updated by "pulling" it from the parameter
         * collection using *parCollection*.getParValue(...).
         */
        parsList.add(new SingleParameter(
                "GridFields",                                          // Parameter name.
                Datatypes.integerRange(0, 200),                        // Data type.
                100,                                                   // Standard value.
                "The width and height of the field.",                  // Description.
                CARS_PARAMETERS_CATEGORY_NAME)); // Category.
       
        /*
         * Better implementation of program parameters including push service.
         * Using this method, you do not have to get the parameter values from
         * the parameter collection (which is inefficient), but the fields
         * given in this class are set automatically to the correct values any
         * time a program parameter is changed.
         *
         * Consider this an example for a parameter connected to a listener class (this).
         * The class given as last parameter (CarsParameter.class in this case) has to
         * implement a static field with the same name as the parameter name (numCars
         * in this case) and, preferably, a static setter method (setNumCars(.) in
         * this case) to securely set the field. At program start and at any time
         * the respective parameter is set, the ParCollection calls the setter
         * method in "push" manner or, if the setter fails, sets the field directly.
         * This way of connecting a program parameter to a java field should be
         * preferred above checking parameters in "pull" manner using the getParValue...
         * methods of ParCollection as it is more efficient and secure.
         * (Both the setter and the field may be private if desired.)
         */
        parsList.add(new SingleParameter(
                NUM_CARS_PAR_NAME,                                   // Parameter name.
                Datatypes.integerRange(0, 2000),                     // Data type.
                100,                                                 // Standard value.
                "The number of cars.",                               // Description.
                CARS_PARAMETERS_CATEGORY_NAME,                       // Category.
                TrafficParameters.class));                           // NEW! Listener class connected to the parameter.
       
        parsList.add(new SingleParameter(
                NUM_STREETS_PAR_NAME,
                Datatypes.integerRange(1, 12),
                5,
                "The number of streets in each direction.",
                CARS_PARAMETERS_CATEGORY_NAME,
                TrafficParameters.class));
       
        parsList.add(new SingleParameter(
                CAR_MAX_SPEED_PAR_NAME,
                Datatypes.integerRange(0, 100),
                100,
                "The maximum speed any car can have as target speed.",
                CARS_PARAMETERS_CATEGORY_NAME,
                TrafficParameters.class));
       
        parsList.add(new SingleParameter(
                CAR_MIN_SPEED_PAR_NAME,
                Datatypes.integerRange(0, 100),
                100,
                "The minimum speed any car can have as target speed.",
                CARS_PARAMETERS_CATEGORY_NAME,
                TrafficParameters.class));
       
        parsList.add(new SingleParameter(
                TWO_LANES_PAR_NAME,
                Datatypes.BOOLEAN,
                true,
                "If every street has two directions (or else one).",
                CARS_PARAMETERS_CATEGORY_NAME,
                TrafficParameters.class));
       
        parsList.add(new SingleParameter(
                ACTIVATE_COLL_STRAT_PAR_NAME,
                Datatypes.BOOLEAN,
                true,
                "If the collision strategy is used (or else not).",
                CARS_PARAMETERS_CATEGORY_NAME,
                TrafficParameters.class));
       
        parsList.add(new SingleParameter(
                PROPORTION_OF_ROUNDABOUTS_PAR_NAME,
                Datatypes.integerRange(0, 100),
                50,
                "The percentage of roundabouts in relation to crossings.",
                CARS_PARAMETERS_CATEGORY_NAME,
                TrafficParameters.class));
       
        parsList.add(new SingleParameter(
                ROUNDABOUT_RADIUS_PAR_NAME,
                Datatypes.integerRange(2, 20),
                4,
                "The roundabout radius.",
                CARS_PARAMETERS_CATEGORY_NAME,
                TrafficParameters.class));
       
        parsList.add(new SingleParameter(
                NUM_OF_STORED_TRACE_POINTS_PAR_NAME,
                Datatypes.INTEGER,
                40,
                "The length of the trace displayed for each car.",
                CARS_PARAMETERS_CATEGORY_NAME,
                TrafficParameters.class));
       
        parsList.add(new SingleParameter(
                "collisionStrategy",
                Datatypes.fixedStringSet(StrategyFactory.getCollisionClassNames()),
                StrategyFactory.getCollisionClassNames()[0],
                "The collision strategy followed by the cars.",
                CARS_PARAMETERS_CATEGORY_NAME,
                TrafficParameters.class));
       
        parsList.add(new SingleParameter(
                "drivingStrategy",
                Datatypes.fixedStringSet(StrategyFactory.getDrivingClassNames()),
                StrategyFactory.getDrivingClassNames()[0],
                "The driving strategy followed by the cars.",
                CARS_PARAMETERS_CATEGORY_NAME,
                TrafficParameters.class));

        return parsList;
    }
   
    /*
     * Setters follow.
     */
   
    public static void setNumOfStoredTracePoints(int numOfStoredTracePoints) {
        TrafficParameters.numOfStoredTracePoints = numOfStoredTracePoints;
        resetRequested = true;
    }

    public static void setNumStreets(int numStreets) {
        TrafficParameters.numStreets = numStreets;
        resetRequested = true;
    }

    public static void setNumCars(int numCars) {
        TrafficParameters.numCars = numCars;
        resetRequested = true;
    }

    public static void setTwoLanes(boolean twoLanes) {
        TrafficParameters.twoLanes = twoLanes;
        resetRequested = true;
    }

    public static void setCarMaxSpeed(int carMaxSpeed) {
        TrafficParameters.carMaxSpeed = carMaxSpeed;
        resetRequested = true;
    }

    public static void setCarMinSpeed(int carMinSpeed) {
        TrafficParameters.carMinSpeed = carMinSpeed;
        resetRequested = true;
    }

    public static void setActivateCollStrat(boolean activateCollStrat) {
        TrafficParameters.activateCollStrat = activateCollStrat;
        resetRequested = true;
    }

    public static void setProportionOfRoundabouts(int proportionOfRoundabouts) {
        TrafficParameters.proportionOfRoundabouts = proportionOfRoundabouts;
        resetRequested = true;
    }

    public static void setRoundaboutRadius(int roundaboutRadius) {
        TrafficParameters.roundaboutRadius = roundaboutRadius;
        resetRequested = true;
    }
   
    public static void setLightsInterval(int lightsInterval) {
        TrafficParameters.lightsInterval = lightsInterval;
        resetRequested = true;
    }
   
    public static void setCollisionStrategy(String collisionStrategy) {
        TrafficParameters.collisionStrategy = collisionStrategy;
        resetRequested = true;
    }
   
    public static void setDrivingStrategy(String drivingStrategy) {
        TrafficParameters.drivingStrategy = drivingStrategy;
        resetRequested = true;
    }
}
TOP

Related Classes of eas.users.ocScenarios.traffic.TrafficParameters

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.