예제 #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()
예제 #2
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()
예제 #3
0
 def tearDown(self):
     self.obj = SimulationManager(self.num_cats, self.station_file,
                                  self.connection_file)
예제 #4
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)
예제 #5
0
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
예제 #6
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