Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_app(self):
app = ModularServer(Model, [])
return app
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], "Wealth Model", { "N" : economy_scale*economy_scale, "width" : economy_scale, "height" : economy_scale} )
server.port = 8521
server.launch()
"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
server = ModularServer(BankReserves, [canvas_element, chart_element],
"Bank Reserves Model",
model_params=model_params
)
def main(x_size, y_size):
""" This function sets up a canvas to graphically represent the model 'MoneyModel'
and a chart, than it runs the server and runs the model in model.py in the browser """
grid = CanvasGrid(agent_portrayal, x_size, y_size, 500, 500)
chart = ChartModule([{"Label": "Gini",
"Color": "Black"}],
data_collector_name='datacollector')
# the simulation uses a class DataCollector, that collects the data and
# relays it from self.datacollector to the webpage
server = ModularServer(MoneyModel,
[grid, chart],
"ABCE and MESA integrated",
x_size * y_size, x_size, y_size)
server.port = 8534 # change this number if address is in use
server.launch()
description='Avg Node Degree'),
'initial_outbreak_size': UserSettableParameter('slider', 'Initial Outbreak Size', 1, 1, 10, 1,
description='Initial Outbreak Size'),
'virus_spread_chance': UserSettableParameter('slider', 'Virus Spread Chance', 0.4, 0.0, 1.0, 0.1,
description='Probability that susceptible neighbor will be infected'),
'virus_check_frequency': UserSettableParameter('slider', 'Virus Check Frequency', 0.4, 0.0, 1.0, 0.1,
description='Frequency the nodes check whether they are infected by '
'a virus'),
'recovery_chance': UserSettableParameter('slider', 'Recovery Chance', 0.3, 0.0, 1.0, 0.1,
description='Probability that the virus will be removed'),
'gain_resistance_chance': UserSettableParameter('slider', 'Gain Resistance Chance', 0.5, 0.0, 1.0, 0.1,
description='Probability that a recovered agent will become '
'resistant to this virus in the future'),
}
server = ModularServer(VirusOnNetwork, [network, MyTextElement(), chart], 'Virus Model', model_params)
server.port = 8521
def main(x_size, y_size):
""" This function sets up a canvas to graphically represent the model 'MoneyModel'
and a chart, than it runs the server and runs the model in model.py in the browser """
grid = CanvasGrid(agent_portrayal, x_size, y_size, 500, 500)
chart = ChartModule([{"Label": "Gini",
"Color": "Black"}],
data_collector_name='datacollector')
# the simulation uses a class DataCollector, that collects the data and
# relays it from self.datacollector to the webpage
server = ModularServer(MoneyModel,
[grid, chart],
"abcEconomics and MESA integrated",
x_size * y_size, x_size, y_size)
server.port = 8534 # change this number if address is in use
server.launch()
portrayal = {"Shape": "circle", "r": 0.5, "Filled": "true", "Layer": 0}
if agent.type == 0:
portrayal["Color"] = "Red"
else:
portrayal["Color"] = "Blue"
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": 0.8,
#"minority_pc": 0.2,
"minority_pc": UserParam("minority_pc", 0.2, 0, 1.0, 0.1),
"homophily": UserParam("homophily", 4, 1, 8, 1)}
server = ModularServer(SchellingModel,
[canvas_element, happy_element, happy_chart],
"Schelling", model_params)
server.launch()
grid = CanvasGrid(agent_portrayal, 10, 10, 500, 500)
chart = ChartModule([
{"Label": "Gini", "Color": "#0000FF"}],
data_collector_name='datacollector'
)
model_params = {
"N": UserSettableParameter('slider', "Number of agents", 100, 2, 200, 1,
description="Choose how many agents to include in the model"),
"width": 10,
"height": 10
}
server = ModularServer(BoltzmannWealthModel, [grid, chart], "Money Model", model_params)
server.port = 8521
from court.model import CourtModel
chart1 = ChartModule([
{"Label": "successful", "Color": "#7bb36e"},{"Label": "failed", "Color": "#c66657"},{"Label": "total", "Color": "#56bfdf"}],
data_collector_name='datacollector',
canvas_height=300, canvas_width=300
)
chart2 = ChartModule([
{"Label": "Gini", "Color": "#56bfdf"}],
data_collector_name='datacollector',
canvas_height=300, canvas_width=300
)
server = ModularServer(
CourtModel,
[chart1,chart2],
name="CourtModel",
model_params={
"juror_count": UserSettableParameter('slider', "Number of jurors", 20, 10, 100, 1,
description="Choose how many Juror agents to include in the model"),
"token_count": UserSettableParameter('slider', "Number of tokens", 40, 10, 400, 1,
description="Choose how many tokens in supply, tokens are split evenly among jurors at initialization."),
"threshold": UserSettableParameter('slider', "Belief Threshold", 1, 0.25, 5, 0.25,
description="Agents must sample within this many standard deviations from the true value to be coherent"),
"penalty_pct": UserSettableParameter('slider', "Dispensation Percentage", 0.1, 0.01, 1, 0.01,
description="Percentage of activated tokens which are redistributed from incoherent jurors to coherent")
})
server.port = 8521
server.launch()
from mesa.visualization.ModularVisualization import ModularServer
from .model import BoidModel
from .SimpleContinuousModule import SimpleCanvas
def boid_draw(agent):
return {"Shape": "circle", "r": 2, "Filled": "true", "Color": "Red"}
boid_canvas = SimpleCanvas(boid_draw, 500, 500)
model_params = dict(N=100, width=100, height=100, speed=5,
vision=10, separation=2)
server = ModularServer(BoidModel, [boid_canvas], "Boids", model_params)
server.launch()