Example #1
0
def run():

    num_cats = read_num_cats_from_stdin()

    sim_mgr = SimulationManager(num_cats, 'data/tfl_stations.csv',
                                'data/tfl_connections.csv')
    sim_mgr.run_simulation()
Example #2
0
 def __init__(self):
     config_1 = SimulationManager.get_default_config()
     config_2 = SimulationManager.get_default_config()
     config_1['general']['obstacle_file']=demo_file_name
     config_2['general']['obstacle_file']=empty_file_name
     self.filled_scene = Scene(config=config_1,initial_pedestrian_number=10)
     self.empty_scene = Scene(config=config_2,initial_pedestrian_number=10)
     self.gt1 = GraphTransporter(self.filled_scene, config_1)
     self.gt2 = GraphTransporter(self.empty_scene, config_2)
Example #3
0
 def __init__(self):
     config_1 = SimulationManager.get_default_config()
     config_2 = SimulationManager.get_default_config()
     config_1['general']['obstacle_file'] = demo_file_name
     config_2['general']['obstacle_file'] = empty_file_name
     self.filled_scene = Scene(config=config_1,
                               initial_pedestrian_number=10)
     self.empty_scene = Scene(config=config_2, initial_pedestrian_number=10)
     self.gt1 = GraphTransporter(self.filled_scene, config_1)
     self.gt2 = GraphTransporter(self.empty_scene, config_2)
Example #4
0
def run():

	num_cats = read_num_cats_from_stdin()

	sim_mgr = SimulationManager(
		num_cats,
		'data/tfl_stations.csv',
		'data/tfl_connections.csv'
	)
	sim_mgr.run_simulation()
Example #5
0
 def run_simulation(self, clock_type):
     self.__register_strategy()
     try:
         data_portal = self._prepare_data_portal()
     except:
         return 0
     clock = FactoryClock.get_clock(clock_type, data_portal)
     self.api_strategy.set_internal_variables(clock, data_portal)
     data_api = DataAPI(data_portal=data_portal,
                        traded_pairs=self.traded_pairs)
     self.api_strategy.data_api = data_api
     scheduler = self.api_strategy.get_scheduler()
     simulation_manager = SimulationManager(clock, self.api_strategy,
                                            scheduler)
     simulation_manager.simulate()
 def test_no_obstacle_means_no_fraction(self):
     config = SimulationManager.get_default_config()
     config['general']['obstacle_file'] = test_fractions_file
     scene = Scene(1, config)
     dyn_plan = DynamicPlanner(scene, config)
     # Cell (7,10) is a free cell.
     assert (7, 10) not in dyn_plan.obstacle_cell_set and (
         7, 10) not in dyn_plan.part_obstacle_cell_dict
 def __init__(self):
     self.config = SimulationManager.get_default_config()
     self.config['general']['obstacle_file'] = empty_scene_file
     self.scene = Scene(config=self.config, initial_pedestrian_number=1)
     self.dyn_plan = DynamicPlanner(self.scene, self.config)
     self.pedestrian = self.scene.pedestrian_list[0]
     self.ped_x = np.random.randint(3, self.scene.size.width - 2)
     self.ped_y = np.random.randint(3, self.scene.size.height - 2)
     self.pedestrian.position = Point([self.ped_x, self.ped_y])
     self.pedestrian.velocity = Velocity([1, -1])
Example #8
0
 def __init__(self):
     config = SimulationManager.get_default_config()
     self.scene_obj = Scene(config=config,initial_pedestrian_number=50)
Example #9
0
 def tearDown(self):
     self.obj = SimulationManager(self.num_cats, self.station_file,
                                  self.connection_file)
Example #10
0
 def setUp(self):
     self.num_cats = 10
     self.station_file = '../data/tfl_stations.csv'
     self.connection_file = '../data/tfl_connections.csv'
     self.obj = SimulationManager(self.num_cats, self.station_file,
                                  self.connection_file)
Example #11
0
 def __init__(self):
     self.config = SimulationManager.get_default_config()
     self.config['general']['obstacle_file'] = demo_file_name
     self.scene = Scene(1000, self.config)
     self.grid_computer = GridComputer(self.scene, False, False, False,
                                       self.config)
def create_eventstream_from_simulator(simulator_file_name, number_events,
                                      limit, model_file):

    # simulator generates ~950 events per day
    simulated_days = (1.25 * number_events / 950)

    sm = SimulationManager(start=datetime.datetime.now(),
                           end=datetime.datetime.now() +
                           timedelta(days=simulated_days),
                           model_file=model_file)

    # different resource_limit values produce different amounts of overlap between process instances
    # limits = 5    => overlap ~40+
    # limits = 10   => overlap ~20
    # limits = 50   => overlap ~10
    #
    # writes results into <filename>.txt
    sm.simulate(name=simulator_file_name,
                resource_limit={
                    'support': limit,
                    'trust': limit
                })

    # Get file path for output of simulation
    # using sys.platform to distinguish between Mac OS / Windows
    if sys.platform == "darwin":
        simulator_output_path = "output/" + simulator_file_name + '.txt'
    else:
        simulator_output_path = "output\\" + simulator_file_name + '.txt'

    #Opens file to read simulator output
    f = open(simulator_output_path)

    average_overlap = calculate_concurrency(simulator_output_path)
    print("average_overlap in simulation:", str(average_overlap))

    cleaned_file_path = ""

    # Open file to write ordered output into
    if sys.platform == "darwin":
        cleaned_file_path = "output/" + simulator_file_name + "_cleaned.txt"
    else:
        cleaned_file_path = "output\\" + simulator_file_name + "_cleaned.txt"

    outfile = open(cleaned_file_path, "w")

    data_elements = ["Name", "City", "University", "Gender", "Income"]

    # list of data elements to pull from
    names = ['Alice', 'Bob', 'Charlie', 'David', 'Emily', 'Frank']
    accounts = ['acct' + str(x) for x in range(len(names))]

    data_element_lists = [names, accounts]

    sampled_data = {}

    activity_data = {}

    addToLine = ''
    splitLine = []

    number_events_in_output = 0

    for line in f.readlines():

        if number_events_in_output < number_events:
            number_events_in_output += 1
        else:
            break

        # remove '#' and everything beyond
        line = line[:line.index("#") - 1]

        splitLine = line.split()

        activity_instance_id = splitLine[1]

        if activity_instance_id not in activity_data.keys():
            activity_data[activity_instance_id] = ' Name=' + random.choice(
                data_element_lists[0])

        if ('START' in splitLine):
            outfile.write(line.rstrip() + '\n')

        elif ('END' in splitLine):
            outfile.write(line.rstrip() + '\n')
        else:
            outfile.write(line.rstrip() + activity_data[activity_instance_id] +
                          '\n')

    print("generated clean log: " + cleaned_file_path)

    # close files
    f.close()
    outfile.close()

    os.rename(
        cleaned_file_path, cleaned_file_path[:-4] + "_act=" +
        str(number_events_in_output) + '.txt')

    return number_events_in_output, cleaned_file_path
Example #13
0
parser.add_argument('-n', '--number', type=int, help='Number of pedestrians in simulation', default=-1)
parser.add_argument('-s', '--step', action='store_true', help='Let simulation progress on mouse click only')
parser.add_argument('-g', '--graph', action='store_true', help='Let simulation graph grid values on each time step')
# parser.add_argument('-i', '--apply-interpolation', action='store_true',
#                     help='Let simulation impose swarm behaviour to pedestrians')
# parser.add_argument('-e', '--exponential-planner', action='store_true', help='Use the exponential planner')
# parser.add_argument('-u', '--combi', action='store_true', help='Use the exponential planner')
# parser.add_argument('-p', '--apply-pressure', action='store_true',
#                     help='Let simulation impose UIC (pressure term) to the pedestrians (-c implied)')
parser.add_argument('-t', '--time-delay', type=int, help='Delay between time steps (in milliseconds)', default=1)
parser.add_argument('-o', '--obstacle-file', type=str, help='JSON file containing obstacle descriptions',
                    default='')
parser.add_argument('-c', '--configuration', type=str, choices=['uniform', 'top', 'center', 'bottom'],
                    default='uniform',
                    help='Specify configuration of pedestrian initialization')
parser.add_argument('--draw-cells', action='store_true', help='Draw the boundaries and cell centers of the cells')
parser.add_argument('-f', '--config-file', type=str, default='configs/default.ini',
                    help='Specify configuration file to be used')
parser.add_argument('-r', '--results', action='store_true', help='Log results of simulation to disk')
parser.add_argument('--store-positions', action='store_true', help='Store positions at some time steps')

parser.add_argument('-v', '--verbose', action='store_true', help='Print debugging information to console')
parser.add_argument('--log-exits', action='store_true', help='Store exit data so simulation results can be reused')
parser.add_argument('-k', '--kernel', action='store_true',
                    help='Don\'t run visualization')

args = parser.parse_args()

manager = SimulationManager(args)
manager.start()
Example #14
0
 def __init__(self):
     config = SimulationManager.get_default_config()
     self.scene_obj = Scene(config=config, initial_pedestrian_number=50)
Example #15
0
 def __init__(self):
     self.config = SimulationManager.get_default_config()
     self.config['general']['obstacle_file'] = demo_file_name
     self.scene = Scene(1000, self.config)
     self.grid_computer = GridComputer(self.scene, False, False, False, self.config)
Example #16
0
from simulation_manager import SimulationManager
from car import Car

in_files = [
    'in/a_example.in',
    # 'in/b_should_be_easy.in',
    # 'in/c_no_hurry.in',
    'in/d_metropolis.in',
    'in/e_high_bonus.in'
]

total_score = 0
for in_file in in_files:
    simulation = SimulationManager(in_file)

    print "PROCESSING FILE: ", in_file
    # Run the simulation
    for t in xrange(simulation.T):
        Car.time = t
        for car in simulation.cars:
            car.step()

        # Have we finished ?
        if simulation.ride_queue.ride_empty():
            print "THE RIDE QUEUE IS EMPTY: QUITTING!"
            break

    simulation.save_answer(in_file.replace('in', 'out'))
    total_score += simulation.evaluate_score()
    print ""
print "Total score: ", total_score