Пример #1
0
        portrayal["scale"] = 0.9
        portrayal["Layer"] = 4

    else:
        return
    return portrayal


canvas_element = CanvasGrid(agent_portrayal, 50, 50, 600, 600)
chart_element = ChartModule([{
    "Label": "Susceptible",
    "Color": "#FF0000"
}, {
    "Label": "Susceptible_with_mask",
    "Color": "#FFFF00"
}, {
    "Label": "Infected",
    "Color": "#99D500"
}, {
    "Label": "Recovered",
    "Color": "#0000FF"
}])

model_params = {
    "verbose":
    UserSettableParameter('checkbox', "Verbose?", False),
    "initial_susceptible":
    UserSettableParameter('slider', 'Initial Susceptible Population', 150, 0,
                          300),
    "initial_susceptible_with_mask":
    UserSettableParameter('slider', 'Initial maksed Susceptible Population',
Пример #2
0
        portrayal["Color"] = ["#FF0000", "#FF9999"]
        portrayal["stroke_color"] = "#00FF00"
    else:
        portrayal["Color"] = ["#0000FF", "#9999FF"]
        portrayal["stroke_color"] = "#000000"

    return portrayal


training_element = TrainingCoverageElement()
canvas_element = CanvasGrid(draw_training_coverage,
                            grid_width=20,
                            grid_height=20,
                            canvas_width=500,
                            canvas_height=500)
training_chart = ChartModule([{"Label": "is_trained", "Color": "Black"}])

model_params = {
    "height":
    20,
    "width":
    20,
    "density":
    UserSettableParameter("slider",
                          "Agent density",
                          value=0.65,
                          min_value=0.1,
                          max_value=1.0,
                          step=0.05),
    "n_steps":
    100,
Пример #3
0
        "width": edge_width(*get_agents(source, target)),
    } for (source, target) in G.edges]

    return portrayal


network = NetworkModule(network_portrayal, 500, 500, library="d3")

#this section give charts
chart = ChartModule([
    {
        "Label": "Infected",
        "Color": "#FF0000"
    },
    {
        "Label": "Susceptible",
        "Color": "#008000"
    },
    {
        "Label": "Resistant",
        "Color": "#808080"
    },
])


class MyTextElement(TextElement):
    def render(self, model):
        ratio = model.proportion_infected()
        ratio_text = "∞" if ratio is math.inf else "{0:.2f}".format(
            ratio)
        infected_text = number_infected(model)
Пример #4
0
    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
)
Пример #5
0

# The model is adjustable on the server.
n_slider = UserSettableParameter("slider", "Number of agents", 750, 1, 1500, 1)
beta_c = UserSettableParameter("slider", "Beta Crowd Penalty", 1.9, 0, 5,
                               0.1)  # Crowd
beta_d = UserSettableParameter("slider", "Beta Distance Penalty", 1, 0, 5,
                               0.1)  # Distance
beta_w = UserSettableParameter("slider", "Beta Waiting Time Penalty", 0.5, 0,
                               5, 0.1)  # Waiting Time
beer_consumption = UserSettableParameter("slider", "Beer Consumption Rate",
                                         0.00083333, 0, 0.005, 0.00005)
serving_speed = UserSettableParameter("slider", "Serving Speed Bar", 0.1, 0, 1,
                                      0.01)
#canvas_element = CanvasGrid(SsAgent_portrayal, 50, 50, 500, 500)
chart_element = ChartModule([{"Label": "Waiting", "Color": "#AA0000"}])

#server = ModularServer(Sugarscape2ConstantGrowback, [canvas_element, chart_element],
#"Sugarscape 2 Constant Growback")
grid = CanvasGrid(SsAgent_portrayal, 18, 34, 250, 500)

server = ModularServer(
    Sugarscape2ConstantGrowback, [grid, chart_element], "ABM Project", {
        "N": n_slider,
        "beta_c": beta_c,
        "beta_d": beta_d,
        "beta_w": beta_w,
        "beer_consumption": beer_consumption,
        "serving_speed": serving_speed
    })
Пример #6
0
                          value=2,
                          min_value=2,
                          max_value=10,
                          step=1),
    "width":
    10,
    "height":
    10,
    "trade":
    UserSettableParameter("choice",
                          "Allow trade?",
                          value=True,
                          choices=[True, False])
}

utility_element = UtilityElement()
grid = CanvasGrid(agent_portrayal, 10, 10, 500, 500)
utility_chart = ChartModule([{
    "Label": "Mean_Utility",
    "Color": "Black"
}],
                            data_collector_name='datacollector')
specialization_chart = ChartModule([{
    "Label": "Mean_Specialization",
    "Color": "Green"
}],
                                   data_collector_name='datacollector')
server = ModularServer(
    mkt, [grid, utility_chart, specialization_chart, utility_element],
    "Money Model", model_params)
Пример #7
0
        portrayal["r"] = .3

    else:
        portrayal["Color"] = ["#AAAADD"]

    return portrayal


canvas_element = CanvasGrid(psyrtsPortrayal, 20, 20, 500, 500)
chart_element = ChartModule([{
    "Label": "Exploration",
    "Color": "#00AA00"
}, {
    "Label": "Exploitation",
    "Color": "#0041FF"
}, {
    "Label": "ResourcesRatio",
    "Color": "#FFAA22"
}, {
    "Label": "MapExplored",
    "Color": "#00FFFF"
}])


class MyTextElement(TextElement):
    def render(self, model):

        totalResources = str(model.resources)
        explorationS = exploration(model)
        exploitationS = exploitation(model)
        resourceRatio = resourcesRatio(model)
        portrayal["Layer"] = 0
        portrayal["r"] = 0.2
    elif agent.wealth > 0:
        portrayal["Color"] = "#ffd966"
        portrayal["Layer"] = 1
        portrayal["r"] = 0.1
    else:
        portrayal["Color"] = "#ff8c66"
        portrayal["Layer"] = 2
        portrayal["r"] = 0.0
    return portrayal

grid = CanvasGrid(agent_portrayal, economy_scale, economy_scale, 650, 650)
chart = ChartModule([
    {"Label": "Gini", "Color": "#6aa35e"}],
    data_collector_name='datacollector',
    canvas_height=600, canvas_width=550
)
#text = TextElement(js_code="document.write(5 + 6);")

server = ModularServer(
    WealthModel,
    [grid, chart],
    name="Wealth Model",
    model_params={
        "N": economy_scale*economy_scale,
        "width": economy_scale,
        "height":economy_scale
        })
server.port = 8521
server.launch()
Пример #9
0
    ),
    "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
server = ModularServer(
    BankReserves,
    [canvas_element, chart_element],
    "Bank Reserves Model",
    model_params=model_params,
)
Пример #10
0
        if agent.fully_grown:
            portrayal["Color"] = ["#00FF00", "#00CC00", "#009900"]
        else:
            portrayal["Color"] = ["#84e184", "#adebad", "#d6f5d6"]
        portrayal["Shape"] = "rect"
        portrayal["Filled"] = "true"
        portrayal["Layer"] = 0
        portrayal["w"] = 1
        portrayal["h"] = 1

    return portrayal


canvas_element = CanvasGrid(wolf_sheep_portrayal, 20, 20, 500, 500)
chart_element = ChartModule(
    [{"Label": "Hen", "Color": "blue"}, {"Label": "Rooster", "Color": "red"},{"Label": "HatchingChicken", "Color": "yellow"}
    ,{"Label": "Egg", "Color": "orange"}, {"Label": "FertilizedEgg", "Color": "green"}]
)

model_params = {
    "grass_regrowth_time": UserSettableParameter(
        "slider", "Grass Regrowth Time", 20, 0, 50
    ),
    "initial_rooster": UserSettableParameter(
        "slider", "Initial Rooster Population", 1, 1, 100
    ),
    "initial_hen": UserSettableParameter(
        "slider", "Initial Hen Population", 1, 1, 100
    ),
    "initial_hatchingChicken": UserSettableParameter(
        "slider", "Initial Hatching Chicken Population", 1, 1, 100
    ),
from model import WorldModel
from mesa.visualization.ModularVisualization import ModularServer
from mesa.visualization.modules import ChartModule

liquidity_agent1_chart = ChartModule([{
    "Label": "Household liquidity",
    "Color": "Black"
}],
                                     data_collector_name="datacollector")

deposit_agent1_chart = ChartModule([{
    "Label": "Household deposit",
    "Color": "Black"
}],
                                   data_collector_name="datacollector")

liquidity_agent0_chart = ChartModule([{
    "Label": "Bank liquidity",
    "Color": "Black"
}],
                                     data_collector_name="datacollector")

net_worth_agents_chart = ChartModule([{
    "Label": "Networth of household",
    "Color": "Black"
}, {
    "Label": "Networth of bank",
    "Color": "Red"
}],
                                     data_collector_name="datacollector")
Пример #12
0
        portrayal["Shape"] = "img/healthy_without_mask.png"
    return portrayal


grid = CanvasGrid(agent_portrayal, int(covid_model['width']),
                  int(covid_model['height']), 800, 800)

chart1 = ChartModule([{
    "Label": "Fatalities",
    "Color": "Black"
}, {
    "Label": "Immune",
    "Color": "Blue"
}, {
    "Label": "Healthy",
    "Color": "Green"
}, {
    "Label": "Infected",
    "Color": "Orange"
}, {
    "Label": "Hospital Occupation",
    "Color": "Yellow"
}],
                     data_collector_name='data_collector')
chart2 = ChartModule([{
    "Label": "Fatality Rate",
    "Color": "Black"
}, {
    "Label": "Morbidity Rate",
    "Color": "Orange"
}],
Пример #13
0
    "sensitivity":
    UserSettableParameter('slider', 'Emotional Sensitivity', 0, 0, 100, 5)

    # "simplified_payoffs": UserSettableParameter('checkbox', 'Simplified Payoffs', False),
    # "b": UserSettableParameter('number', 'Simplified Payoffs: Benefit of Co-op', value=4),
    # "c": UserSettableParameter('number', 'Simplified Payoffs: Cost of Co-op', value=1),
}

#chart_element = ChartModule([{"Label": "Cooperations", "Color": C_COLOR},
#                            {"Label": "Defections", "Color": D_COLOR}], canvas_height=200, canvas_width=200)

chart_element = ChartModule([{
    "Label": "Percentage Cooperations",
    "Color": C_COLOR
}, {
    "Label": "Percentage Defections",
    "Color": D_COLOR
}, {
    "Label": "Average Mood",
    "Color": "#ffc0cb"
}])

# k_element = CoopIndexDisplay()
#chart_element_2 = ChartModule([{"Label": "Average Mood", "Color": "#ffc0cb"}], canvas_height=200, canvas_width=300)
# TODO: Kind of want to add in mutual cooperations tracking, but that's extraneous right now

server = ModularServer(
    PDModel,
    [
        canvas_element,
        step_element,
        chart_element,  #k_element
Пример #14
0
                    'evitar_agentes': False,
                    'en_cuarentena': False,
                    'quedate_en_casa': False,
                    'prob_contagiar': 0.5,
                    'prob_infectarse': 0.8,
                    'radio_de_infeccion': 0
                    }



malla = CanvasGrid(dibujar_agente, 75, 75 , 600, 600)
grafico = ChartModule([{'Label': 'Suceptibles',
                        'Color': 'Green'},
                     {'Label': 'Expuestos',
                        'Color': 'Orange'},
                     {'Label': 'Infectados',
                        'Color': 'Red'},
                     {'Label': 'Recuperados',
                        'Color': 'Black'}],
                    data_collector_name = 'datacollector')

argumentos_modelo ={"N":n_agentes, "city_object": Ciudad, 
                    "agent_object": Individuo_2,
                    "ind_attrs": attrs_individuos}

server = ModularServer(Modelo,
                       [malla, grafico],
                       "Modelo",
                       argumentos_modelo)

server.port = 8521
Пример #15
0
        target,
        'color':
        edge_color(G.node[source]['agent'][0], G.node[target]['agent'][0]),
        'width':
        edge_width(G.node[source]['agent'][0], G.node[target]['agent'][0]),
    } for i, (source, target, _) in enumerate(G.edges(data=True))]

    return portrayal


network = NetworkModule(network_portrayal, 500, 500, library='d3')
chart = ChartModule([{
    'Label': 'Susceptible',
    'Color': '#ADD694'
}, {
    'Label': 'Infected',
    'Color': '#F2728C'
}, {
    'Label': 'Removed',
    'Color': ' #67B8C7'
}])


class RatioElement(TextElement):
    def render(self, model):
        ratio = model.removed_susceptible_ratio()
        ratio_text = '∞' if ratio is math.inf else '{0:.2f}'.format(
            ratio)
        return 'Removed/Susceptible Ratio: ' + ratio_text


class InfectedRemainingElement(TextElement):
Пример #16
0
        susceptible = model.susceptible
        exposed = model.exposed

        return "Number Suscpetible of  cases: {}<br>Number Exposed of Citizen: {}<br>Number of Infected cases: {}<br>Number of Recovered cases: {}<br>Dead: {}<br>R0 value: {}".format(
            susceptible, exposed, infected, recovered, dead, r_o)


canvas_element = CanvasGrid(agent_portrayal, 10, 10, 500, 500)
text_element = MyTextElement()
chart = ChartModule([{
    "Label": "susceptible",
    "Color": "#b5551d"
}, {
    "Label": "exposed",
    "Color": "#fcf00a"
}, {
    "Label": "infected",
    "Color": "#fa0c00"
}, {
    "Label": "recovered",
    "Color": "#008000"
}],
                    data_collector_name="datacollector")

chart3 = ChartModule([{
    "Label": "Most Poor",
    "Color": "#FF0000"
}, {
    "Label": "Poor",
    "Color": "#f5a442"
}, {
    "Label": "Middle Class",
Пример #17
0
        portrayal["stroke_color"] = "#000000"
        if agent.is_cooperative:
            portrayal["Color"] = ["#0000FF", "#FF0000"
                                  ]  # Blue from outside; Red from inside
            portrayal["stroke_color"] = "#FFFFFF"

    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"
}, {
    "Label": "segregation",
    "Color": "Blue"
}])

# 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":
          "Species2_Dead": "#FF0000",
          "Spreading": "#FFF900"}


def forest_disease_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_disease_portrayal, 100, 100, 500, 500)
tree_chart = ChartModule([{"Label": label, "Color": color} for (label, color) in COLORS.items()])

model_params = {
    "height": 100,
    "width": 100,
    "species1_tree_density": UserSettableParameter("slider", "Species1 Tree density", 0.65, 0.01, 1.0, 0.01),
    "species2_tree_density": UserSettableParameter("slider", "Species2 Tree density", 0.65, 0.01, 1.0, 0.01),
    "mortality": UserSettableParameter("slider", "Dead after n years", 1, 1, 10, 1),
    "wind": UserSettableParameter('choice', 'Prevailing wind direction', value='N',
                                  choices=['N', 'S', 'E', 'W']),
    "distance": UserSettableParameter("slider", "Distance", 1, 1, 5, 1)

}
server = ModularServer(ForestDisease, [canvas_element, tree_chart], "Forest Disease", model_params)
Пример #19
0
        portrayal["Layer"] = 1
        portrayal["w"] = 1
        portrayal["h"] = 1
        portrayal["text"] = agent.gate_id
        portrayal["text_color"] = "White"

    elif type(agent) is SecurityAgent:
        portrayal["Color"] = GUARD_COLOR if not agent.saw_thief else "Red"
        portrayal["r"] = 0.6
        portrayal["Layer"] = 2
        portrayal["text"] = agent.guard_id
        portrayal["text_color"] = "Black"

    elif type(agent) is ThiefAgent:
        portrayal["Color"] = THIEF_COLOR
        portrayal["Layer"] = 0
        portrayal["r"] = 0.8

        if agent.direction is not None:
            portrayal["text"] = agent.direction
            portrayal["text_color"] = "Black"

    return portrayal


canvas_element = CanvasGrid(mall_portrayal, 20, 20, 500, 500)

chart_element = ChartModule([{"Label":"Escape Distance", "Color": "#AA0000"}])


Пример #20
0
        portrayal["stroke_color"] = "#000000"
    else:
        portrayal["r"] = 0.5
        portrayal["text"] = 'B'
        portrayal["Color"] = ["#FFFFFF", "#FFFFFF"]
        portrayal["stroke_color"] = "#000000"

    return portrayal


# Dashboard outputs
gdp_element = GDPElement()
canvas_element = CanvasGrid(economic_system_draw, 10, 10, 400, 400)
employment_chart = ChartModule([{
    "Label": "Employment",
    "Color": "#0000FF"
}],
                               data_collector_name='datacollector')

# Model parameters
model_params = {
    "width":
    UserSettableParameter("slider", "Grid width", 10, 2, 50, 1),
    "height":
    UserSettableParameter("slider", "Grid height", 10, 2, 50, 1),
    "industry_pc":
    UserSettableParameter("slider", "Fraction industry", 0.8, 0.1, 1.0, 0.1),
    "services_pc":
    UserSettableParameter("slider", "Fraction services", 0.6, 0.00, 1.0, 0.05),
    "tax_industry":
    UserSettableParameter("slider", "Tax rate industry", 0.1, 0.01, 0.8, 0.01),
Пример #21
0
grid_height = 100
canvas_width = 500
canvas_height = 500

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

# # El método recolector de datos lo usa este cambas
# tree_chart = ChartModule([{"Label": "Fine", "Color": "green"},
#                           {"Label": "On Fire", "Color": "red"},
#                           {"Label": "Burned Out", "Color": "black"}])
#

best_text = BestText()
average_text = AverageText()

pso_chart = ChartModule([{"Label": "Best", "Color": "green"},
                         {"Label": "Average", "Color": "red"}])

#self, population: int, dimension: int, attraction_best_global: float,
#                 attraction_best_personal: float, lim_vel_particles: float,
#                 inertia_particle: float, max_iterations: int,
#                 width: int, height: int, num_max_locales: int,
#                 suavizar_espacio: int

model_params = {
    #"population": 18,#18,
    "population": UserSettableParameter("slider", "Population", 18, 0, 50, 1),
    "dimension": 2,
    #"attraction_best_global": 1.9,
    "attraction_best_global": UserSettableParameter("slider", "attraction_best_global ", 1.9, 0, 5, 0.1),
    #"attraction_best_personal": 1.5,
    "attraction_best_personal": UserSettableParameter("slider", "attraction_best_personal", 1.5, 0, 5, 0.1),
Пример #22
0
        else:
            portrayal["Color"] = ["#84e184", "#adebad", "#d6f5d6"]
        portrayal["Shape"] = "rect"
        portrayal["Filled"] = "true"
        portrayal["Layer"] = 0
        portrayal["w"] = 1
        portrayal["h"] = 1

    return portrayal


canvas_element = CanvasGrid(wolf_sheep_portrayal, 20, 20, 500, 500)
chart_element = ChartModule([{
    "Label": "Wolves",
    "Color": "#AA0000"
}, {
    "Label": "Sheep",
    "Color": "#666666"
}])

model_params = {
    "grass":
    UserSettableParameter('checkbox', 'Grass Enabled', True),
    "grass_regrowth_time":
    UserSettableParameter('slider', 'Grass Regrowth Time', 20, 1, 50),
    "initial_sheep":
    UserSettableParameter('slider', 'Initial Sheep Population', 100, 10, 300),
    "sheep_reproduce":
    UserSettableParameter('slider', 'Sheep Reproduction Rate', 0.04, 0.01, 1.0,
                          0.01),
    "initial_wolves":
Пример #23
0
from road_network_model.agent import Car, TrafficLight
from road_network_model.model import RoadNetworkModel
from road_network_model.portrayal import road_network_model_portrayal
from road_network_model.constant import PROJECT_TITLE, CANVAS_WIDTH, CANVAS_HEIGHT, GRID_WIDTH, GRID_HEIGHT, NUMBER_OF_CARS

import math

# Define a CanvasGrid to visualise the Road Network Model
canvas_element = CanvasGrid(road_network_model_portrayal, GRID_WIDTH,
                            GRID_HEIGHT, CANVAS_WIDTH, CANVAS_HEIGHT)

chart_car_state = ChartModule([{
    "Label": "Idle",
    "Color": "#FF0000"
}, {
    "Label": "Move",
    "Color": "#00FF00"
}, {
    "Label": "Finished",
    "Color": "#0000FF"
}])

chart_car_moving = ChartModule([{
    "Label": "ToOffice",
    "Color": "#F1C40F"
}, {
    "Label": "ToResidence",
    "Color": "#2C3E50"
}])


class InfoTextElement(TextElement):
Пример #24
0
        portrayal["Color"] = "yellow"
    elif cell.isDead:
        portrayal["Color"] = "black"

    return portrayal


# Make a world that is 50x50, on a 500x500 display.
canvas_element = CanvasGrid(portrayCell, 50, 50, 500, 500)

# The two graphs that are displayed in the web socket
cell_chart = ChartModule([{
    "Label": "Fraction Infected",
    "Color": 'Red'
}, {
    "Label": "Fraction Quarantined",
    "Color": 'Yellow'
}],
                         canvas_height=500,
                         canvas_width=1000)
cell_chart2 = ChartModule([{
    "Label": "Fraction Recovered",
    "Color": 'Green'
}, {
    "Label": "Fraction Dead",
    "Color": 'Black'
}],
                          canvas_height=500,
                          canvas_width=1000)

# The parameters that can be set a priori by the user in the web socket
Пример #25
0
    if type(agent) is Zucca_seed:
        portrayal["Color"] = ["#C8B560", "#C8B560"]
        portrayal["stroke_color"] = "#000000"
        portrayal["text_color"] = "#C8B560"
        portrayal["Layer"] = 0
    if type(agent) is flower:
        portrayal["Color"] = ["#FF0000", "#FF0000"]
        portrayal["stroke_color"] = "#000000"
        portrayal["Layer"] = 1
        portrayal["r"] = 0.35
    return portrayal


canvas_element = CanvasGrid(Squash_Bee_portrayal, 50, 50, 500, 500)
chart_element = ChartModule([{"Label": "Zucche_fiori", "Color": "#8AF017"},
                                {"Label": "Zucche", "Color": "#FBB917"},
                                {"Label": "Seed", "Color": "#C8B560"},
                                {"Label": "Api", "Color": "#FFFF00"},
                                {"Label": "Larve", "Color": "#ADA96E"}])

model_params = {"density_bee": UserSettableParameter('slider', 'numero di api nel prato', 180, 0, 500),
                "density_gender_bee": UserSettableParameter('slider', 'Densità di api femmine', 60, 0, 100),
                "gain_polline_raccolto": UserSettableParameter('slider', 'guadagno energia dal polline', 60, 0, 100),
                "density_zucca": UserSettableParameter('slider', 'numero di fiori di zucca nel prato', 200, 1, 500),
                "prob_accoppiamento": UserSettableParameter('slider', 'probabilità di accoppiamento tra due api', 80, 0, 100),
                "offsetX": UserSettableParameter('slider', 'spostamento campo X', 5, 0, 20),
                "offsetY": UserSettableParameter('slider', 'spostamento campo Y', 5, 0, 20)}

server = ModularServer(SquashBee, [canvas_element, chart_element], "Simulazione comportamento dell'ape della zucca", model_params)
server.port = 8521
Пример #26
0

width = GRID_WIDTH
height = GRID_HEIGHT

canvas_element = CanvasGrid(hive_portrayal, width, height, 500, 500)
chart_element = ChartModule([{
    "Label": "n_bees",
    "Color": "#AA0000"
}, {
    "Label": "hive_food",
    "Color": "#000000"
}, {
    "Label": "scout_bees",
    "Color": "#70a5f9"
}, {
    "Label": "forage_bees",
    "Color": "#f4b042"
}, {
    "Label": "rest_bees",
    "Color": "#17ef71"
}, {
    "Label": "baby_bees",
    "Color": "#ff93d0"
}], 500, 500)

server = ModularServer(
    BeeForagingModel, [canvas_element, chart_element], "Hive", {
        "width":
        width,
        "height":
Пример #27
0
    if agent.wealth > 0:
        portrayal["Color"] = "red"
        portrayal["Layer"] = 0
    else:
        portrayal["Color"] = "grey"
        portrayal["Layer"] = 1
        portrayal["r"] = 0.2
    return portrayal

#we instantiate a grid of 500px * 500px
grid = CanvasGrid(agent_portrayal, 10, 10, 500, 500)

#Add a chart element to the server to appear under the grid
chart = ChartModule([{
                    "Label": "Gini",
                    "Color": "Black"}],
                    data_collector_name="datacollector")

server = ModularServer(
                    MoneyModel, #model class we are running
                    [grid, chart],     # a list of module objects to include in the visualisation
                    "Money Model", # title
                    {"N": 100, "width": 10,"height": 10} # inputs for the model itself
                    )


server.port = 8521 # default

server.launch()
#ctrl + c in terminal to terminate
Пример #28
0
        portrayal = {
            "Shape": "circle",
            "Color": agent.color,
            "Filled": "true",
            "Layer": 0,
            "r": 0.5
        }

        if agent.is_checked:
            portrayal["Color"] = "white"
    return portrayal


chart = ChartModule([{
    "Label": "total_income",
    "Color": "Black"
}],
                    data_collector_name='income_data_collector')

queue_length_chart = ChartModule(
    [{
        "Label": "average_queue_length",
        "Color": "Blue"
    }],
    data_collector_name='queue_length_data_collector')

grid = CanvasGrid(agent_portrayal, width, height, width * 10, height * 10)

n_slider = UserSettableParameter('slider', "Number of opened checkouts", 3, 1,
                                 len(market.cashRegisters) - 1, 1)
Пример #29
0

class HappyElement(TextElement):
    '''
    Display a text count of how many happy agents there are.
    '''

    def __init__(self):
        pass

    def render(self, model):
        return "market_price : " + str(model.market_price)


happy_element = HappyElement()

model_params = {
    "agent_count": 3,
    #"density": UserSettableParameter("slider", "Agent density", 0.8, 0.1, 1.0, 0.1)
}

colors=["aliceblue","antiquewhite","antiquewhite1","antiquewhite2","antiquewhite3","antiquewhite4","aqua","aquamarine1","aquamarine2","aquamarine3","aquamarine4","azure1","azure2","azure3","azure4","banana","beige","bisque1","bisque2","bisque3","bisque4","black","blanchedalmond","blue","blue2","blue3","blue4","blueviolet","brick","brown","brown1","brown2","brown3","brown4","burlywood","burlywood1","burlywood2","burlywood3","burlywood4","burntsienna","burntumber","cadetblue","cadetblue1","cadetblue2","cadetblue3","cadetblue4","cadmiumorange","cadmiumyellow","carrot","chartreuse1","chartreuse2","chartreuse3","chartreuse4","chocolate","chocolate1","chocolate2","chocolate3","chocolate4","cobalt","cobaltgreen","coldgrey","coral","coral1","coral2","coral3","coral4","cornflowerblue","cornsilk1","cornsilk2","cornsilk3","cornsilk4","crimson","cyan2","cyan3","cyan4","darkgoldenrod","darkgoldenrod1","darkgoldenrod2","darkgoldenrod3","darkgoldenrod4","darkgray","darkgreen","darkkhaki","darkolivegreen","darkolivegreen1","darkolivegreen2","darkolivegreen3","darkolivegreen4","darkorange","darkorange1","darkorange2","darkorange3","darkorange4","darkorchid","darkorchid1","darkorchid2","darkorchid3","darkorchid4","darksalmon","darkseagreen","darkseagreen1","darkseagreen2","darkseagreen3","darkseagreen4","darkslateblue","darkslategray","darkslategray1","darkslategray2","darkslategray3","darkslategray4","darkturquoise","darkviolet","deeppink1","deeppink2","deeppink3","deeppink4","deepskyblue1","deepskyblue2","deepskyblue3","deepskyblue4","dimgray","dodgerblue1","dodgerblue2","dodgerblue3","dodgerblue4","eggshell","emeraldgreen","firebrick","firebrick1","firebrick2","firebrick3","firebrick4","flesh","floralwhite","forestgreen","gainsboro","ghostwhite","gold1","gold2","gold3","gold4","goldenrod","goldenrod1","goldenrod2","goldenrod3","goldenrod4","gray","gray1","gray10","gray11","gray12","gray13","gray14","gray15","gray16","gray17","gray18","gray19","gray2","gray20","gray21","gray22","gray23","gray24","gray25","gray26","gray27","gray28","gray29","gray3","gray30","gray31","gray32","gray33","gray34","gray35","gray36","gray37","gray38","gray39","gray4","gray40","gray42","gray43","gray44","gray45","gray46","gray47","gray48","gray49","gray5","gray50","gray51","gray52","gray53","gray54","gray55","gray56","gray57","gray58","gray59","gray6","gray60","gray61","gray62","gray63","gray64","gray65","gray66","gray67","gray68","gray69","gray7"]

chart_data_viz = [{"Label": "market_price_%d" % i, "Color": random.choice(colors)} for i in range(0, model_params["agent_count"])]
happy_chart = ChartModule(chart_data_viz)

server = ModularServer(Schelling,
                       [happy_element, happy_chart],
                       "Schelling", model_params)
server.launch()
Пример #30
0
        portrayal["Color"] = "#007777"
    elif isinstance(agent, DamagedQuiescentCellAgent):
        portrayal["Color"] = "#003333"
    elif isinstance(agent, DeadCell):
        portrayal["Color"] = "#000000" 
    else:
        portrayal["Color"] = "#0000aa" + hex(int(min(agent.C, 1) * 255 / 16))[-1] + hex(int(min(agent.C, 1) * 255 % 16))[-1]
    return portrayal



height = 20
width = 20

grid = CanvasGrid(agent_portrayal, height, width, 500, 500)
chart = ChartModule([{"Label": "MTD",
                      "Color": "Black"}])

model_params = { 
    "height": height,
    "width": width,
    "param_scale": 0.5,
    "kde": UserSettableParameter("slider", "KDE", 0.02, 0., 0.3, 0.001),
    "initial_tumor_size": UserSettableParameter("slider", "initial tumor size", 2, 1, width // 2, 1),
    "first_cycle_offset": UserSettableParameter("slider", "first cycle offset", 80, 1, 200, 1),
    "treatment_cycles": UserSettableParameter("slider", "treatment cycles", 30, 0,50, 1),
    "treatment_cycle_interval": UserSettableParameter("slider", "treatment cycle interval", 4, 1, 200, 1),
#    "proliferative_growth_rate": UserSettableParameter("slider",
#        "proliferative growth rate", 0.121, 0, 1.0, 0.01),
#    "proliferative_to_quiescent_rate": UserSettableParameter("slider",
#        "proliferative to quiescent_rate", 0.03, 0, 1.0, 0.01),
#    "proliferative_elimination_rate": UserSettableParameter("slider",