Exemple #1
0
def main():
    s = Simulation(processes=1)
    grid = MultiGrid(50, 50, True)

    # build sugar and spice
    sugar_distribution = pylab.genfromtxt("sugar-map.txt")
    spice_distribution = sugar_distribution.T
    sugars = []
    spices = []
    for _, x, y in grid.coord_iter():
        max_sugar = sugar_distribution[x, y]
        max_spice = spice_distribution[x, y]
        sugar = SugarPatch((x, y), max_sugar)
        spice = SpicePatch((x, y), max_spice)
        sugars.append(sugar)
        spices.append(spice)
        grid.place_agent(sugar, (x, y))
        grid.place_agent(spice, (x, y))

    # build agents
    agents = s.build_agents(SsAgent, 'SsAgent', 100, parameters={'grid': grid})

    # prices = []
    for r in range(100):
        s.advance_round(r)
        for sugar in sugars:
            sugar.step()
        for spice in spices:
            spice.step()
        agents.move()
        agents.eat()
        print(',', len(agents.trade_with_neighbors()))

        agents.trade()
        agents.agg_log(possessions=['sugar', 'spice'])

    s.graphs()
Exemple #2
0
def main():
    simulation_parameters = {
        'name': 'direct_optimization',
        'random_seed': None,
        'rounds': 500,
        'trade_logging': 'off',
        'num_firms': 250,
        'alpha': 0.3,
        'gamma': 0.8,
        'price_stickiness': 0.0,
        'network_weight_stickiness': 0.0,
        'wage_stickiness': 0.0,
        'dividends_percent': 0.0,
        'percentage_beneficiaries': 0.25,
        'percentage_injection': 0.25,
        'time_of_intervention': 250
    }
    s = Simulation(name=simulation_parameters['name'])

    network = create_network(simulation_parameters['num_firms'])
    network = [{
        'neighbors': network.neighbors(neighbor)
    } for neighbor in range(simulation_parameters['num_firms'])]
    firms = s.build_agents(Firm,
                           'firm',
                           **simulation_parameters,
                           agent_parameters=[n for n in network])
    household = s.build_agents(
        Household,
        'household',
        1,
        num_firms=simulation_parameters['num_firms'],
        wage_stickiness=simulation_parameters['wage_stickiness'])
    centralbank = s.build_agents(
        CentralBank,
        'centralbank',
        1,
        time_of_intervention=simulation_parameters['time_of_intervention'],
        percentage_injection=simulation_parameters['percentage_injection'],
        percentage_beneficiaries=simulation_parameters[
            'percentage_beneficiaries'])

    for rnd in range(simulation_parameters['rounds']):
        s.advance_round(rnd)
        (firms + household).send_demand()
        (firms + household).selling()
        (firms + household).buying()
        firms.production()
        firms.dividends()
        household.consuming()
        firms.change_weights()
        firms.stats()
        centralbank.intervention()
        household.agg_log(goods=['money'], variables=['utility', 'rationing'])
        firms.agg_log(goods=['money'],
                      variables=[
                          'produced', 'profit', 'price', 'dead', 'inventory',
                          'rationing'
                      ])
        (household + firms).refresh_services('labor',
                                             'labor_endowment',
                                             units=1)

    s.graphs()