コード例 #1
0
def move_scenario():
    """
    One apad is added and it should move somewhere.
    Figure out how times and speed will be calculated. 1 second
    of our time is 30 minutes in simulation, but speed of apad is 0.5 meters per second.
    How will we calculate everything??
    """
    #deltat = 1  # this is 30 minutes
    #deltat = 0.5  # this is 15 minutes
    deltat = 0.25  # this is 7.5 minutes
    topology = util.parser(
        filename=os.path.join("..", "init_files", "init_topo_exmple.txt"))
    apad = topology.all_agents[0]
    r = rospy.Rate(1 / deltat)  # 1 Hz
    xs = []
    ys = []
    while not rospy.is_shutdown():
        apad.move(deltat)
        x, y = apad.coordinates
        xs.append(x)
        ys.append(y)
        r.sleep()
        if len(xs) > 10:
            break
    util.plot_coordinates(xs, ys)
コード例 #2
0
ファイル: main.py プロジェクト: farjun/MasterTaki
def test_and_plot(num_of_iterations):
    counter_weights = check_pickle_file_path(approximate_weights_path)
    players, number_of_games, levels, discount, epsilon, print_mode = parser(
        sys.argv)
    winning_percentages = [0] * num_of_iterations
    game = None
    for i in range(num_of_iterations):
        print("Start iteration number %d" % (i + 1))
        game = GameManager(players,
                           number_of_games,
                           levels,
                           discount,
                           epsilon,
                           print_mode=print_mode,
                           counter_weights_list=counter_weights)
        game.run_game()  # run the test
        game.print_scoring_table()
        winning_percentages[i] = game.get_player_score(
            0) / number_of_games  # insert reinforcement agent index
        print("Finish iteration number %d" % (i + 1))
    player_1_type = game.get_player_type(0)
    player_2_type = game.get_player_type(1)
    print("The average %s winning percentage is %6.2f" %
          (player_1_type, sum(winning_percentages) / num_of_iterations))
    pyplot.plot(range(1, len(winning_percentages) + 1), winning_percentages)
    pyplot.xlabel("Iteration number")
    pyplot.ylabel("%s winning percentage" % player_1_type)
    title = "%s vs %s\n%d games in each iteration" % (
        player_1_type, player_2_type, number_of_games)
    if player_1_type == "AlphaBetaPruning" or player_2_type == "AlphaBetaPruning":
        title += "\nAlpha Beta with depth " + str(levels)
    pyplot.title(title)
    pyplot.show()
コード例 #3
0
def scenarioGoToNearest():
    system = parser(filename="evolutionary_init.txt")
    mussel_coordinates = [list(item.coordinates) for item in system.mussels]
    start = min(mussel_coordinates,
                key=lambda x: distance(list(system.pads[0].coordinates), x))
    points = go_to_nearest(system, start)
    totalDistance = total_distance(points)
    system.plot_topology(
        annotate_energy=False,
        order_of_passing=True,
        title=
        "Way of prioritizing: Go to nearest point with nearest first point; Total Distance: {}"
        .format(totalDistance))
コード例 #4
0
ファイル: main.py プロジェクト: farjun/MasterTaki
def run_from_parser():
    counter_weights = check_pickle_file_path(approximate_weights_path)
    players, number_of_games, levels, discount, epsilon, print_mode = parser(
        sys.argv)
    game = GameManager(players,
                       number_of_games,
                       levels,
                       discount,
                       epsilon,
                       print_mode=print_mode,
                       counter_weights_list=counter_weights)
    game.run_game()  # run the test
    game.print_scoring_table()
コード例 #5
0
def scenarioEvolutionary():
    system = parser(filename="evolutionary_init.txt")
    mussel_coordinates = [list(item.coordinates) for item in system.mussels]
    bestGene, points_dict = evolutionary.main(mussel_coordinates,
                                              system.pads[0].coordinates)
    switchDict = dict()
    for key, item in points_dict.items():
        switchDict[tuple(item)] = key
    # for i, mussel in enumerate(system.mussels):
    points = bestGene.points
    for i, mussel in enumerate(system.mussels):
        system.mussels[i].order_of_passing = points.index(
            list(mussel.coordinates))
    totalDistance = total_distance(points, system.pads[0].coordinates)
    system.plot_topology(
        annotate_energy=False,
        order_of_passing=True,
        title="Way of prioritizing: Evolutionary algorithm; Total Distance: {}"
        .format(totalDistance))
コード例 #6
0
ファイル: topology.py プロジェクト: anniekovac/master_mussels
        plt.legend()

        for (i, mussel) in enumerate(self.mussels):
            if annotate_energy:
                ax.annotate(str(mussel.energy),
                            (mussels_x[i] + 0.05, mussels_y[i] + 0.05))
            if order_of_passing:
                ax.annotate(str(mussel.order_of_passing),
                            (mussels_x[i] - 0.08, mussels_y[i] - 0.08))

        for (i, apad) in enumerate(self.pads):
            if annotate_energy:
                ax.annotate(str(apad.energy),
                            (pads_x[i] + 0.05, pads_y[i] + 0.05))

        plt.grid()
        plt.xlabel("X coordinates of agents")
        plt.ylabel("Y coordinates of agents")
        if title:
            plt.title(title)
        if save:
            plt.savefig(str(time.time()).replace(".", "") + ".jpg")
        else:
            plt.show()


if __name__ == '__main__':
    topology = util.parser(filename=os.path.join(os.getcwd(), "init_files",
                                                 "evolutionary_init.txt"))
    #topology.plot_topology(order_of_passing=True)