Example #1
0
        portrayal["Layer"] = 1

    # Return the portrayal of the agent so it can be drawn by the server
    return portrayal


# Set up visualisation elements
# Set up a CanvasGrid, that portrays agents as defined by the portrayal
# function we defined, has 10 x 10 cells, and a display size of 500x500 pixels
grid = CanvasGrid(agent_portrayal, 10, 10, 500, 500)

# Set up user sliders.  For each, we create an instance of the
# UserSettableParameter class, and pass to it that we want a slider, the
# label for the slider, the default, minimum and maximum values for the
# slider, and the increments of change for the slider.
number_of_agents_slider = UserSettableParameter('slider', "Number of Agents",
                                                20, 2, 100, 1)
initial_infection_slider = UserSettableParameter(
    'slider', "Probability of Initial Infection", 0.3, 0.01, 1, 0.01)
transmissibility_slider = UserSettableParameter('slider', "Transmissibility",
                                                0.2, 0.01, 1, 0.01)
level_of_movement_slider = UserSettableParameter('slider', "Level of Movement",
                                                 0.5, 0.01, 1, 0.01)
mean_length_of_disease_slider = UserSettableParameter(
    'slider', "Mean Length of Disease (days)", 10, 1, 100, 1)

# Set up the server as a ModularServer, passing in the model class we
# imported earlier, the list of elements we want to visualise (just the grid
# here), the title to display for the server visualisation, and each user
# interface we want to include (our sliders here) in a dictionary, where the
# index name in " marks must match the respective variable name in the Model
# Class, and the lookup value is the name of the slider we declared above
Example #2
0
def build_server(grid_width=50, grid_height=50):
    canvas_width = 500
    canvas_height = 500

    canvas_element = CanvasGrid(agent_potrayal, grid_width, grid_height,
                                canvas_width, canvas_height)
    chart_element = ChartModule([{
        "Label":
        "Susceptible",
        "Color":
        "rgb{}".format(COLOR_MAP.get_color(AgentState.SUSCEPTIBLE))
    }, {
        "Label":
        "Exposed",
        "Color":
        "rgb{}".format(COLOR_MAP.get_color(AgentState.EXPOSED))
    }, {
        "Label":
        "Infectious",
        "Color":
        "rgb{}".format(COLOR_MAP.get_color(AgentState.INFECTIOUS))
    }, {
        "Label":
        "Symptomatic",
        "Color":
        "rgb{}".format(COLOR_MAP.get_color(AgentState.SYMPTOMATIC))
    }, {
        "Label":
        "Recovered",
        "Color":
        "rgb{}".format(COLOR_MAP.get_color(AgentState.RECOVERED))
    }, {
        "Label":
        "Vaccinated",
        "Color":
        "rgb{}".format(COLOR_MAP.get_color(AgentState.VACCINATED))
    }, {
        "Label":
        "R0/10",
        "Color":
        "rgb{}".format(COLOR_MAP.get_color("R0/10"))
    }])
    model_params = {
        "width":
        grid_width,
        "height":
        grid_height,
        "population_density":
        UserSettableParameter('slider',
                              'Population Density',
                              value=1.0,
                              min_value=0.01,
                              max_value=1.0,
                              step=0.01),
        "vaccine_density":
        UserSettableParameter('slider',
                              'Vaccine Density',
                              value=0.0,
                              min_value=0.0,
                              max_value=0.99,
                              step=0.01),
        "initial_infection_fraction":
        UserSettableParameter('slider',
                              'Initial Infection Fraction',
                              value=0.05,
                              min_value=0.01,
                              max_value=0.99,
                              step=0.01),
        "initial_vaccination_fraction":
        UserSettableParameter('slider',
                              'Initial Vaccination Fraction',
                              value=0.00,
                              min_value=0.00,
                              max_value=0.99,
                              step=0.01),
        "prob_infection":
        UserSettableParameter('slider',
                              'Infection Probability',
                              value=0.05,
                              min_value=0.01,
                              max_value=1.0,
                              step=0.01),
        "prob_agent_movement":
        UserSettableParameter('slider',
                              'Movement Probability',
                              value=0.1,
                              min_value=0.00,
                              max_value=1.0,
                              step=0.01),
        "max_timesteps":
        UserSettableParameter('number', 'Max. Timesteps', value=200),
        "early_stopping_patience":
        UserSettableParameter('number', 'Early Stopping Patience', value=14),
        "toric":
        UserSettableParameter('checkbox', 'Toric Grid', value=True),
        "seed":
        UserSettableParameter('number', 'Seed', value=420),
    }

    _server = ModularServer(
        DiseaseSimModel,
        [canvas_element, chart_element],  # noqa
        "Rog Simulator",
        model_params)

    return _server
Example #3
0
        },
    ],
    data_collector_name="datacollector",
)

server = ModularServer(
    CovidModel,
    [grid, chart],
    "Agent-based pandemics simulation",
    {
        "n_susceptible":
        UserSettableParameter(
            "slider",
            "Number of susceptible",
            997,
            500,
            2000,
            1,
            description=
            "Choose how many susceptible agents to include in the model",
        ),
        "n_infected":
        UserSettableParameter(
            "slider",
            "Number of infected",
            3,
            1,
            2000,
            1,
            description=
            "Choose how many infected agents to include in the model",
        ),
Example #4
0
# Make a world that is 50x50 cells, and 500x500 pixels.
canvas_element = CanvasGrid(portrayPDAgent, 50, 50, 500, 500)

chart_element = ChartModule([{
    "Label": "Cooperating_Agents",
    "Color": "#7570b3"
}])

model_params = {
    "height":
    50,
    "width":
    50,
    "p_coop":
    UserSettableParameter("slider",
                          "Initial Cooperators",
                          value=0.5,
                          min_value=0.1,
                          max_value=0.9,
                          step=0.1),
    "schedule_type":
    UserSettableParameter("choice",
                          "Scheduler type",
                          value="Random",
                          choices=list(PDModel.schedule_types.keys()))
}

server = ModularServer(PDModel, [canvas_element, chart_element],
                       "Prisoner's Dilemma", model_params)
Example #5
0
COLORS = {"Fine": "#00AA00", "On Fire": "#880000", "Burned Out": "#000000"}


def forest_fire_portrayal(tree):
    if tree is None:
        return
    portrayal = {"Shape": "rect", "w": 1, "h": 1, "Filled": "true", "Layer": 0}
    (x, y) = tree.get_pos()
    portrayal["x"] = x
    portrayal["y"] = y
    portrayal["Color"] = COLORS[tree.condition]
    return portrayal


canvas_element = CanvasGrid(forest_fire_portrayal, 100, 100, 500, 500)
tree_chart = ChartModule([{
    "Label": label,
    "Color": color
} for (label, color) in COLORS.items()])

model_params = {
    "height":
    100,
    "width":
    100,
    "density":
    UserSettableParameter("slider", "Tree density", 0.65, 0.01, 1.0, 0.01)
}
server = ModularServer(ForestFire, [canvas_element, tree_chart], "Forest Fire",
                       model_params)
Example #6
0
        # set agent color based on savings and loans
        if agent.savings > agent.model.rich_threshold:
            color = RICH_COLOR
        if agent.savings < 10 and agent.loans < 10:
            color = MID_COLOR
        if agent.loans > 10:
            color = POOR_COLOR

        portrayal["Color"] = color

    return portrayal


# dictionary of user settable parameters - these map to the model __init__ parameters
model_params = {"init_people": UserSettableParameter("slider", "People", 25, 1, 200,
                                                    description="Initial Number of People"),
                "rich_threshold": UserSettableParameter("slider", "Rich Threshold", 10, 1, 20,
                                                   description="Upper End of Random Initial Wallet Amount"),
                "reserve_percent": UserSettableParameter("slider", "Reserves", 50, 1, 100,
                                                    description="Percent of deposits the bank has to hold in reserve")
                }

# set the portrayal function and size of the canvas for visualization
canvas_element = CanvasGrid(person_portrayal, 20, 20, 500, 500)

# map data to chart in the ChartModule
chart_element = ChartModule([{"Label": "Rich", "Color": RICH_COLOR},
                             {"Label": "Poor", "Color": POOR_COLOR},
                             {"Label": "Middle Class", "Color": MID_COLOR}])

# create instance of Mesa ModularServer
Example #7
0
from mesa.visualization.ModularVisualization import ModularServer
from mesa.visualization.modules import ChartModule
from mesa.visualization.UserParam import UserSettableParameter
from abm_buyer_seller.model import WasteModel


chart = ChartModule([{'Label': 'Recycling_Rate', 'Color': 'Black'},
                     {'Label': 'Seller_Savings', 'Color': 'Blue'},
                     {'Label': 'Buyer_Savings', 'Color': 'Red'},
                     {'Label': 'Overall_Savings', 'Color': 'Green'}],
                    data_collector_name='data_collector')

server = ModularServer(WasteModel, [chart],
                       'Waste Model',
                       {'seller_num': UserSettableParameter('slider', 'Number of sellers', 3, 1, 10),
                        'buyer_num': UserSettableParameter('slider', 'Number of buyers', 3, 1, 10),
                        'width': 1, 'height': 1})
server.port = 8521





Example #8
0
                 "Filled": "true",
                 "r": 0.5}
    if agent.condition == "Trialer":
        portrayal["Color"] = "blue"
        portrayal["Layer"] = 0
    elif agent.condition == "Adopter":
        portrayal["Color"] = "red"
        portrayal["Layer"] = 0
        portrayal["r"] = 0.7
    else:
        portrayal["Color"] = "grey"
        portrayal["Layer"] = 0
        portrayal["r"] = 0.2
    return portrayal

ae_slider = UserSettableParameter('slider', "Starting Algo Effectiveness", 0.6, 0.5, 0.8, 0.01)
wms_slider = UserSettableParameter('slider', "Weekly Marketing Spend", 2000, 1000, 10000, 100)
wts_slider = UserSettableParameter('slider', "Weekly Training Spend", 2000, 1000, 10000, 100)
wus_slider = UserSettableParameter('slider', "Weekly Usability Spend", 2000, 1000, 10000, 100)
ve_slider = UserSettableParameter('slider', "Visualization effectiveness (in % time saved)", 0.01, 0.01, 0.2, 0.01)
agent_density_slider = UserSettableParameter('slider', "Starting Algo Effectiveness", 0.5, 0, 1, 0.01)

grid = CanvasGrid(agent_portrayal, 50, 50, 500, 500)

chart1 = ChartModule([{"Label":"Potential Trialer",
                     "Color": "grey"}, {"Label":"Trialer",
                     "Color": "blue"}, {"Label":"Adopter",
                     "Color": "red"}],
                   data_collector_name='dc_adoption')

chart2 = ChartModule([{"Label":"Avg Output Differential Value",
Example #9
0
        portrayal["Layer"] = 0
        #portrayal["r"] = 0.3
    else:
        if agent.prev_incarcerated == True:
            portrayal["Layer"] = 0
            #portrayal["r"] = 0.2
            portrayal["Color"] = "red"

    return portrayal


# Generating a 750 x 600 px grid
grid = CanvasGrid(agent_portrayal, 50, 40, 750, 600)

# Slider to adjust population count
n_slider = UserSettableParameter('slider', "Population Count", 1000, 100, 2000,
                                 1)

# Static Text used for model description
static_text1 = UserSettableParameter('static_text', value=description1)
static_text2 = UserSettableParameter('static_text', value=description2)
static_text3 = UserSettableParameter('static_text', value=description3)

# Allows the user to modify the race of the simulated population
race_option = UserSettableParameter('choice',
                                    'Race of Simulated Population',
                                    value='Black',
                                    choices=['Black', 'White'])

# Independent sliders for black and white sentence lengths
# different ones are required due to distinct default values
bsl_slider = UserSettableParameter('slider', "Max Sentence Length", 17, 1, 100,
Example #10
0
        (x, y) = agent.get_pos()
        portrayal["x"] = x
        portrayal["y"] = y
        portrayal["Color"] = colors[agent.get_color()]

    return portrayal


grid_width = 50
grid_height = 50
canvas_width = 500
canvas_height = 500

model_params = {
    "initial_topics":
    UserSettableParameter("slider", "initial_topics", 100, 1, 1000, 1),
    "agrupados":
    UserSettableParameter('checkbox', 'agrupados', value=True),
    "dispersion":
    UserSettableParameter("slider", "dispersion", 5, 1, 100, 1),
    "tam_dispersion":
    UserSettableParameter("slider", "tam_dispersion", 2, 1, 10, 1),
    "num_cluster":
    UserSettableParameter("slider", "num_cluster", 5, 1, 20, 1),
    "tolerancia":
    0,
    "representar_areas":
    UserSettableParameter('checkbox', 'representar_areas', value=True),
    "height":
    grid_height,
    "width":
Example #11
0
    "Label": "Average Perception of Safety",
    "Color": "#0000FF"
}],
                     data_collector_name="datacollector")

chart2 = ChartModule([{
    "Label": "Crime-rate",
    "Color": "black"
}],
                     data_collector_name="datacollector")

model_params = {
    "n_victims":
    UserSettableParameter('slider',
                          'Number of Possible Victims',
                          value=50,
                          min_value=0,
                          max_value=100,
                          step=1),
    "n_offenders":
    UserSettableParameter('slider',
                          'Number of Possible Offernders',
                          value=15,
                          min_value=0,
                          max_value=30,
                          step=1),
    "n_criminal_generators":
    UserSettableParameter('slider',
                          'Number of Criminal Generators',
                          value=3,
                          min_value=0,
                          max_value=6,
Example #12
0
                    {"Label": "0.50", "Color": "#FF9800"},
                    {"Label": "0.75", "Color": "#FFC100"},
                    {"Label": "1.00", "Color": "#FFEC19"},
                    ], data_collector_name='datacollector')

linechart_2 = ChartModule([
                    {"Label": "score", "Color": "#F6412D"},
                    ], data_collector_name='datacollector2')

histogram = HistogramModule(["Attraction1", "Attraction2", "Attraction3",
                            "Attraction4", "Attraction5"], 20, 50)

model_params = {
    "height": height,
    "width": width,
    "N_attr": UserSettableParameter("slider", "Number of attractions", num_agents, 1, num_agents, 1),
    "N_cust": UserSettableParameter("slider", "Number of customers", int(N_cust/1.5), 1, N_cust * 2, 1),
    "strategy": UserSettableParameter('choice', 'Strategy choice', value='Closest_by',
                                      choices=['Random', 'Closest_by']),
    "theme": UserSettableParameter('choice', 'Theme park lay-out', value='circle',
                                      choices=['random', 'circle', 'cluster']),
    "max_time": max_time,
    "weight": UserSettableParameter("slider", "Weight of waitingtime", 0, 0, 1, 0.25),
    "adaptive": True
}

server = ModularServer(
    Themepark,
    [grid, histogram, chart, linechart, linechart_2],
    "Theme Park Model",
    model_params,
Example #13
0
def radar_portrayal(agent):
    if agent is None:
        return

    portrayal = {}
    portrayal["Shape"] = "circle"
    portrayal["r"] = .5
    portrayal["Layer"] = 0
    portrayal["Filled"] = "true"
    color = COOPERATIVE_COLOR

    return portrayal

# dictionary of user settable parameters - these map to the model __init__ parameters
model_params = {
    "use_team": UserSettableParameter('checkbox', 'Use Team', True)
                }

# set the portrayal function and size of the canvas for visualization
canvas_element = CanvasGrid(radar_portrayal, 20, 20, 500, 500)

# map data to chart in the ChartModule
chart_element = ChartModule([{"Label": "Wrong", "Color": COOPERATIVE_COLOR},
                                {"Label": "Correct", "Color": "#11FF44"}],
                                data_collector_name='datacollector'
                                )

# create instance of Mesa ModularServer
server = ModularServer(RadarTask, [canvas_element, chart_element],
                       "Radar Task",
                       model_params=model_params
    if agent is None:
        return
    portrayal = {"Shape": "circle", "r": 0.5, "Filled": "true", "Layer": 0}

    if agent.type == 0:
        portrayal["Color"] = ["#FF0000", "#FF9999"]
        portrayal["stroke_color"] = "#00FF00"
    else:
        portrayal["Color"] = ["#0000FF", "#9999FF"]
        portrayal["stroke_color"] = "#000000"
    return portrayal


happy_element = HappyElement()
canvas_element = CanvasGrid(schelling_draw, 20, 20, 500, 500)
happy_chart = ChartModule([{"Label": "happy", "Color": "Black"}])

model_params = {
    "height": 20,
    "width": 20,
    "density": UserSettableParameter("slider", "Agent density", 0.8, 0.1, 1.0, 0.1),
    "minority_pc": UserSettableParameter(
        "slider", "Fraction minority", 0.2, 0.00, 1.0, 0.05
    ),
    "homophily": UserSettableParameter("slider", "Homophily", 3, 0, 8, 1),
}

server = ModularServer(
    Schelling, [canvas_element, happy_element, happy_chart], "Schelling", model_params
)
Example #15
0
bar_chart_element_row = BarChartModule(yCollectors, canvas_width=550)

# Create a chart to represent total amount of cAMP on the grid
chart_element = ChartModule([{
    "Label": "Total Amount of cAMP",
    "Color": "#85c6e7"
}])

# Setting size of model
model_params = {
    "height":
    200,
    "width":
    220,
    "numAgents":
    UserSettableParameter("slider", "Number of Agents", 1, 1, 10, 1),
    "gDense":
    UserSettableParameter("slider", "Density of Agents on Grid", .5, 0, 1, .1),
    "kRate":
    UserSettableParameter("slider", "Rate of cAMP decay", 1, 0, 5, .5),
    "dcDiffu":
    UserSettableParameter("slider", "Diffusion Constant of cAMP", .001, 0, .01,
                          .001),
    "dhRes":
    UserSettableParameter("slider", "Spatial Resolution for cAMP Simulation",
                          .01, 0, .1, .01),
    "dtRes":
    UserSettableParameter("slider", "Time Resolution for cAMP Simulation", .01,
                          .01, .1, .01),
    "secRate":
    UserSettableParameter("slider", "Rate of cAMP Secretion by an Agent", 1, 0,
Example #16
0
            "r": 0.7,
            "Filled": "false",
            "Layer": 1
        }
        (x, y) = agent.get_pos()
        portrayal["x"] = x
        portrayal["y"] = y
        portrayal["Color"] = colors[agent.get_color()]

    return portrayal


grid_width = 50
grid_height = 50
canvas_width = 500
canvas_height = 500

rectas = Rectas()

model_params = {
    "data_size": UserSettableParameter("slider", "data_size", 40, 1, 100, 1),
    "height": grid_height,
    "width": grid_width
}

canvas_element = CanvasGrid(pso_portrayal, grid_width, grid_height,
                            canvas_width, canvas_height)

server = ModularServer(Perceptron_Model, [canvas_element, rectas],
                       "perceptron", model_params)
Example #17
0
# création de la grille grâce à des classes fournies par mesa, voir la doc
# mesa pour plus de précisions
canvas_element = CanvasGrid(wolf_sheep_portrayal, 20, 20, 500, 500)
chart_element = ChartModule([{
    "Label": "Fox",
    "Color": "#AA0000"
}, {
    "Label": "Rabbit",
    "Color": "#666666"
}])

# les paramètres modifiables par l'utilisateur avant le lancement de la simulation
model_params = {
    "grass":
    UserSettableParameter("checkbox", "Grass Enabled", True),
    "grass_regrowth_time":
    UserSettableParameter("slider", "Carrot Regrowth Time", 7, 1, 50),
    "initial_sheep":
    UserSettableParameter("slider", "Initial Rabbit Population", 300, 10, 500),
    "sheep_reproduce":
    UserSettableParameter("slider", "Rabbit Reproduction Rate", 0.0, 0.00, 0.1,
                          0.001),
    "initial_wolves":
    UserSettableParameter("slider", "Initial Fox Population", 50, 10, 300),
    "wolf_reproduce":
    UserSettableParameter(
        "slider",
        "Fox Reproduction Rate",
        0,
        0.00,
Example #18
0
        portrayal['w'] = 0.02
        portrayal['Color'] = 'Red'
    elif type(agent) is Robot:
        portrayal['Shape'] = "circle"
        portrayal['r'] = 2
        # portrayal['r'] = 2
        # portrayal['text_color'] = 'Black'
        portrayal['Color'] = 'Red'
        # portrayal['stroke_color'] = '#030303'
    else:
        portrayal['Shape'] = 'circle'
        portrayal['r'] = 2
        portrayal['Color'] = 'Blue'
        # portrayal['stroke_color'] = '#030303'
    return portrayal


params = {
    'width':
    20,
    'height':
    20,
    'density':
    UserSettableParameter('slider', 'crowd density', 0.3, 0.00, 0.9, 0.1),
    'train':
    False
}

boid_canvas = SimpleCanvas(crowd_draw, 500, 500)
server = ModularServer(CrowdDynamics, [boid_canvas], "Crowd Dynamics", params)
Example #19
0
            portrayal["Color"] = "white"
            portrayal["Layer"] = 0
        elif agent.kind == "E":
            portrayal["Color"] = "blue"
            portrayal["Layer"] = 0
        elif agent.kind == "I":
            portrayal["Color"] = "red"
            portrayal["Layer"] = 0
        elif agent.kind == "B":
            portrayal["Color"] = "green"
            portrayal["Layer"] = 0

    return portrayal


canvas_element = CanvasGrid(turtle_portrayal, 20, 20, 400, 400)
chart          = ChartModule([{"Label": 'NumberOfContacts', "Color": "#0000FF"}]
)

model_params = {"turtles": UserSettableParameter('slider', 'turtles', 100, 100, 5000, 100),
                "i0" : UserSettableParameter('slider', 'i0', 10, 1, 100, 5),
                "r0" : UserSettableParameter('slider', 'r0', 3.5, 0.5, 10.5, 0.5),
                "ti" : UserSettableParameter('slider', 'ti', 5, 1, 20, 1),
                "tr" : UserSettableParameter('slider', 'ti', 5, 1, 20, 1)}


server = ModularServer(BarrioTortugaSEIR, [canvas_element, chart], "Barrio Tortuga SEIR",
model_params)
server.port = 8521
server.launch()
Example #20
0
        }
    elif type(agent) is FoodAgent:

        portrayal = {
            "Shape": "circle",
            "Color": "red",
            "Filled": "true",
            "Layer": 5,
            "r": 0.5
        }
    return portrayal


# Setup the parameters: here changeable by the user
model_params = {
    "N": UserSettableParameter('slider', "Number of agents", 1, 1, 8, 1)
}

# Setup the visualisation of the grid
canvas_element = CanvasGrid(food_portrayal, 20, 20, 500, 500)

# Define two charts (based on the collected data!)
chart = ChartModule([{
    "Label": "Collected energy",
    "Color": "red"
}, {
    "Label": "Active agents",
    "Color": "blue"
}],
                    data_collector_name='datacollector')
chart2 = ChartModule([{
Example #21
0
        "Color": "purple"
    }, {
        "Label": "dead",
        "Color": "gray"
    }, {
        "Label": "quarantined",
        "Color": "blue"
    }],
    data_collector_name="datacollector",
)

model_params = {
    "population":
    UserSettableParameter("slider",
                          "population",
                          value=900,
                          min_value=10,
                          max_value=1000,
                          step=10),
    "time_until_symptomatic":
    UserSettableParameter("slider",
                          "time_until_symptomatic",
                          value=3,
                          min_value=0,
                          max_value=10,
                          step=1),
    "initial_proportion_sick":
    UserSettableParameter(
        "slider",
        "initial_proportion_sick",
        value=0.1,
        min_value=0,
Example #22
0
def launch(width, height, port=None):
    model_params = {
        'starting_settlements':
        UserSettableParameter('slider',
                              'starting_settlements',
                              value=14,
                              min_value=5,
                              max_value=20,
                              description='Initial Number of Settlements'),
        'starting_households':
        UserSettableParameter(
            'slider',
            'starting_households',
            value=7,
            min_value=1,
            max_value=10,
            description='Initial Number of Households per Settlement'),
        'starting_household_size':
        UserSettableParameter(
            'slider',
            'starting_household_size',
            value=5,
            min_value=1,
            max_value=10,
            description='Initial Number of Workers in each Household'),
        'starting_grain':
        UserSettableParameter(
            'slider',
            'starting_grain',
            value=3000,
            min_value=100,
            max_value=8000,
            description='Initial Grain Supply of Households'),
        'min_ambition':
        UserSettableParameter('slider',
                              'min_ambition',
                              value=0.1,
                              min_value=0.0,
                              max_value=1.0,
                              step=0.1,
                              description='Minimum Household Ambition'),
        'min_competency':
        UserSettableParameter('slider',
                              'min_competency',
                              value=0.5,
                              min_value=0.0,
                              max_value=1.0,
                              step=0.1,
                              description='Minimum Household Competency'),
        'generational_variation':
        UserSettableParameter(
            'slider',
            'generational_variation',
            value=0.9,
            min_value=0.0,
            max_value=1.0,
            step=0.1,
            description='Generational Variation in Ambition and Competency'),
        'knowledge_radius':
        UserSettableParameter('slider',
                              'knowledge_radius',
                              value=5,
                              min_value=5,
                              max_value=40,
                              description='Household Knowledge Radius'),
        'population_growth_rate':
        UserSettableParameter('slider',
                              'pop_growth_rate',
                              value=0.1,
                              min_value=0.0,
                              max_value=0.5,
                              step=0.01,
                              description='Population Growth Rate'),
        'distance_cost':
        UserSettableParameter('slider',
                              'distance_cost',
                              value=10,
                              min_value=1,
                              max_value=15,
                              step=1,
                              description='Distance Cost'),
        'allow_rental':
        UserSettableParameter('checkbox',
                              'allow_rental',
                              value=False,
                              description='Allow Land Rental'),
        'land_rental_rate':
        UserSettableParameter('slider',
                              'land_rental_rate',
                              value=0.5,
                              min_value=0.3,
                              max_value=0.6,
                              step=0.05,
                              description='Land Rental Rate'),
        'fallow_limit':
        UserSettableParameter('slider',
                              'fallow_limit',
                              value=4,
                              min_value=0,
                              max_value=10,
                              step=1,
                              description='Fallow Limit'),
        'annual_competency_increase':
        UserSettableParameter(
            'slider',
            'annual_competency_increase',
            value=0,
            min_value=0,
            max_value=10,
            step=0.25,
            description='Annual Competency Increase Percentage'),
        'w':
        width,
        'h':
        height
    }

    visualisation_elements = []

    # grid visualisation
    visualisation_elements.append(
        EgyptGrid(__agent_portrayal__, width, height, 500, 500))

    # datacollector graphs
    visualisation_elements.append(
        ChartModule([{
            'Label': 'Gini',
            'Color': 'Black'
        }],
                    data_collector_name='datacollector'))
    visualisation_elements.append(
        ChartModule([{
            'Label': 'Total Wealth',
            'Color': 'Black'
        }],
                    data_collector_name='datacollector'))
    visualisation_elements.append(
        ChartModule([{
            'Label': 'Mean Settlement Wealth',
            'Color': 'Black'
        }],
                    data_collector_name='datacollector'))
    visualisation_elements.append(
        ChartModule([{
            'Label': 'Total Population',
            'Color': 'Black'
        }],
                    data_collector_name='datacollector'))
    visualisation_elements.append(
        ChartModule([{
            'Label': 'Mean Settlement Population',
            'Color': 'Black'
        }],
                    data_collector_name='datacollector'))

    server = ModularServer(EgyptModel, visualisation_elements, 'Egypt Model',
                           model_params)

    server.launch(port)
Example #23
0
class MyTextElement(TextElement):
    def render(self, model):
        opinion_0 = count_opinion(model, 0)
        opinion_1 = count_opinion(model, 1)

        return 'Opinion 0 count: {}<br>Opinion 1 count: {}'.format(
            opinion_0, opinion_1)


model_params = {
    'N':
    UserSettableParameter(
        'slider',
        'Number of agents',
        10,
        10,
        500,
        10,
        description='Choose how many agents to include in the model',
    ),
    'avg_node_degree':
    UserSettableParameter('slider',
                          'Avg Node Degree',
                          5,
                          1,
                          10,
                          1,
                          description='Avg Node Degree'),
    'rule':
    UserSettableParameter('choice',
                          'Rule Type',
Example #24
0
import numpy as np
from mesa.visualization.UserParam import UserSettableParameter

# The file contain the parameters that affect the flow of entire experiment.

# grid size of one size of the model instance
gridsize = 50

model_params = {
    "gridsize":
    gridsize,
    "cop_density":
    UserSettableParameter("slider", "Cop Density", 0.01, 0, 1, 0.001),
    "citizen_density":
    UserSettableParameter("slider", "Citizen Density", 0.7, 0, 1, 0.001),
    "agent_type":
    "Poor",
    "legitimacy":
    UserSettableParameter("slider", "Legitimacy", 1.0, 0.001, 1, 0.001),
    "l_state":
    UserSettableParameter("checkbox", "Decrease Legitimacy", value=False),
    "reduction_constant":
    UserSettableParameter("number", "Reduction Constant", value=0.01),
    "active_threshold":
    UserSettableParameter("slider", "Active Threshold", 0.2, 0, 1, 0.1),
    "include_wealth":
    UserSettableParameter("checkbox", "Include Wealth", value=True),
    "rich_threshold":
    UserSettableParameter("slider", "Rich Threshold", 10, 1, 20),
}
Example #25
0
        portrayal["stroke_color"] = "#00FF00"

    else:
        portrayal["Color"] = ["#0000FF", "#0000FF"]
        portrayal["stroke_color"] = "#000000"

    return portrayal


# Initialize the Canvas and chart
happy_element = HappyElement()
canvas_element = CanvasGrid(schelling_draw, 30, 30, 450, 450)
happy_chart = ChartModule([{"Label": "happy", "Color": "Black"}])

# Set the parameters for the model. UserSettableParameter means that the user can modify this parameter in the web page. It takes 6 parameters (type, name, initial value, min value, max value, value per step).
model_params = {
    "height":
    30,
    "width":
    30,
    "density":
    UserSettableParameter("slider", "Agent density", 0.9, 0.1, 1.0, 0.1),
    "minority_pc":
    UserSettableParameter("slider", "Fraction minority", 0.5, 0.00, 1.0, 0.05),
    "homophily":
    UserSettableParameter("slider", "Homophily", 3, 0, 8, 1),
}

# Initialize the server with all the configurations defined above
server = ModularServer(Schelling, [canvas_element, happy_element, happy_chart],
                       "Schelling", model_params)
Example #26
0
    def __init__(self):
        pass

    def render(self, model):
        # image created on MS Paint and uploaded to internet, but also featured in this folder for reference
        return (
            "<center><img src = 'http://i63.tinypic.com/21o30yg.png'></center>"
            + "<br>" + "<br><br></h3>")


text0 = MapLegend()
canvas = CanvasGrid(movement_portrayal, width, height, canvas_width,
                    canvas_height)
# chart_count = ChartModule([monkey_movement_chart])

agent_slider = UserSettableParameter('slider', "Number of Families", 20, 1, 30,
                                     1)
humans_choice = UserSettableParameter(
    'choice',
    "Status of Humans in Reserve",
    'with_humans',
    choices=['with_humans', 'without_humans'])

model_params = {"number_of_families": agent_slider, "grid_type": humans_choice}

server = ModularServer(Movement, [canvas, text0],
                       "FNNR: an ABM of Guizhou Golden Monkey Movement",
                       model_params)
# deleted ', chart_count' after canvas
server.port = 8080
#port = int(os.getenv('PORT', 5000))
#server.listen(port, address='0.0.0.0')
Example #27
0
        return
    portrayal = {'Shape': 'circle', 'r': 0.5, 'Filled': 'true', 'Layer': 0}

    if agent.type == 0:
        portrayal['Color'] = ['#FF0000', '#FF9999']
        portrayal['stroke_color'] = '#00FF00'
    else:
        portrayal['Color'] = ['#0000FF', '#9999FF']
        portrayal['Stroke_color'] = '#000000'
    return portrayal


happy_element = HappyElement()
canvas_element = CanvasGrid(schelling_draw, 20, 20, 500, 500)
happy_chart = ChartModule([{'Label': 'happy', 'Color': 'Black'}])

model_params = {
    'height':
    20,
    'width':
    20,
    'density':
    UserSettableParameter('slider', 'Agent density', 0.8, 0.1, 1.0, 0.1),
    'minority_pc':
    UserSettableParameter('slider', 'Fraction minority', 0.2, 0.00, 1.0, 0.05),
    'homophily':
    UserSettableParameter('slier', 'Homophily', 3, 0, 8, 1),
}

server = ModularServer(Schelling, [canvas_element, happy_element, happy_chart],
                       'Schelling', model_params)
Example #28
0
    "Color": INFECTED_COLOR
}, {
    "Label": "Recovered",
    "Color": RECOVERED_COLOR
}, {
    "Label": "Quarantined of Infected",
    "Color": QUARANTINING_COLOR
}, {
    "Label": "Average R_0",
    "Color": R0_COLOR
}])

model_params = {
    "num_infec_agents":
    UserSettableParameter("number",
                          "Initial Infected",
                          1,
                          description="Initial Infected"),
    "num_uninfec_agents":
    UserSettableParameter("number",
                          "Initial Uninfected",
                          20,
                          description="Initial Uninfected"),
    "num_rec_agents":
    UserSettableParameter("number",
                          "Initial Recovered",
                          0,
                          description="Initial Recovered"),
    "mask_efficacy":
    UserSettableParameter("number",
                          "Mask Efficacy in %",
                          95,
Example #29
0
        portrayal["Shape"] = "images/penguin.png"
        portrayal["scale"] = 1.25
        portrayal["Layer"] = 1

        # if agent.kill is False:
        #     portrayal["Color"] = "grey"
        #     portrayal["Layer"] = 1
        # else:
        #     portrayal["Color"] = "red"
        #     portrayal["r"] = "0.25"
        #     portrayal["Layer"] = 1
        return portrayal


die_slider = UserSettableParameter('slider',
                                   "Temperature at which penguins die", 5, 0,
                                   40, 1)
loss_rate_slider = UserSettableParameter('slider', "Heat Loss rate to ground",
                                         0.01, 0, 0.5, 0.01)
n_slider = UserSettableParameter('slider', "Number of Penguins", 25, 1, 200, 1)

# lets show the average heat of the penguins
chart = ChartModule([{
    "Label": "Average Heat of Penguins",
    "Color": "Black"
}],
                    data_collector_name='data_collector')

grid = CanvasHexGrid(agent_portrayal, 25, 25, 500, 500)
server = ModularServer(
    Arctic, [grid, chart], "Arctic Landscape", {
Example #30
0
        portrayal["Color"] = "red"
        portrayal["Layer"] = 1

    return portrayal

grid = CanvasGrid(agent_portrayal, 150, 150, 1000, 1000)
gini_chart = ChartModule([
    {"Label": "Gini", "Color": "#0000FF"}],
    data_collector_name='ginicollector'
)
avg_chart = ChartModule([
    {"Label": "Average Wealth", "Color": "#0000FF"}],
    data_collector_name='avgcollector')

model_params = {
    "N": UserSettableParameter('slider', "Number of agents", 200, 2, 400, 1,
                               description="Choose how many agents to include in the model"),
    "initial_wealth": UserSettableParameter('slider', "Initial Wealth", 10, 2, 20, 1),
    "cost_per_pixel": UserSettableParameter('slider', "Cost of Car Travel per Unit", 0.3, 0.1, 1, 0.1),
    "pt_cost": UserSettableParameter('slider', "Cost of PT Travel", 2, 1, 10, 1),
    "cost_to_move": UserSettableParameter('slider', "Cost of Moving/Selling", 30, 10, 60, 1),
    "pt_aval": UserSettableParameter('slider', "Avaliablity of PT over distance", 1, 0.1, 3, 0.1),
    "width": 150,
    "height": 150,
    "city_pos": (75, 75)

}

server = ModularServer(CommuteModel, [grid, gini_chart, avg_chart], "Commute Model", model_params)
server.port = 8521