Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #5
0
import inspect
import csv
from Solvers.Path_Based_Frank_Wolfe_Solver import Path_Based_Frank_Wolfe_Solver

plt.rcParams.update({'font.size': 18})

connection = Java_Connection()
if connection.pid is not None:
    this_folder = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
    configfile = os.path.join(this_folder, os.path.pardir, 'configfiles', 'cfg_vi_mn.xml')
    coefficients = {}
    T = 3600  # Time horizon of interest
    sim_dt = 4.0  # Duration of one time_step for the traffic model

    sampling_dt = 4  # Duration of time_step for the solver, in this case it is equal to sim_dt
    model_manager = Link_Model_Manager_class(configfile, connection.gateway, "mn", sim_dt, "bpr", coefficients)

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

    num_coeff = 5

    for i in range(num_links):
        fft= (model_manager.beats_api.get_link_with_id(long(i)).getFull_length() \
          / model_manager.beats_api.get_link_with_id(long(i)).get_ffspeed_mps())/3600
        coefficients[long(i)] = np.zeros(num_coeff)
        coefficients[i][0] = copy(fft)
        coefficients[i][4] = copy(fft*0.15)
    route = {}
    route['1'] = [0, 3, 4, 5]
Пример #6
0
plt.rcParams.update({'font.size': 18})

connection = Java_Connection()
demand_range = [0, 2, 4, 6, 8, 10, 12, 14, 15, 16, 18, 20]
bpr_param = [0., 0.3, 0.4, 0.6, 0.8, 1.]
for b in bpr_param:
    for d in demand_range:
        if connection.pid is not None:
            this_folder = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
            configfile = this_folder +'\\configfiles\\cfg\\Total20\\cfg_vi_static_10.xml'
            coefficients = {}
            T = 90  # Time horizon of interest
            sim_dt = 90.0  # Duration of one time_step for the traffic model

            sampling_dt = 90  # Duration of time_step for the solver, in this case it is equal to sim_dt
            model_manager = Link_Model_Manager_class(configfile, connection.gateway, "static", sim_dt, "bpr", coefficients)
            model_manager.beats_api.set_stochastic_process('deterministic')
            #Estimating bpr coefficients with beats
            num_links = model_manager.beats_api.get_num_links()
            avg_travel_time = np.zeros(num_links)

            num_coeff = 5

            for i in range(num_links):
                fft= (model_manager.beats_api.get_link_with_id(long(i)).getFull_length() \
                  / model_manager.beats_api.get_link_with_id(long(i)).get_ffspeed_mps())
                coefficients[long(i)] = np.zeros(num_coeff)
                coefficients[i][0] = copy(fft)
                coefficients[i][4] = copy(fft*b)
            route = {}
            route['1'] = [0, 3, 4, 5]
Пример #7
0
    # File where to save the pickled objects
    this_folder = os.path.dirname(
        os.path.abspath(inspect.getfile(inspect.currentframe())))
    outputfile = os.path.join(this_folder, os.path.pardir, 'output',
                              scenario_name + '.pickle')

    coefficients = {}  #BPR Coefficients

    T = 3600  # Time horizon of interest
    sim_dt = 0.0  # Duration of one time_step for the traffic model

    sampling_dt = 600  # 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.get_num_links()
    avg_travel_time = np.zeros(num_links)

    num_coeff = 5

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