Esempio n. 1
0
 def run_single(self, trial_number):
     """ Using -1 as the trial number indicates that this is for a 
     single run, so the trial number won't be included in the filename. """
     avg_num_tasks = 200.
     task_length = 100
     for probes_ratio in self.probes_ratio_values:
         network_delay = 2
         if probes_ratio == -1:
             network_delay = 0
         first = True
         # Number of different utilization values.
         utilization_granularity = 10
         file_prefix = self.get_prefix(trial_number, probes_ratio)
         for i in range(1, utilization_granularity + 1):
             arrival_delay = (task_length * avg_num_tasks *
                              utilization_granularity /
                              (self.num_servers * self.cores_per_server *
                               i))
             simulation.main(["job_arrival_delay=%f" % arrival_delay,
                              "num_users=1",
                              "network_delay=%d" % network_delay,
                              "probes_ratio=%f" % probes_ratio,
                              "task_length_distribution=constant",
                              "num_tasks=%d" % avg_num_tasks,
                              "task_length=%d" % task_length,
                              "task_distribution=constant",
                              "load_metric=total",
                              "cores_per_server=%d" % self.cores_per_server,
                              "file_prefix=%s" % file_prefix,
                              "num_servers=%d" % self.num_servers,
                              "total_time=%d" % self.total_time,
                              "first_time=%s" % first])
             first = False
Esempio n. 2
0
 def run_single(self, trial_number):
     """ Using -1 as the trial number indicates that this is for a 
     single run, so the trial number won't be included in the filename. """
     avg_num_tasks = 200.
     task_length = 100
     for probes_ratio in self.probes_ratio_values:
         network_delay = 2
         if probes_ratio == -1:
             network_delay = 0
         first = True
         # Number of different utilization values.
         utilization_granularity = 10
         file_prefix = self.get_prefix(trial_number, probes_ratio)
         for i in range(1, utilization_granularity + 1):
             arrival_delay = (
                 task_length * avg_num_tasks * utilization_granularity /
                 (self.num_servers * self.cores_per_server * i))
             simulation.main([
                 "job_arrival_delay=%f" % arrival_delay, "num_users=1",
                 "network_delay=%d" % network_delay,
                 "probes_ratio=%f" % probes_ratio,
                 "task_length_distribution=constant",
                 "num_tasks=%d" % avg_num_tasks,
                 "task_length=%d" % task_length,
                 "task_distribution=constant", "load_metric=total",
                 "cores_per_server=%d" % self.cores_per_server,
                 "file_prefix=%s" % file_prefix,
                 "num_servers=%d" % self.num_servers,
                 "total_time=%d" % self.total_time,
                 "first_time=%s" % first
             ])
             first = False
Esempio n. 3
0
 def run_single(self, trial_number):
     """ Using -1 as the trial number indicates that this is for a 
     single run, so the trial number won't be included in the filename. """
     avg_num_tasks = 200. / 6 + 5 * 10. / 6
     for network_delay, probes_ratio in zip(self.delay_values,
                                            self.probes_ratio_values):
         first = True
         utilization_granularity = 20  # Number of different utilization values.
         file_prefix = self.get_prefix(trial_number, network_delay,
                                       probes_ratio)
         for i in range(1, utilization_granularity + 1):
             arrival_delay = (100. * avg_num_tasks *
                              utilization_granularity /
                              (self.num_servers * i))
             simulation.main([
                 "job_arrival_delay=%f" % arrival_delay,
                 "network_delay=%d" % network_delay,
                 "probes_ratio=%f" % probes_ratio,
                 "task_length_distribution=facebook",
                 "task_distribution=bimodal",
                 "file_prefix=%s" % file_prefix,
                 "num_servers=%d" % self.num_servers,
                 "total_time=%d" % self.total_time,
                 "first_time=%s" % first
             ])
             first = False
Esempio n. 4
0
def wait_time_vs_load(file_prefix, utilization, num_servers, tasks_per_job, probes_ratio):
    """ This debugs anomalous performance by plotting wait time.
    
    The output files plot a CDF of wait time for each load (as returned by
    the probe to the server).
    """
    task_length = 100
    arrival_delay = task_length * tasks_per_job / (num_servers * utilization)
    network_delay = 1
    total_time = 1e4
    simulation.main(
        [
            "job_arrival_delay=%f" % arrival_delay,
            "num_users=1",
            "network_delay=%d" % network_delay,
            "probes_ratio=%f" % probes_ratio,
            "task_length_distribution=constant",
            "num_tasks=%d" % tasks_per_job,
            "task_length=%d" % task_length,
            "task_distribution=constant",
            "load_metric=total",
            "file_prefix=%s" % file_prefix,
            "num_servers=%d" % num_servers,
            "total_time=%d" % total_time,
            "first_time=True",
            "record_task_info=True",
        ]
    )
    for job_or_task in ["job", "task"]:
        output_prefix = "%s_%s" % (file_prefix, job_or_task)
        data_filename = "raw_results/%s_wait_cdf" % output_prefix
        # Figure out how many load lines to plot.
        data_file = open(data_filename, "r")
        items = data_file.readline().split("\t")
        num_load_values = len(items) - 2
        data_file.close()

        filename = "plot_%s.gp" % output_prefix
        gnuplot_file = open(filename, "w")
        gnuplot_file.write("set terminal postscript color 'Helvetica' 14\n")
        gnuplot_file.write("set size 0.5,0.5\n")
        gnuplot_file.write("set output 'graphs/%s.ps'\n" % output_prefix)
        gnuplot_file.write("set xlabel 'Task Wait Time (ms)'\n")
        gnuplot_file.write("set ylabel 'Cumulative Probability'\n")
        gnuplot_file.write("set grid ytics\n")
        gnuplot_file.write("plot ")
        for load in range(num_load_values):
            if load != 0:
                gnuplot_file.write(", \\\n")
            gnuplot_file.write("'%s' using %d:1 with l lw 4 title 'Load=%d'" % (data_filename, load + 2, load))
        gnuplot_file.close()

        subprocess.call(["gnuplot", filename])
Esempio n. 5
0
def fairness_time(load_metric, cores_per_server):
    """ Plots the number of running tasks for each user, over time. """
    num_tasks = 10
    network_delay = 5
    probes_ratio = 2
    num_servers = 1000
    total_time = 5000
    file_prefix = "fairness"
    first = True
    utilization = 2.0
    num_users = 4
    arrival_delay = (100.0 * num_tasks / (num_servers * cores_per_server *
                                          utilization))
    simulation.main(["job_arrival_delay=%f" % arrival_delay,
                     "network_delay=%d" % network_delay,
                     "probes_ratio=%f" % probes_ratio,
                     "task_length_distribution=constant",
                     "task_distribution=constant",
                     "job_arrival_distribution=poisson",
                     "deterministic=True",
                     "file_prefix=%s" % file_prefix,
                     "num_users=%d" % num_users,
                     "cores_per_server=%d" % cores_per_server,
                     "num_servers=%d" % num_servers,
                     "num_tasks=%d" % num_tasks,
                     "total_time=%d" % total_time,
                     "load_metric=%s" % load_metric,
                     "relative_weights=1,1,1,2",
                     "relative_demands=1,1,1,1",
                     "first_time=%s" % first])
    
    gnuplot_filename = "plot_fairness.gp"
    gnuplot_file = open(gnuplot_filename, "w")
    gnuplot_file.write("set terminal postscript color\n")
    gnuplot_file.write("set output 'graphs/fairness.ps'\n")
    gnuplot_file.write("set size 0.5,0.5\n")
    #gnuplot_file.write("set xlabel 'Time (ms)'\n")
    #gnuplot_file.write("set ylabel 'Number of Running Tasks'\n")
    gnuplot_file.write("set grid ytics\n")
    gnuplot_file.write("set xrange[0:%d]\n" % total_time)
    gnuplot_file.write("plot ")

    # Write total number of running tasks.
    gnuplot_file.write(("'raw_results/%s_running_tasks' using 1:2 lt 0 lw 4 "
                        "with l notitle") % file_prefix)
    for user_id in range(num_users):
        gnuplot_file.write(",\\\n")
        gnuplot_file.write(("'raw_results/%s_running_tasks_%s' using "
                            "1:2 lt %d lw 4 with l notitle") %
                           (file_prefix, user_id, user_id + 1))
    gnuplot_file.close()

    return gnuplot_filename
Esempio n. 6
0
def simulate_serial():
    print('Iniciando Modo Serial:')
    process_init = pt()  # Contador de processo
    script_init = timeit.default_timer()  # Contador Benchmark

    simulation.main()

    process_end = pt() - process_init
    script_end = timeit.default_timer() - script_init
    print('Tempo de Finalização do Processo (Serial): ', process_end)
    print('Tempo de Finalização do Script (Serial): ', script_end)
    print('--------------------------')
Esempio n. 7
0
def wait_time_vs_load(file_prefix, utilization, num_servers, tasks_per_job,
                       probes_ratio):
    """ This debugs anomalous performance by plotting wait time.
    
    The output files plot a CDF of wait time for each load (as returned by
    the probe to the server).
    """
    task_length = 100
    arrival_delay = (task_length * tasks_per_job /
                     (num_servers * utilization))
    network_delay = 1
    total_time = 1e4
    simulation.main(["job_arrival_delay=%f" % arrival_delay,
                     "num_users=1",
                     "network_delay=%d" % network_delay,
                     "probes_ratio=%f" % probes_ratio,
                     "task_length_distribution=constant",
                     "num_tasks=%d" % tasks_per_job,
                     "task_length=%d" % task_length,
                     "task_distribution=constant",
                     "load_metric=total",
                     "file_prefix=%s" % file_prefix,
                     "num_servers=%d" % num_servers,
                     "total_time=%d" % total_time,
                     "first_time=True",
                     "record_task_info=True"])
    for job_or_task in ["job", "task"]:
        output_prefix = "%s_%s" % (file_prefix, job_or_task)
        data_filename = "raw_results/%s_wait_cdf" % output_prefix
        # Figure out how many load lines to plot.
        data_file = open(data_filename, "r")
        items = data_file.readline().split("\t")
        num_load_values = len(items) - 2
        data_file.close()
    
        filename = "plot_%s.gp" % output_prefix
        gnuplot_file = open(filename, 'w')
        gnuplot_file.write("set terminal postscript color 'Helvetica' 14\n")
        gnuplot_file.write("set size 0.5,0.5\n")
        gnuplot_file.write("set output 'graphs/%s.ps'\n" % output_prefix)
        gnuplot_file.write("set xlabel 'Task Wait Time (ms)'\n")
        gnuplot_file.write("set ylabel 'Cumulative Probability'\n")
        gnuplot_file.write("set grid ytics\n")
        gnuplot_file.write("plot ")
        for load in range(num_load_values):
            if load != 0:
                gnuplot_file.write(", \\\n")
            gnuplot_file.write("'%s' using %d:1 with l lw 4 title 'Load=%d'"
                               % (data_filename, load+2, load))
        gnuplot_file.close()
        
        subprocess.call(["gnuplot", filename])
Esempio n. 8
0
def simulate_single_simulation(single_simulation_dict,
                               suspension_simulation=True):
    title = single_simulation_dict['model_inverse_title']
    n_neurons, n_steps, n_iterations = simulation.extract_rnn_structure_from_title(
        title)

    title_model_inverse_data = {
        'title': title,
        'n_neurons': n_neurons,
        'n_steps': n_steps,
        'n_iterations': n_iterations
    }

    title = single_simulation_dict['model_title']
    n_neurons, n_steps, n_iterations = simulation.extract_rnn_structure_from_title(
        title)
    title_model_data = {
        'title': title,
        'n_neurons': n_neurons,
        'n_steps': n_steps,
        'n_iterations': n_iterations
    }

    if suspension_simulation:
        simulation.simulation_TCP([title_model_inverse_data],
                                  [title_model_data],
                                  mse_calc=False,
                                  plotting=True)
    else:
        simulation_time = 40
        dt = 0.5
        amplitude = 2
        period = 10
        simulation.main(
            [title_model_inverse_data], [title_model_data],
            simulation_time=simulation_time,
            dt=dt,
            SP=model_and_inv_model_identification.generate_rectangle(
                simulation_time, amplitude, period, dt=dt),
            mse_calc=False,
            plotting=True)

        simulation_time = 100
        period = 70
        simulation.main(
            [title_model_inverse_data], [title_model_data],
            simulation_time=simulation_time,
            dt=dt,
            SP=model_and_inv_model_identification.generate_rectangle(
                simulation_time, amplitude, period, dt=dt),
            mse_calc=False,
            plotting=True)
Esempio n. 9
0
def fairness_time(load_metric, cores_per_server):
    """ Plots the number of running tasks for each user, over time. """
    num_tasks = 10
    network_delay = 5
    probes_ratio = 2
    num_servers = 1000
    total_time = 5000
    file_prefix = "fairness"
    first = True
    utilization = 2.0
    num_users = 4
    arrival_delay = (100.0 * num_tasks /
                     (num_servers * cores_per_server * utilization))
    simulation.main([
        "job_arrival_delay=%f" % arrival_delay,
        "network_delay=%d" % network_delay,
        "probes_ratio=%f" % probes_ratio, "task_length_distribution=constant",
        "task_distribution=constant", "job_arrival_distribution=poisson",
        "deterministic=True",
        "file_prefix=%s" % file_prefix,
        "num_users=%d" % num_users,
        "cores_per_server=%d" % cores_per_server,
        "num_servers=%d" % num_servers,
        "num_tasks=%d" % num_tasks,
        "total_time=%d" % total_time,
        "load_metric=%s" % load_metric, "relative_weights=1,1,1,2",
        "relative_demands=1,1,1,1",
        "first_time=%s" % first
    ])

    gnuplot_filename = "plot_fairness.gp"
    gnuplot_file = open(gnuplot_filename, "w")
    gnuplot_file.write("set terminal postscript color\n")
    gnuplot_file.write("set output 'graphs/fairness.ps'\n")
    gnuplot_file.write("set size 0.5,0.5\n")
    #gnuplot_file.write("set xlabel 'Time (ms)'\n")
    #gnuplot_file.write("set ylabel 'Number of Running Tasks'\n")
    gnuplot_file.write("set grid ytics\n")
    gnuplot_file.write("set xrange[0:%d]\n" % total_time)
    gnuplot_file.write("plot ")

    # Write total number of running tasks.
    gnuplot_file.write(("'raw_results/%s_running_tasks' using 1:2 lt 0 lw 4 "
                        "with l notitle") % file_prefix)
    for user_id in range(num_users):
        gnuplot_file.write(",\\\n")
        gnuplot_file.write(("'raw_results/%s_running_tasks_%s' using "
                            "1:2 lt %d lw 4 with l notitle") %
                           (file_prefix, user_id, user_id + 1))
    gnuplot_file.close()

    return gnuplot_filename
Esempio n. 10
0
def main():
    page = st.sidebar.selectbox(
        "Menu", ["COVID19 no seu Município", "Metodologia", "Quem somos?"])

    if page == "Metodologia":
        if __name__ == "__main__":
            md.main()

    elif page == "COVID19 no seu Município":
        if __name__ == "__main__":
            sm.main()

    elif page == "Quem somos?":
        if __name__ == "__main__":
            tm.main()
Esempio n. 11
0
 def simulator(self):
     robot_num = self.ui.Robot_num.value()
     filename = self.ui.Map_filename_read.text()
     algorithm = self.choose_model(self.ui.Algorithm.currentText())
     alpha = self.ui.Alpha.value()
     length = self.ui.Len.value()
     total_time = self.ui.Total_time.value()
     is_window = self.is_windowed(self.ui.Window.currentText())
     cover_ratio = self.ui.Cover_ratio.value()
     self.ui.progressBar.setRange(0, total_time)
     if algorithm == 4 or algorithm == 5:
         parameter = [alpha, length]
     else:
         parameter = [alpha, 0]
     result = []
     for i in range(total_time):
         tmp = simulation.main(robot_num, algorithm, parameter, (100, 100),
                               filename, cover_ratio, is_window)
         result.append(tmp)
         np_result = np.array(result)
         self.ui.Num_now.clear()
         self.ui.Num_now.insertPlainText(str(i + 1))
         self.ui.Time_now.clear()
         self.ui.Time_now.insertPlainText(str(tmp))
         self.ui.progressBar.setValue(i + 1)
         print((i + 1) / total_time)
         self.ui.Mean.clear()
         self.ui.Mean.insertPlainText(str(np.mean(np_result)))
         self.ui.Stander.clear()
         self.ui.Stander.insertPlainText(str(np.std(np_result)))
     self.ui.Coverage_time.setYRange(min=0, max=1000)
     self.curve.setData([j for j in range(1, i + 2)], result)
Esempio n. 12
0
def main(n=100000, generate=False):
    # Read saved data
    c = simulation.main(n, generate)

    # Table1
    print('Table I -- Number of wins by strategy')
    c2 = c.groupby('strategy').agg('count').iloc[:, 0]
    print(c2)

    # Table2
    print('______________________________________________________')
    print('Table II -- Number of wins by ties and strategy')
    c3 = c.groupby(['tie', 'strategy']).agg('count').iloc[:, 0]
    print(c3)
    print(c3.groupby(level=[0]).sum())

    # Table3
    print('______________________________________________________')
    print('Table III -- Number of wins by goals')
    c4 = c.groupby('goal').agg('count').iloc[:, 0]
    print(c4)

    # Table4 -- Luck
    print('______________________________________________________')
    print('Table IV -- Luck')
    print(c[['w_avg_dice', '2nd_avg_dice', 'o_avg_dice']].median())
    print(
        c.groupby(by='tie').agg('median')[[
            'w_avg_dice', '2nd_avg_dice', 'o_avg_dice'
        ]])
    print(
        c.groupby(by='strategy').agg('median')[[
            'w_avg_dice', '2nd_avg_dice', 'o_avg_dice'
        ]])

    # Table5 -- Luck by strategy and tie
    print('______________________________________________________')
    print('Table V')
    print(
        c.groupby(by=['tie', 'strategy']).agg('median')[[
            'w_avg_dice', '2nd_avg_dice', 'o_avg_dice'
        ]])

    # Table6 Resilience and Opportunity
    print('______________________________________________________')
    print('Table VI')
    print(
        c.groupby(by=['strategy', 'tie']).agg(['count', 'median'])[[
            'w_num_rolls', 'o_avg_num_rolls', 'w_avg_dice', 'o_avg_dice'
        ]])
    return c
Esempio n. 13
0
def belief_tester():
    global error
    output = main(sys.argv)
    agents = output[0]
    true_prob = output[1]
    for agent in agents:
        try:
            assert (abs(agent.cur_belief() - true_prob) <= 0.05)
            logging.debug('agent {} true prob {} belief {}'.format(
                agent, true_prob, agent.cur_belief()))
        except AssertionError:
            logging.error('agent belief issue with {}. Exiting'.format(agent))
            error = True
            break
Esempio n. 14
0
def analyze_model(modelpath):
    global runtimes
    try:
        plt.clf()
        logger.info('analyze: \t' + modelpath)
        start = time.clock()
        dbmf.main(modelpath, True, True)
        runtimes[(modelpath, 'dbmf')] = time.clock() - start
        start = time.clock()
        pa.main(modelpath, True, True)
        runtimes[(modelpath, 'pa')] = time.clock() - start
        start = time.clock()
        mc.main(read_model(modelpath), 5, 1000, 95, None)
        runtimes[(modelpath, 'mcsimple')] = time.clock() - start

        start = time.clock()
        stopping_heuristic(modelpath)
        runtimes[(modelpath, 'stoppingheuristic')] = time.clock() - start
        write_runtime()
        #evaluate_methods(modelpath, ['cluster_subspaceXX', 'cluster_subspaceXY','cluster_subspaceXZ'])
        #return
        evaluate_model(modelpath, 'cluster_subspaceXY')

        #evaluate_model(modelpath,'cluster_subspaceXY')
        write_runtime()
        #evaluate_model(modelpath,'cluster_subspaceXZ')
        simu_model = read_model(modelpath)
        start = time.clock()
        mc.main(simu_model, 10, 10000, 95, None)
        runtimes[(modelpath, 'mcfull')] = time.clock() - start

        logger.info('RUNTIME:\t' + repr(runtimes))
        write_runtime()
    except:
        write_runtime()
        logger.error('ERROR AT MODEL: \t' + modelpath)
        logger.error(traceback.format_exc())
Esempio n. 15
0
 def run_single(self, trial_number):
     """ Using -1 as the trial number indicates that this is for a 
     single run, so the trial number won't be included in the filename. """
     avg_num_tasks = 200. / 6 + 5 * 10. / 6
     for network_delay, probes_ratio in zip(self.delay_values,
                                            self.probes_ratio_values):
         first = True
         utilization_granularity = 20  # Number of different utilization values.
         file_prefix = self.get_prefix(trial_number, network_delay,
                                       probes_ratio)
         for i in range(1, utilization_granularity + 1):
             arrival_delay = (100. * avg_num_tasks *
                              utilization_granularity /
                              (self.num_servers * i))
             simulation.main(["job_arrival_delay=%f" % arrival_delay,
                              "network_delay=%d" % network_delay,
                              "probes_ratio=%f" % probes_ratio,
                              "task_length_distribution=facebook",
                              "task_distribution=bimodal",
                              "file_prefix=%s" % file_prefix,
                              "num_servers=%d" % self.num_servers,
                              "total_time=%d" % self.total_time,
                              "first_time=%s" % first])
             first = False
Esempio n. 16
0
def simulate_threading():
    # Contadores
    print('Iniciando Multithreading:\n')
    process_init = pt()  # Contador de processo
    script_init = timeit.default_timer()  # Contador Benchmark

    with ThreadPoolExecutor(max_workers=None) as executor:
        executor.map(simulation.main())
        # task2 = executor.map(cpu_data.main())

    process_end = pt() - process_init
    script_end = timeit.default_timer() - script_init
    print('Tempo de Finalização do Processo (Threading): ', process_end)
    print('Tempo de Finalização do Script (Threading): ', script_end)
    print('--------------------------')
Esempio n. 17
0
                    labelbottom=True,
                    left=False,
                    right=False,
                    labelleft=True)

    plt.savefig('results/png/{}_{}_{}.png'.format(col1, col2, tie),
                bbox_inches='tight')
    plt.savefig('results/pdf/{}_{}.pdf'.format(col1, col2),
                bbox_inches='tight')
    plt.show()


if __name__ == '__main__':
    m = 100000
    gen = False
    c = simulation.main(m, gen)
    # plotting(c)
    # plotting(c[c.tie], col2='2nd_avg_dice')
    # plotting(c[c.tie == False], col2='2nd_avg_dice')
    # p = 'strategy'
    # cs = ['sensible', 'minimalist', 'blitz']
    # t = 'n_countries'
    # plot_kde(c, cs, p, t)
    # t = 'o_avg_dice'
    # plot_kde(c, cs, p, t)
    # t = 'w_avg_dice'
    # plot_kde(c, cs, p, t)
    # p = 'goal'
    # cs = ['territory18', 'territory24', 'continent', 'destroy']
    # t = 'n_countries'
    # plot_kde(c, cs, p, t, 'n_countries_goal')
Esempio n. 18
0
            final_cost = test3.get_cost(test3.state)
            initial_cost = test3.get_cost(np.array([0., 0.]))
            logging.error(
                'failing bounded loss with mkt state {}, revenue {}, losing {} revenue should be {} bound {}'
                .format(test3.state, test3.revenue, loss,
                        final_cost - initial_cost, bound))
            error = True
            break


bounded_loss_test(LMSRMarket)
bounded_loss_test(LMSRProfitMarket)

print 'testing all agents can be initialized'
sys.argv = ["simulation.py", "ZeroI,1", "Truthful,1", "BuyOne,1", '-q']
main(sys.argv)

sys.argv = [
    "simulation.py", "ZeroI,1", "Truthful,1", "BuyOne,1",
    "--mkt_type=LMSRMoney", '-q'
]
main(sys.argv)

print 'testing that posteriors update correctly'


def belief_tester():
    global error
    output = main(sys.argv)
    agents = output[0]
    true_prob = output[1]
Esempio n. 19
0
def simulate_tourney(num_sims, ratings_type):
    df = main(num_sims, ratings_type)
    return df
Esempio n. 20
0
    """Makes the robot move away from the line and into the field.

    Args:
        robot: A Robot object to be moved and which has detected the lines.
        line: A pymunk.Vec2d object representing average direction of lines detected (from line()).
    """

    # sets the robot to move in whichever direction the TOFs detect is further away from the wall
    resultant = pymunk.Vec2d(
        0 if line.x == 0 else abs(line.x) if
        (robot.TOFReadings[1] > robot.TOFReadings[3]
         and robot.TOFReadings[3] < 120) or robot.TOFReadings[1] > 120 else
        -abs(line.x),
        0 if line.y == 0 else abs(line.y)
        if robot.TOFReadings[0] > robot.TOFReadings[2] else -abs(line.y),
    )
    if resultant != pymunk.Vec2d(0, 0):
        robot.move(450, vec_to_world(resultant))


# the programs have been moved to separate files in the /examples for clarity

if __name__ == "__main__":
    main(
        CONFIG,
        examples.own.attack,
        examples.own.defend,
        examples.opponent.o_attack,
        examples.opponent.o_defend,
    )
Esempio n. 21
0
    return


def o_defend(
    robots: List[Robot],
    detectLine: Callable,
    ballPosition: pymunk.Vec2d,
    robotPositions: List[pymunk.Vec2d],
    dribble: Callable[[Robot], None],
    kick: Callable[[Robot], None],
) -> None:
    """Program and logic for opponent defending robot.

    Args:
        robots: A list of both Robots for opponent side.
        detectLine: Function returning a pymunk.Vec2d vector representing
            average **direction** of lines detected by robot passed as argument.
        ballPosition: pymunk.Vec2d object representing world coordinate position of ball.
        robotPositions: List of pymunk.Vec2d objects each representing the world coordinate position of a robot,
            in order [own attack robot, own defense robot, opponent attack robot, opponent defense robot].
        dribble: Function to dribble the ball (and sets robot.dribbleState)
        kick: Function to kick the ball in the front catchment area (if any).
    """

    return


if __name__ == "__main__":
    main(CONFIG, attack, defend, o_attack, o_defend)
Esempio n. 22
0
def fairness_isolation(load_metric, network_delay, probes_ratio,
                       cores_per_server):
    """ This function makes a graph to look at how well we achieve isolation.
    
    We fix the usage of one user at 50% of their allocation, and increase
    the usage of the other user.
    """
    num_users = 2
    num_tasks = 10
    num_servers = 1000
    task_length = 100
    total_time = 2e4
    file_prefix = "fairness_isolation"

    capacity_tasks_per_milli = num_servers * cores_per_server / task_length
    # Demand of user 0, which has constant demand that's 1/4 of cluster
    # calacity (which is half of its share).
    constant_demand_per_milli = capacity_tasks_per_milli / 4.0
    changing_demand_per_milli = capacity_tasks_per_milli / 4.0
    first = True
    while changing_demand_per_milli < (1.5 * capacity_tasks_per_milli):
        total_demand = constant_demand_per_milli + changing_demand_per_milli
        arrival_delay = float(num_tasks) / total_demand
        simulation.main([
            "job_arrival_delay=%f" % arrival_delay,
            "network_delay=%d" % network_delay,
            "probes_ratio=%f" % probes_ratio,
            "task_length_distribution=constant", "task_distribution=constant",
            "job_arrival_distribution=poisson", "deterministic=True",
            "file_prefix=%s" % file_prefix,
            "num_users=%d" % num_users,
            "num_servers=%d" % num_servers,
            "cores_per_server=%d" % cores_per_server,
            "num_tasks=%d" % num_tasks,
            "task_length=%d" % task_length,
            "total_time=%d" % total_time,
            "load_metric=%s" % load_metric,
            ("relative_demands=%d,%d" %
             (constant_demand_per_milli, changing_demand_per_milli)),
            "first_time=%s" % first
        ])
        first = False
        changing_demand_per_milli += 0.1 * capacity_tasks_per_milli
        first = False

    gnuplot_filename = "plot_fairness_isolation.gp"
    gnuplot_file = open(gnuplot_filename, "w")
    gnuplot_file.write("set terminal postscript color\n")
    gnuplot_file.write("set output 'graphs/fairness_isolation.ps'\n")
    gnuplot_file.write("set size 0.5,0.5\n")
    #gnuplot_file.write("set xlabel 'Utilization'\n")
    #gnuplot_file.write("set ylabel 'Normalized Response Time (ms)'\n")
    gnuplot_file.write("set yrange [0:600]\n")
    gnuplot_file.write("set grid ytics\n")
    gnuplot_file.write("plot ")

    gnuplot_file.write(("'raw_results/%s_response_time' using "
                        "3:4 lt 0 lw 4 with l notitle,\\\n") % (file_prefix))
    gnuplot_file.write(("'raw_results/%s_response_time' using "
                        "3:4:5 lt 0 lw 4 with errorbars "
                        "notitle") % (file_prefix))
    for user_id in range(num_users):
        gnuplot_file.write(",\\\n")
        gnuplot_file.write(("'raw_results/%s_response_time_%s' using "
                            "3:4 lt %d lw 4 with l notitle,\\\n") %
                           (file_prefix, user_id, user_id + 1))
        gnuplot_file.write(("'raw_results/%s_response_time_%s' using "
                            "3:4:5 lt %d lw 4 with errorbars "
                            "notitle") % (file_prefix, user_id, user_id + 1))
    gnuplot_file.close()
    return gnuplot_filename
def execute_run(data):
    """ Calls each run for a given run schedule.
        Separate function to allow multiprocessing.
    """

    main(data)
Esempio n. 24
0
import sys
from simulation import main

sys.argv = [
    'simulation.py',
    '--initial_state=0.1,0.1',
    '--num_rounds=3',
    '--num_trials=2',
    '--budget=10.',
    '--mkt_type=LMSR',
    '-q',
    'BuyOne,3',
    'Truthful,3',
]
output = main(sys.argv)

agents = output[0]
true_prob = output[1]
mkt_revenues = output[2]
mkt_probs = output[3]
mkt_lower_bounds = output[4]
mkt_upper_bounds = output[5]
agent_beliefs = output[6]
mkt_payoffs = output[7]

print 'agents in the market are {}'.format(agents)
for agent in agents:
    print(
        'access agent IDs like this: {} (useful for indexing into agent_beliefs, below)'
        .format(agent.id))
print 'true probability of occurrence is {}'.format(true_prob)
Esempio n. 25
0
def main():
    # Get cli args
    kargs = get_args()
    print(kargs)
    instance = kargs["instance"]

    # Final dataframe containing data for each experiment of the simulation
    final_df = pd.DataFrame()

    # Create folder with timestamp as name for storing
    # simulation data
    dir_path = create_timestamp_folder(
        config_manager.SIMULATION_CONTROLLER_ARCHIVE_PATH)

    if instance == "":
        # 1) Generate instance configuration
        print("> STEP 1 - Generating instance configuration...")
        instance_generator.main()
        # Move instance generator output to final folder
        copy_dir(config_manager.OUTPUT_INSTANCE_PATH, dir_path)
    else:
        print("> STEP 1 - Skip -- instance passed as param: {}...".format(
            instance))
        copy_file(instance, dir_path)

    # Before simulations starts, remove all agent logs file from base foulder
    remove_dir_content(config_manager.SIMULATION_AGENT_LOGGING_BASE_PATH)

    # Execute each instance for a predefined number of times (ex. 5)
    for i in range(0, config_manager.NUMBER_OF_SIMULATION_EXECUTION):

        # Generate a random seed for the experiment
        # Note: this is a very important point for experiment reproduction
        # Is very important set seed for both library (random and np)
        seed = np.random.randint(0, 4096)
        random.seed(seed)
        np.random.seed(seed)

        # 2) Single simulation based on configuration file generated before
        print("> STEP 2 - Simulation of instance...")
        simulation.main(instance)

        #time.sleep(2)

        # 3) Analyze simulation output
        print("> STEP 3 - Analyze output...")
        analyzer.main()

        # Create a dir for each iteration of the simulation
        # Move analyzer output files to final foulder (separated for each iteration)
        path = dir_path.joinpath("iteration_{}".format(i))
        os.makedirs(path)
        copy_dir(config_manager.ANALYZER_OUTPUT_PATH, path)

        # Copy to this foulder also simulation results (weights for each agent)
        # Also clean src dir of all content (avoiding file overwriting)
        copy_dir(config_manager.SIMULATION_AGENT_LOGGING_BASE_PATH, path)
        remove_dir_content(config_manager.SIMULATION_AGENT_LOGGING_BASE_PATH)

        #time.sleep(2)

        # 4) Load analyzer output file that contains index for comparison
        print("> STEP 4 - Load Index df...")
        df = pd.read_csv(config_manager.INDEX_COMPARISON_FILE,
                         delimiter='\t',
                         header=0,
                         index_col=0)

        df.index.name = "strategy"
        df["seed"] = [seed] * len(list(df.index.values))
        df.set_index(["seed", df.index], inplace=True)

        print(df)

        if final_df.empty:
            final_df = df
        else:
            final_df = pd.concat([final_df, df])

        # print(final_df)
        # time.sleep(5)

    # 5) Export final results comparison table
    print("> STEP 5 - Export final results table...")
    print(final_df)

    final_df.to_csv(config_manager.SIMULATION_CONTROLLER_OUTPUT_FILE,
                    sep='\t',
                    encoding='utf-8')

    # Move instance generator output to final folder
    copy_dir(config_manager.SIMULATION_CONTROLLER_OUTPUT_PATH, dir_path)

    with open(
            dir_path.joinpath(
                config_manager.
                SIMULATION_CONTROLLER_ARCHIVE_COMPARISON_FILE_NAME), "w") as f:
        # Print mean result of comparison index after 5 executions
        for s in config_manager.STRATEGIES:
            print("---------------------------------------------")
            f.write("---------------------------------------------\n")
            print("> Strategy {}".format(s))
            f.write("> Strategy {}\n".format(s))
            res = final_df.query("strategy == @s")

            for index in config_manager.INDEX_TO_MEAN_FOR_COMPARISON_FOR_TXT_FILE:
                #print(res[index])
                val = res[index].mean()
                print("     > {}: {:0.2f}".format(index, val))
                f.write("     > {}: {:0.2f}\n".format(index, val))

    # Zip archive foulder with all previous gathered data
    zip_foulder(dir_path, dir_path)

    # Remove dir previously zipped
    remove_dir_with_content(dir_path)
Esempio n. 26
0
import topologies
import simulation

simulation.main(topologies.topologies[0], 5)
simulation.main(topologies.topologies[0], 6)
simulation.main(topologies.topologies[1], 5)
simulation.main(topologies.topologies[1], 6)
simulation.main(topologies.topologies[2], 5)
simulation.main(topologies.topologies[2], 6)
Esempio n. 27
0
def fairness_isolation(load_metric, network_delay, probes_ratio,
                       cores_per_server):
    """ This function makes a graph to look at how well we achieve isolation.
    
    We fix the usage of one user at 50% of their allocation, and increase
    the usage of the other user.
    """
    num_users = 2
    num_tasks = 10
    num_servers = 1000
    task_length = 100
    total_time = 2e4
    file_prefix = "fairness_isolation"

    capacity_tasks_per_milli = num_servers * cores_per_server / task_length
    # Demand of user 0, which has constant demand that's 1/4 of cluster
    # calacity (which is half of its share).
    constant_demand_per_milli = capacity_tasks_per_milli / 4.0
    changing_demand_per_milli = capacity_tasks_per_milli / 4.0
    first = True
    while changing_demand_per_milli < (1.5 * capacity_tasks_per_milli):
        total_demand = constant_demand_per_milli + changing_demand_per_milli
        arrival_delay = float(num_tasks) / total_demand
        simulation.main(["job_arrival_delay=%f" % arrival_delay,
                         "network_delay=%d" % network_delay,
                         "probes_ratio=%f" % probes_ratio,
                         "task_length_distribution=constant",
                         "task_distribution=constant",
                         "job_arrival_distribution=poisson",
                         "deterministic=True",
                         "file_prefix=%s" % file_prefix,
                         "num_users=%d" % num_users,
                         "num_servers=%d" % num_servers,
                         "cores_per_server=%d" % cores_per_server,
                         "num_tasks=%d" % num_tasks,
                         "task_length=%d" % task_length,
                         "total_time=%d" % total_time,
                         "load_metric=%s" % load_metric,
                         ("relative_demands=%d,%d" % 
                          (constant_demand_per_milli,
                           changing_demand_per_milli)),
                         "first_time=%s" % first])
        first = False
        changing_demand_per_milli += 0.1 * capacity_tasks_per_milli
        first = False
      
    gnuplot_filename = "plot_fairness_isolation.gp"
    gnuplot_file = open(gnuplot_filename, "w")
    gnuplot_file.write("set terminal postscript color\n")
    gnuplot_file.write("set output 'graphs/fairness_isolation.ps'\n")
    gnuplot_file.write("set size 0.5,0.5\n")
    #gnuplot_file.write("set xlabel 'Utilization'\n")
    #gnuplot_file.write("set ylabel 'Normalized Response Time (ms)'\n")
    gnuplot_file.write("set yrange [0:600]\n")
    gnuplot_file.write("set grid ytics\n")
    gnuplot_file.write("plot ")

    gnuplot_file.write(("'raw_results/%s_response_time' using "
                        "3:4 lt 0 lw 4 with l notitle,\\\n") %
                       (file_prefix))
    gnuplot_file.write(("'raw_results/%s_response_time' using "
                        "3:4:5 lt 0 lw 4 with errorbars "
                        "notitle") % (file_prefix))
    for user_id in range(num_users):
        gnuplot_file.write(",\\\n")
        gnuplot_file.write(("'raw_results/%s_response_time_%s' using "
                            "3:4 lt %d lw 4 with l notitle,\\\n") %
                           (file_prefix, user_id, user_id + 1))
        gnuplot_file.write(("'raw_results/%s_response_time_%s' using "
                            "3:4:5 lt %d lw 4 with errorbars "
                            "notitle") %
                           (file_prefix, user_id, user_id + 1))
    gnuplot_file.close()
    return gnuplot_filename