def main():
    """Main script.
    """

    # Use Agg backend for matplotlib. Why?
    matplotlib.use('Agg')

    # Load in parameters
    params = PARAMS.copy()

    # Calculate dimension of the strategy arrays
    params['DIMENSION'] = (100 / params['GRANULARITY'] + 1)

    # Calculate the value of a single unit of a strategy based on uniform dist.
    params['STARTING_PCT'] = 1.0 / (params['DIMENSION'] ** 2)

    # Initialize teams
    teams = initialize_starting_distribution(**params)

    species_breakdown = [1.0 / 3.0] * 3

    species_breakdown_history = [[], [], []]

    # Initialize average deal data lists
    avg_deal_data = [[], [], []]

    data = teams

    fig, axarr, img, cbar = initialize_figure(avg_deal_data, data, **params)

    # MAIN LOOP
    for round_number in range(params['ROUNDS']):
        # Calculate fitness
        game.calc_scores(**params)

        # Update data
        results = game.update_data()

        teams = results[0]
        avg_deal_data = results[1]
        species_breakdown = results[2]
        species_breakdown_history = results[3]
        center_of_mass = results[4]

        update_figures(fig, axarr, img, cbar, teams, avg_deal_data, 
               species_breakdown_history, center_of_mass, i, **params)

        filename = params['SIM_NAME'] + "%04d.png" % i
        fig.savefig(os.path.join("output", "tmp", filename), dpi=150)

    remove_file(os.path.join("output", "videos", params["SIM_NAME"] + ".mp4"))

    create_video_from_frames(params['SIM_NAME'])

    clear_directory(os.path.join("output", "tmp"))
def main():
    """Main script.
    """

    # Use Agg backend for matplotlib. Why?
    matplotlib.use('Agg')

    # Load in parameters
    params = PARAMS.copy()

    # Calculate dimension of the strategy arrays
    params['DIMENSION'] = (100 / params['GRANULARITY'] + 1)

    # Calculate the value of a single unit of a strategy based on uniform dist.
    params['STARTING_PCT'] = 1.0 / (params['DIMENSION']**2)

    # Initialize teams
    teams = initialize_starting_distribution(**params)

    species_breakdown = [1.0 / 3.0] * 3

    species_breakdown_history = [[], [], []]

    # Initialize average deal data lists
    avg_deal_data = [[], [], []]

    data = teams

    fig, axarr, img, cbar = initialize_figure(avg_deal_data, data, **params)

    # MAIN LOOP
    for round_number in range(params['ROUNDS']):
        # Calculate fitness
        game.calc_scores(**params)

        # Update data
        results = game.update_data()

        teams = results[0]
        avg_deal_data = results[1]
        species_breakdown = results[2]
        species_breakdown_history = results[3]
        center_of_mass = results[4]

        update_figures(fig, axarr, img, cbar, teams, avg_deal_data,
                       species_breakdown_history, center_of_mass, i, **params)

        filename = params['SIM_NAME'] + "%04d.png" % i
        fig.savefig(os.path.join("output", "tmp", filename), dpi=150)

    remove_file(os.path.join("output", "videos", params["SIM_NAME"] + ".mp4"))

    create_video_from_frames(params['SIM_NAME'])

    clear_directory(os.path.join("output", "tmp"))
def main():
    """Main script.
    """

    # Use Agg backend for matplotlib. Why?
    matplotlib.use('Agg')

    # Load in parameters
    params = PARAMS.copy()

    # Calculate dimension of the strategy arrays
    params['DIMENSION'] = (100 / params['GRANULARITY'] + 1)

    # Calculate the value of a single unit of a strategy based on uniform dist.
    params['UNIT_VALUE'] = 1.0 / (params['DIMENSION']**2)

    params['NUMBER_OF_TEAMS'] = len(params['TEAM_SPEC'])

    # Initialize game
    game = Game(**params)

    # Initialize plot
    fig, axarr, img, cbar = initialize_figure(game, **params)

    # MAIN LOOP
    for round_number in range(params['ROUNDS']):
        game.calc_scores(**params)

        game.update_data(round_number, **params)

        print "*******************************"
        print "round_number:", round_number

        for team in game.teams:
            print team.stats.loc[round_number]

        print "*******************************"

        fig, axarr, img, cbar = update_figures(fig, axarr, img, cbar, game,
                                               round_number, **params)

        filename = params['SIM_NAME'] + "%04d.png" % round_number
        fig.savefig(os.path.join("output", "tmp", filename), dpi=120)

    remove_file(os.path.join("output", "videos", params["SIM_NAME"] + ".mp4"))

    create_video_from_frames(params['SIM_NAME'])

    clear_directory(os.path.join("output", "tmp"))
Esempio n. 4
0
def main():
    """Main script.
    """

    # Use Agg backend for matplotlib. Why?
    matplotlib.use('Agg')

    # Load in parameters
    params = PARAMS.copy()

    # Calculate dimension of the strategy arrays
    params['DIMENSION'] = (100 / params['GRANULARITY'] + 1)

    # Calculate the value of a single unit of a strategy based on uniform dist.
    params['UNIT_VALUE'] = 1.0 / (params['DIMENSION'] ** 2)

    params['NUMBER_OF_TEAMS'] = len(params['TEAM_SPEC'])

    # Initialize game
    game = Game(**params)

    # Initialize plot
    fig, axarr, img, cbar = initialize_figure(game, **params)

    # MAIN LOOP
    for round_number in range(params['ROUNDS']):
        game.calc_scores(**params)

        game.update_data(round_number, **params)

        print "*******************************"
        print "round_number:", round_number

        for team in game.teams:
            print team.stats.loc[round_number]

        print "*******************************"

        fig, axarr, img, cbar = update_figures(fig, axarr, img, cbar, game, 
                                               round_number, **params)

        filename = params['SIM_NAME'] + "%04d.png" % round_number
        fig.savefig(os.path.join("output", "tmp", filename), dpi=120)

    remove_file(os.path.join("output", "videos", params["SIM_NAME"] + ".mp4"))

    create_video_from_frames(params['SIM_NAME'])

    clear_directory(os.path.join("output", "tmp"))