Ejemplo n.º 1
0
    def setUpClass(cls):

        # make Java connection
        cls.connection = Java_Connection()

        # create a static/bpr model managers
        this_folder = os.path.dirname(
            os.path.abspath(inspect.getfile(inspect.currentframe())))
        configfile = os.path.join(this_folder, os.path.pardir, 'configfiles',
                                  'seven_links.xml')
        bpr_coefficients = {
            0L: [1, 0, 0, 0, 1],
            1L: [1, 0, 0, 0, 1],
            2L: [5, 0, 0, 0, 5],
            3L: [2, 0, 0, 0, 2],
            4L: [2, 0, 0, 0, 2],
            5L: [1, 0, 0, 0, 1],
            6L: [5, 0, 0, 0, 5]
        }
        cls.model_manager = Link_Model_Manager_class(configfile, "static",
                                                     cls.connection, None,
                                                     "bpr", bpr_coefficients)

        api = cls.model_manager.beats_api

        time_period = 1  # Only have one time period for static model
        paths_list = list(api.get_path_ids())
        commodity_list = list(api.get_commodity_ids())
        route_list = {}

        for path_id in paths_list:
            route_list[path_id] = api.get_subnetwork_with_id(
                path_id).get_link_ids()

        # Test used to validate the Demand_Assignment_Class
        # Creating the demand assignment for initialization
        cls.demand_assignments = Demand_Assignment_class(route_list,
                                                         commodity_list,
                                                         time_period,
                                                         dt=time_period)
        demands = {}
        demand_value = np.zeros(time_period)
        demand_value1 = np.zeros(time_period)
        demand_value[0] = 2
        demand_value1[0] = 2
        demands[(1L, 1L)] = demand_value
        demands[(2L, 1L)] = demand_value1
        demands[(3L, 1L)] = demand_value
        cls.demand_assignments.set_all_demands(demands)

        # create link states
        cls.link_states = cls.model_manager.traffic_model.Run_Model(
            cls.demand_assignments)
Ejemplo n.º 2
0
    def setUpClass(cls):
        cls.conn = Java_Connection()

        this_folder = os.path.dirname(
            os.path.abspath(inspect.getfile(inspect.currentframe())))
        configfile = os.path.join(this_folder, os.path.pardir, os.path.pardir,
                                  'configfiles', 'seven_links.xml')
        sim_dt = 2
        coefficients = {
            0L: [1, 0, 0, 0, 1],
            1L: [1, 0, 0, 0, 1],
            2L: [2, 0, 0, 0, 2],
            3L: [1, 0, 0, 0, 1],
            4L: [2, 0, 0, 0, 2],
            5L: [1, 0, 0, 0, 1],
            6L: [1, 0, 0, 0, 1]
        }

        cls.model_manager = Link_Model_Manager_class(configfile, "mn",
                                                     cls.conn.gateway, sim_dt,
                                                     "bpr", coefficients)
Ejemplo n.º 3
0
    def setUpClass(cls):

        # make Java connection
        cls.connection = Java_Connection()

        # create a static/bpr model manager
        this_folder = os.path.dirname(
            os.path.abspath(inspect.getfile(inspect.currentframe())))
        configfile = os.path.join(this_folder, os.path.pardir, 'configfiles',
                                  'seven_links.xml')
        bpr_coefficients = {
            0L: [1, 0, 0, 0, 1],
            1L: [1, 0, 0, 0, 1],
            2L: [5, 0, 0, 0, 5],
            3L: [2, 0, 0, 0, 2],
            4L: [2, 0, 0, 0, 2],
            5L: [1, 0, 0, 0, 1],
            6L: [5, 0, 0, 0, 5]
        }
        cls.model_manager = Link_Model_Manager_class(configfile, "static",
                                                     cls.connection, None,
                                                     "bpr", bpr_coefficients)
Ejemplo n.º 4
0
if connection.pid is not None:

    # Contains local path to input configfile, for the three_links.xml network
    this_folder = os.path.dirname(
        os.path.abspath(inspect.getfile(inspect.currentframe())))
    configfile = os.path.join(this_folder, os.path.pardir, 'configfiles',
                              'seven_links.xml')

    coefficients = {}
    T = 1800  # Time horizon of interest
    sim_dt = 0.0  # Duration of one time_step for the traffic model

    sampling_dt = 300  # Duration of time_step for the solver, in this case it is equal to sim_dt

    model_manager = Link_Model_Manager_class(configfile, "static",
                                             connection.gateway, sim_dt, "bpr",
                                             coefficients)

    #Estimating bpr coefficients with beats
    num_links = model_manager.otm_api.scenario().get_num_links()
    avg_travel_time = np.zeros(num_links)

    num_coeff = 5

    for i in range(num_links):
        link_info = model_manager.otm_api.scenario().get_link_with_id(long(i))
        fft = (link_info.getFull_length() / 1000 / link_info.get_ffspeed_kph())
        coefficients[long(i)] = np.zeros(num_coeff)
        coefficients[i][0] = copy(fft)
        coefficients[i][4] = copy(fft * 0.15)