def visualization_grid(width, height, highS, middleS, lowS, edu_setting=False, cureProb=0.1, cureProbFac=2/1440, mutateProb=0.0050, diseaseRate=0.2): """ Launch grid visualization on server. width: Width of the grid. height: Height of the grid. highS: Number of agents with high sociability. middleS: Number of agents with middle sociability. lowS: Number of agents with low sociability. edu_setting: If true, agents will follow a schedule and sit in classrooms, else they will move freely through an open grid. cureProb: Probability of agent getting better. cureProbFac: Factor of cureProb getting higher. mutateProb: Probability of a disease mutating. diseaseRate: Rate at which the disease spreads """ grid = CanvasGrid(agent_portrayal, width, height, width*10, height*10) server = ModularServer(DiseaseModel, [grid], "Disease Model", {"highS": highS, "middleS": middleS, "lowS": lowS, "width": width, "height": height, "edu_setting": edu_setting, "cureProb": cureProb, "cureProbFac": cureProbFac, "mutateProb": mutateProb, "diseaseRate": diseaseRate}) server.port = 8521 # The default server.launch()
def StartSimulation(fieldSize): grid = CanvasGrid(agent_portrayal, fieldSize, fieldSize, 500, 500) chart = ChartModule([{ "Label": "Suma przeżytych rund każdej jednostki do kosztu całej armii - czerwoni", "Color": "Red" }, { "Label": "Suma przeżytych rund każdej jednostki do kosztu całej armii - niebiescy", "Color": "Blue" }], data_collector_name='datacollector') chart_hp = ChartModule([{ "Label": "Punkty życia armii czerwonej", "Color": "Red" }, { "Label": "Punkty życia armii niebieskiej", "Color": "Blue" }], data_collector_name='datacollector_health') server = ModularServer(Battlefield, [grid, chart, chart_hp], "Draw Model", { "width": fieldSize, "height": fieldSize }) server.port = 8521 # The default server.launch()
def visualize(args): ppd = 8 #pixels per dimension width = 150 height = 140 countR = int(round(height * width / 25 * 3)) # avg 3 Rabits per each 5x5 cells square countF = int(round(height * width / 25 * 1)) # avg 1 Fox per each 5x5 cells square grid = MyCanvasGrid(rabit_portrayal, fox_portrayal, terain_portrayal, width, height, width * ppd, height * ppd) FoxesNr = {"Label": "FoxesNr", "Color": "red"} RabitsNr = {"Label": "RabitsNr", "Color": "blue"} chart_count = ChartModule([FoxesNr, RabitsNr], data_collector_name='datacollector') server = ModularServer( Field, [grid, chart_count], "Rabit VS Fox Model", { "width": width, "height": height, "num_rabits": countR, "num_foxes": countF, "mode": Mode.Visualization, "seed": 999 }) server.port = 8521 # The default server.launch()
def __init__(self, model): #super().__init__(model=model) self.model = model grid = CanvasGrid(self.agent_portrayal, 50, 50, 500, 500) chart = ChartModule([{ "Label": "Emergence", "Color": "Black" }], data_collector_name='datacollector') server = ModularServer(ComplexClusteringModel, visualization_elements=[grid, chart], name="Ant Model", model_params={ "mid": model.middel, "num_ants": model.num_ants, "density_of_particels": model.density_of_particels, "step_size": model.step_size, "jumping_distance": model.jumping_distance, "perceptionRadius": model.perceptionRadius, "particleThreshhold": model.particleThreshhold, "kPlus": model.kPlus, "kMinus": model.kMinus }) server.port = 8525 # The default server.launch() pass
def run(model, parameters, visual, back = False): """ Execute the simulation with visual representation. Args: parameters: Parameters associated with the simulation model and others such as grid size. model: Model that is simulated. visual: JS files with the visualization elements that are included in the JavaScript browser visualization template. back: Python file working as backend visualization. """ backEndVisualization = BackEndVisualization(int(parameters['width']), int(parameters['height']), 500, 500, visual) path = os.path.abspath(soba.__file__) path = path.rsplit('/', 1)[0] local_handler = (r'/local/(.*)', tornado.web.StaticFileHandler, {"path": path}) external_handler = (r'/external/(.*)', tornado.web.StaticFileHandler, {"path": ""}) ModularServer.handlers = ModularServer.handlers[:-1] ModularServer.handlers = ModularServer.handlers + [local_handler] + [external_handler] if back != False: server = ModularServer(model, [backEndVisualization, back], name="Simulation", model_params=parameters) else: server = ModularServer(model, [backEndVisualization], name="Simulation", model_params=parameters) server.port = 7777 server.launch()
def main(): """ The main running function. :return: 0 on success """ ln_slider = UserSettableParameter('slider', "Number of L. Niger Agents", NUM_LNIGER, 0, 300, 1) fj_slider = UserSettableParameter('slider', "Number of F. Japonica Agents", NUM_FJAPON, 0, 300, 1) mk_slider = UserSettableParameter('slider', "Number of M. Kuricola Colonies", NUM_MK_COL, 0, 100, 1) ft_slider = UserSettableParameter('slider', "Number of F. Tropicalis Colonies", NUM_FT_COL, 0, 100, 1) # Instantiate the grid the agents will be moving on grid = CanvasGrid(agent_portrayal, GRID_WIDTH, GRID_HEIGHT, 500, 500) if VISUALIZE_MODEL: # Open the visualization server server = ModularServer( AntModel, [grid], "L. Niger Model", { "num_ln": ln_slider, "num_fj": fj_slider, "num_mk_col": mk_slider, "num_ft_col": ft_slider, "width": GRID_WIDTH, "height": GRID_HEIGHT }) server.port = 8521 server.launch() else: for j in range(NUM_SIMS): sim_time_sum = 0 print("Model Initialization #", str(j)) s = time() model = AntModel(NUM_LNIGER, NUM_FJAPON, NUM_MK_COL, NUM_FT_COL, GRID_WIDTH, GRID_HEIGHT) e = time() sim_time_sum += e - s print(e - s) for i in range(STEP_COUNT): if i % 10 == 0: print(j, "Step", i) s = time() model.step() e = time() sim_time_sum += e - s if i % 10 == 0: print(e - s) print("Model #", str(j), "complete. Total time", str(sim_time_sum)) df = model.data_collector.get_agent_vars_dataframe() df = df.dropna(axis=0) df.to_csv(path_or_buf="raw_new/out" + str(j) + ".csv") return 0
def make_server(graphics_option, server_port=8521): model_label = 'Infectious Disease Simulator' full_display = [ network, SupportTextElement('Title: Mean R0', True), chart_r0, SupportTextElement( 'Title: Daily count of hosts with different disease states', True), chart_all_counts, SupportTextElement( 'Title: Daily count of hosts with different disease states', True), chart_infectious_and_dead, SupportTextElement( 'Title: Daily count of hosts with different test-confirmed disease states', True), chart_infectious_and_dead_test_confirmed, SupportTextElement( 'Title: Rate per 1M for cumulative infectious cases', True), chart_rate_cumulative_infectious, SupportTextElement('Title: Rate per 1M for cumulative dead cases', True), chart_rate_cumulative_dead, SupportTextElement( 'Title: Daily count of infectious hosts with different symptom states', True), chart_infectious_symptom_state, SupportTextElement( 'Title: Daily count of infectious hosts with different clinical service usage', True), chart_clinical_service_use_for_infectious, SupportTextElement( 'Title: Daily count of recovered hosts with different complication states', True), chart_recovered_complication_state, SupportTextElement( 'Title: Daily count of recovered hosts with different clinical service usage', True), chart_clinical_service_use_for_recovered, MainTextElement(), ] if graphics_option is 'default': current_server = ModularServer(HostNetwork, [ network, SupportTextElement(), chart_all_counts, MainTextElement() ], model_label, model_params) elif graphics_option is 'full': current_server = ModularServer(HostNetwork, full_display, model_label, model_params) elif graphics_option is 'full_without_network_graph': current_server = ModularServer(HostNetwork, full_display[1:], model_label, model_params) elif graphics_option is 'text_only': current_server = ModularServer(HostNetwork, [MainTextElement()], model_label, model_params) current_server.port = server_port return current_server
def launch_basic(): width = 15 height = 10 num_agents = 2 pixel_ratio = 50 grid = CanvasGrid(agent_draw, width, height, width * pixel_ratio, height * pixel_ratio) server = ModularServer(ShapesModel, [grid], "Basic Example", num_agents, width, height) server.max_steps = 0 server.port = 8888 server.launch()
def dynamic_run(params: dict): if params['show_grid']: # visual grid on which agents move grid = CanvasGrid(agent_portrayal, params['grid_width'], params['grid_height'], 500, 500) visualization_elements.insert(0, grid) server = ModularServer(InfectionModel, visualization_elements, "Infection Model", {"params": params}) server.port = 8521 server.launch()
def launch_shape_model(): width = 15 height = 10 num_agents = 2 pixel_ratio = 50 grid = CanvasGrid(agent_draw, width, height, width * pixel_ratio, height * pixel_ratio) server = ModularServer(ShapeExample, [grid], "Shape Model Example", {"N": num_agents, "width": width, "height": height}) server.max_steps = 0 server.port = 8521 server.launch()
def __init__(self, model): # super().__init__(model=model) grid = CanvasGrid(self.agent_portrayal, 50, 50, 500, 500) server = ModularServer(SimpleClusteringModel, visualization_elements=[grid], name="Ant Model", model_params={"mid": model.middel, "num_ants": model.num_ants, "density_of_particels": model.density_of_particels, "step_size": model.step_size, "jumping_distance": model.jumping_distance}) server.port = 8525 # The default server.launch() pass
def launch_shape_model(): width = 15 height = 10 num_agents = 2 pixel_ratio = 50 grid = CanvasGrid(agent_draw, width, height, width * pixel_ratio, height * pixel_ratio) server = ModularServer(ShapesModel, [grid], "Shape Model Example", num_agents, width, height) server.max_steps = 0 server.port = 8521 server.launch()
def viz_run(width, height, elev_cells, veg_cells, tracking_type): grid = CanvasGrid(agent_portrayal, width, height, 1200, 900) chart = ChartModule([{"Label": "Pack Health", "Color": "Black"}], canvas_height=200, canvas_width=500, data_collector_name='datacollector') chart2 = ChartModule([{"Label": "Pack Average Track Error", "Color": "Black"}], canvas_height=200, canvas_width=500, data_collector_name='datacollector') server = ModularServer(WolfModel, [grid, chart, chart2], "WolfSim", {"N": 25, "width": width, "height": height, "elev": elev_cells, "veg": veg_cells, "tracking_type": tracking_type}) server.port = 8520 # The defaul server.launch()
def main(): network = NetworkModule(network_portrayal, 500, 500, library='d3') N = 10 percInfect = 0.5 percRecover = 0.25 server = ModularServer(DiseaseModel, [network], "Disease Model", { "N": N, "percInfect": percInfect, "percRecover": percRecover }) server.port = 8521 # The default server.launch()
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()
def launch_shape_model(): width = 50 height = 17 num_agents = 2 pixel_ratio = 10 grid = CanvasGrid(agent_draw, width, height, width * pixel_ratio, height * pixel_ratio) server = ModularServer(ShapesModel, [grid], "Shape Model Example", model_params={ 'N': num_agents, 'width': width, 'height': height }) server.max_steps = 0 server.port = 8888 server.launch()
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", {'num_agents': 1000, 'x_size': x_size, 'y_size': y_size}) server.port = 8534 # change this number if address is in use server.launch()
def run_interactive_visualization(model, model_params, agent_portrayal, grid_width, grid_height, pixel_width=500, pixel_height=500, additional_modules=[], port=8531, title="SynBioSoc ABM"): grid = CanvasGrid(agent_portrayal, grid_width, grid_height, canvas_width=pixel_width, canvas_height=pixel_height) modules = [grid] modules.extend(additional_modules) server = ModularServer(model, modules, title, model_params) server.port = port server.launch()
def run(configuration, seed=None): """ Run the mesa server :param configuration: configuration used by the model. :param seed: random seed. By default None. """ """ to get results for multiple iterations, run underlying code and add this to default.json in configurations: "inf_threshold": 50, "active_threshold_t": 0.5, "graph_type": "GraphType.ERDOS_RENYI.name" """ #batch_run = BatchRunner(CivilViolenceModel, fixed_parameters = config, iterations = 10) #batch_run.run_all() #data = batch_run.get_model_vars_dataframe() #data.head() random.seed(seed) model_params = get_user_model_parameters() # By updating model_params with configuration after getting the user settable parameters, # it let us provide fixed values for our model which won't be overwritten by the user choice. # Just remove attribute from the configuration file to get user interface back. model_params.update( configuration ) # Overwritten user parameters don't appear in the graphic interface model_params.update({'seed': seed}) server = ModularServer(CivilViolenceModel, get_visualization_elements(model_params, show_network=False), name="Civil violence with network model", model_params=model_params) print(model_params) server.port = 8521 server.launch()
''' kapital_households_chart = ChartModule([{ "Label": "KapitalH", "Color": "Blue" }], data_collector_name="datacollector") rate_chart = ChartModule([{ "Label": "Rate", "Color": "Black" }], data_collector_name="sinu_datacollector") kapital_households_global_chart = ChartModule( [{ "Label": "KapitalG", "Color": "Red" }], data_collector_name="datacollector") server2 = ModularServer( SinuModel, [kapital_households_chart, kapital_households_global_chart, rate_chart], "SinuModel", { "n_households": 20, "df3": 'pfebtc.xlsx', "list_kapital_global": btc_model.kapital_global_btcModel }) server2.port = 8524 #The default server2.launch()
evacueesChart = ChartModule([{ "Label": "Evacuees", "Color": "Red" }], data_collector_name='data_collector') evacuatedChart = ChartModule([{ "Label": "Evacuated", "Color": "Green" }], data_collector_name='data_collector') grid = CanvasGrid(agent_portrayal, 27, 27, 500, 500) element_list = [grid, evacueesChart, evacuatedChart] server = ModularServer(EvacuationModel, element_list, "Evacuation Model", { "N": 250, "width": 27, "height": 27 }) ''' server = ModularServer(EvacuationModel, [grid], "Evacuation Model", {"N":1, "width":11, "height":11}) ''' server.port = 8422 # The default server.launch()
portrayal = { "Shape": "circle", "Color": "red", "Filled": "true", "Layer": 0, "r": 0.5 } return portrayal # Grid dimension WIDTH, HEIGHT = 500, 500 # Grid squaring nb_square_x, nb_square_y = 10, 10 grid = CanvasGrid(agent_portrayal, nb_square_x, nb_square_y, WIDTH, HEIGHT) # Initialize grid server = ModularServer( CivModel, # Initialize Server for Model "CivModel" [grid], # Print grids "Dark Forest Model", # Title { "N": 5, "width": 10, "height": 10 }) # Declare CivModel arguments server.port = 8521 # Set port server.launch()
agents[0].wealth), } for (node_id, agents) in G.nodes.data('agent')] portrayal['edges'] = [{'id': edge_id, 'source': source, 'target': target, 'color': '#000000', } for edge_id, (source, target) in enumerate(G.edges)] return portrayal grid = NetworkModule(network_portrayal, 500, 500, library='sigma') chart = ChartModule([ {"Label": "Gini", "Color": "Black"}], data_collector_name='datacollector' ) model_params = { "num_agents": UserSettableParameter('slider', "Number of agents", 7, 2, 10, 1, description="Choose how many agents to include in the model"), "num_nodes": UserSettableParameter('slider', "Number of nodes", 10, 3, 12, 1, description="Choose how many nodes to include in the model, with at " "least the same number of agents") } server = ModularServer(BoltzmannWealthModelNetwork, [grid, chart], "Money Model", model_params) server.port = 8521
"r": 3, "Filled": "true", "Color": "Blue" } elif agent.airport_type == "Closed": return { "Shape": "circle", "r": 3, "Filled": "true", "Color": "Grey" } else: raise Exception("Airport is neither origin or destination") else: raise Exception("Trying to display an agent of unknown type") # Makes a canvas of 500x500 pixels. Increasing or decreasing canvas size should # not affect results - only visualization. formation_canvas = SimpleCanvas(boid_draw, 1000, 1000) chart = ChartModule([{ "Label": "Total Fuel Used", "Color": "Black" }], data_collector_name='datacollector') server = ModularServer(FormationFlying, [formation_canvas, chart], "Formations", model_params) server.port = random.randrange(8500, 9000) server.launch()
from mesa.visualization.ModularVisualization import ModularServer from gini import MoneyModel def agent_portrayal(agent): portrayal = {"Shape": "circle", "Filled": "true", "r": 0.5} if agent.wealth > 0: portrayal["Color"] = "red" portrayal["Layer"] = 0 else: portrayal["Color"] = "grey" portrayal["Layer"] = 1 portrayal["r"] = 0.2 return portrayal grid = CanvasGrid(agent_portrayal, 10, 10, 500, 500) chart = ChartModule([{"Label": "Gini", "Color": "Black"}], data_collector_name='datacollector') server = ModularServer(MoneyModel, [grid, chart], "Money Model", {"N": 100, "width": 10, "height": 10}) server.port = 8522 # The default server.launch()
def run_visual(): def network_portrayal(G): portrayal = dict() portrayal["nodes"] = [] for n in G.nodes.data(): portrayal["nodes"].append({ "size": node_size_based_on_crowd(n), "color": n[1]["color"], }) portrayal["edges"] = [] for source, target in G.edges: portrayal["edges"].append({ "source": source, "target": target, "color": "black", "width": 1, }) return portrayal class Time(TextElement): def render(self, model): time = model.date return str(time) network = NetworkModule(network_portrayal, 800, 800, library="d3") chart = ChartModule([{ "Label": "infected", "Color": "Green" }, { "Label": "healthy", "Color": "Red" }, { "Label": "recovered", "Color": "Blue" }], data_collector_name='datacollector') model_params = { "p_nodes": UserSettableParameter("number", "prob nodes", value=0.04), "healthy_N": UserSettableParameter("slider", "amount healthy", 95, 1, 500), "sick_N": UserSettableParameter("slider", "amount sick", 5, 1, 500), "altruism": UserSettableParameter("slider", "altruism", 10, 1, 100), "infect_score_lower": UserSettableParameter("slider", "infect_score_lower", -40, -100, 100, 10), "infect_score_upper": UserSettableParameter("slider", "infect_score_upper", -20, -100, 100) } model_params["network_params"] = [ (model_params["healthy_N"].value + model_params["sick_N"].value, "House", "Grey"), (15, "Work", "yellow"), (5, "School", "green"), (3, "Shop", "Brown"), (3, "Bar", "Brown"), (3, "Park", "Brown"), (1, "University", "Red") ] server = ModularServer(BaseModel, [network, Time(), chart], "Infected model", model_params) server.port = 8521 # The default server.launch()
[{"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, step=1), "r_criminal_generators": UserSettableParameter('slider', 'Radius of the Criminal Generator Area', value=4, min_value=0, max_value=8, step=1), "max_cp": UserSettableParameter('slider', 'Upper Bound on Criminal Preference of Offenders', value=0.5, min_value=0, max_value=1, step=0.01), "pop_count": 0, "height": 50, "width": 50 } server = ModularServer(Model, [grid, chart1, chart2], "Violent Crime when Walking Home Alone at Night", model_params) server.port = 8002 server.launch()
portrayal["Layer"] = 2 portrayal["Shape"] = "rect" elif type(agent) is IsraelRear: color = ISRAEL_REAR_COLOR portrayal["Color"] = color size = 1.0 portrayal["r"] = portrayal["w"] = portrayal["h"] = size portrayal["Layer"] = 3 portrayal["Shape"] = "rect" return portrayal canvas_element = SeparationBarrierGrid(israeli_palestinian_portrayl, 40, 40, 600, 600) greed = 4 server = ModularServer(SeparationBarrierModel, [canvas_element], "Separation Barrier - Greed Level %d" % (greed), height=40, width=40, settlement_density = 0.3, palestinian_density = 0.2, settlers_violence_rate = 0.01, settler_vision = 5, palestinian_vision = 5, settlers_growth_rate = 0.01, suicide_rate = 0.001, greed_level=greed, ) server.port = 6666 server.launch()
else: portrayal["Color"] = "grey" portrayal["Layer"] = 1 portrayal["r"] = 0.2 return portrayal # canvas grid with dimensions 10 x 10, drawn in 500 x 500 pixels grid = CanvasGrid(agent_portrayal, 10, 10, 500, 500) # plot gini chart = ChartModule([{ "Label": "Gini", "Color": "black" }], data_collector_name="datacollector") # user-definable number of agents # parameter changes don't take place until the model is reset n_slider = UserSettableParameter("slider", "Number of Agents", 100, 2, 200, 1) # create server server = ModularServer(MoneyModel, [grid, chart], "Money Model", { "N": n_slider, "width": 10, "height": 10 }) server.port = 8521 # default server.launch()
# (Un)masked agents show up as (non-)filled circles if agent.masked == True: portrayal['Filled'] = 'true' if agent.infected == True: portrayal['Color'] = 'red' if agent.immune == True: portrayal['Color'] = 'green' return portrayal grid = CanvasGrid(agent_portrayal, 50, 50, 500, 500) line_charts = ChartModule([{ 'Label': 'Susceptible', 'Color': 'lightblue' }, { 'Label': 'Infected', 'Color': 'red' }, { 'Label': 'Recovered & Immune', 'Color': 'green' }]) server = ModularServer(CovidModel, [grid, line_charts], 'COVID Simulation Model', model_params) server.port = 8521 # default port if unspecified server.launch()
else: portrayal["Color"] = "blue" portrayal["Layer"] = 0 if not agent.alive: portrayal["Color"] = "black" portrayal["Layer"] = 0 return portrayal grid = CanvasGrid(agent_portrayal, sim_params.get('grid_x'), sim_params.get('grid_y'), sim_params.get('grid_x') * 4, sim_params.get('grid_y') * 4) chart = ChartModule([{ "Label": "Infected", "Color": "Red" }, { "Label": "Immune", "Color": "Green" }, { "Label": "Deaths", "Color": "Black" }], data_collector_name='datacollector') server = ModularServer(Simulation, [grid, chart], "COVID-19 Model", {"params": sim_params}) server.port = 8521 # The default server.launch()
from mesa.visualization.modules import CanvasGrid from mesa.visualization.modules import ChartModule from mesa.visualization.ModularVisualization import ModularServer from MoneyModel import MoneyModel def agent_portrayal(agent): portrayal = {"Shape": "circle", "Filled": "true", "r": 0.5} if agent.wealth > 0: portrayal["Color"] = "red" portrayal["Layer"] = 0 else: portrayal["Color"] = "grey" portrayal["Layer"] = 1 portrayal["r"] = 0.2 return portrayal grid = CanvasGrid(agent_portrayal, 10, 10, 500, 500) chart = ChartModule([ {"Label": "Gini", "Color": "Black"}], data_collector_name='datacollector' ) server = ModularServer(MoneyModel, [grid, chart], "Money Model", 100, 10, 10) server.port = 8888 server.launch()
UserSettableParameter( "slider", "Academic sector opinion", 0, -1, 1, 1, description="Opinion of academic sector stakeholder."), "civil_opinion": UserSettableParameter("slider", "Civil society opinion", 0, -1, 1, 1, description="Opinion of civil society stakeholder."), "media_opinion": UserSettableParameter("slider", "Media industry opinion", 0, -1, 1, 1, description="Opinion of media industry stakeholder.") } # create server server = ModularServer(SEmodel, [network, MyTextElement(), chart], "Stakeholder Engagement Model", model_parameters) server.port = 8518 # default port
def getFridgeTableValues(model): return list( map(lambda fridge: fridge.contents.copy(), model.fridges.copy())) + [model.truck.loadProductAmounts()] def getFridgeTableFormatings(model): return [{ "color": color } for color in colors] + [{ "color": "Black", "bold": True }] class DaysCounter(TextElement): def render(self, model): return "Days: %d" % model.schedule.days grid = CanvasGrid(agentPortrayal, 20, 20, 500, 500) fridgesStates = TableVisualization(getFridgeTableHeader, getFridgeTableValues, getFridgeTableFormatings) daysCounter = DaysCounter() server = ModularServer(FoodSupplyModel, [grid, fridgesStates, daysCounter], "Food supply model", 10, 20, 20) server.port = 8889 server.launch()
"Color": "#0000FF" }, { "Label": "netflix", "Color": "#FF0000" }, { "Label": "disneyplus", "Color": "#00FF00" } #{"Label": "appletv", "Color": "#000000"} ]) model_params = { "quality_amazonprime": UserSettableParameter('slider', 'Quality amazonprime', 25, 1, 100, 1), "quality_netflix": UserSettableParameter('slider', 'Quality netflix', 50, 1, 100, 1), "quality_disneyplus": UserSettableParameter('slider', 'Quality disneyplus', 15, 1, 100, 1), "content_amazonprime": UserSettableParameter('slider', 'Content amazonprime', 15, 1, 100, 1), "content_netflix": UserSettableParameter('slider', 'Content netflix', 5, 1, 100, 1), "content_disneyplus": UserSettableParameter('slider', 'Content disneyplus', 7, 1, 100, 1) #"initial_appletv": UserSettableParameter('slider', 'Initial appletv', 10, 1, 100, 1) } server = ModularServer(market, [canvas_element, chart_element], "DIgital TV Effect", model_params) server.port = 8521
def agent_portrayal(agent): portrayal = {"Shape": "circle", "Filled": "true", "r": 0.5} if agent.wealth > 0: portrayal["Color"] = "green" portrayal["Layer"] = 0 else: portrayal["Color"] = "red" portrayal["Layer"] = 1 portrayal["r"] = 0.5 return portrayal grid = CanvasGrid(agent_portrayal, 100, 100, 512, 512) chart1 = ChartModule([{"Label": "Coverage", "Color": "#0000FF"}], data_collector_name='datacollector') model_params = { "N": UserSettableParameter('slider', "Number of agents", 16, 1, 200, 1, description="Choose how many agents to include in the model"), "width": 100, "height": 100 } #server = ModularServer(MoniModel, [grid, chart], "Money Model", model_params) server = ModularServer(MoniModel, [grid], "Monitoring pattern", model_params) server.port = 8426 server.launch()