Exemple #1
0
    def __init__(self, n_doctors=3, n_init_arg=5, experiment_case=1):
        self.n_init_arg = n_init_arg

        # Create a line chart tracking avg_belief for all the initial arguments
        list_var = []
        for i in range(self.n_init_arg):
            dict = {"Label": ARGUMENT_NAMES[i], "Color": COLORS[i]}
            list_var.append(dict)
        avg_belief_line_chart = ChartModule(list_var)

        # Create a line chart tracking the committee decision progress
        list_var = []
        for i, disease in enumerate(MedicalModel.LIST_OF_DISEASES.values()):
            dict = {"Label": disease, "Color": COLORS[i]}
            list_var.append(dict)
        disease_line_chart = ChartModule(list_var)

        # Create bar chart to display the agents belief arrays
        list_var = []
        for i in range(self.n_init_arg):
            dict = {"Label": ARGUMENT_NAMES[i], "Color": COLORS[i]}
            list_var.append(dict)
        bar_chart = BarChartModule(list_var, scope="agent")

        diagnosis = PrintedDiagnosis()

        legend_belief_array = LegendElement(
            '<font size="5"><b>1. </b></font> The graph below displays the belief '
            'array for each of the doctors (e.g. Doctor 0, Doctor 1..)')
        legend_conclusion = LegendElement(
            '<font size="5"><b>2. </b></font> The graph below displays the probability '
            'of the committee in each conclusion.')
        legend_avg_belief = LegendElement(
            'The graph below represents the average belief between all doctors '
            'for each of the possible arguments')

        list_of_visualizations = [
            legend_belief_array, bar_chart, legend_conclusion,
            disease_line_chart, diagnosis, legend_avg_belief,
            avg_belief_line_chart
        ]
        model_legend = """<h1>Default Case Scenario.</h1><br><h3>The initial set of arguments is the 
        following:</h3><br>
        """
        for arg_name, arg_idx in MedicalModel.LIST_OF_ARGUMENTS.items():
            model_legend += "<b>" + arg_name + "</b>" + ": " + arg_idx + "<br>"

        model_params = {
            "Legend": UserSettableParameter('static_text', value=model_legend),
            "N": n_doctors,
            "n_init_arg": n_init_arg,
            "experiment_case": experiment_case
        }
        # Create server
        self.server = ModularServer(MedicalModel, list_of_visualizations,
                                    "ABM medical diagnosis", model_params)
        self.server.port = 8521
Exemple #2
0
        "Label": "Poor",
        "Color": POOR_COLOR
    },
    {
        "Label": "Middle Class",
        "Color": MID_COLOR
    },
])

model_bar = BarChartModule([
    {
        "Label": "Rich",
        "Color": RICH_COLOR
    },
    {
        "Label": "Poor",
        "Color": POOR_COLOR
    },
    {
        "Label": "Middle Class",
        "Color": MID_COLOR
    },
])

agent_bar = BarChartModule(
    [{
        "Label": "Wealth",
        "Color": MID_COLOR
    }],
    scope="agent",
    sorting="ascending",
    sort_by="Wealth",
Exemple #3
0
}],
                              data_collector_name='datacollector')

chartConsumidores = ChartModule([{
    "Label": "Gini",
    "Color": "#18496D"
}, {
    "Label": "S80/S20",
    "Color": "#A43DC6"
}, {
    "Label": "Consumidores",
    "Color": "#993599"
}],
                                data_collector_name='datacollector')

agent_bar = BarChartModule(
    fields=[{
        "Label": "Ingreso total",
        "Color": "#4CCE59"
    }],
    scope="agent",
    sorting="ascending",
    sort_by="ingreso_total",
)

server = ModularServer(
    EconomiaSocialista,
    [chartGini, chartGiniS80S20, chartConsumidores, agent_bar],
    "Economia socialista", model_params)
server.port = 8521  # The default
server.launch()
Exemple #4
0
xCollectors = list()
yCollectors = list()

# Loop to create bars for bar graphs
coord = 0
for x in range(masterHeight):
    xCollectors.append({"Label": ("x: " + str(coord)), "Color": "#85c6e7"})
    coord += 1

coord = 0
for y in range(masterWidth):
    yCollectors.append({"Label": ("y: " + str(coord)), "Color": "#85c6e7"})
    coord += 1

# Create a bar charts to represent column and row amounts of relative to grid
bar_chart_element_col = BarChartModule(xCollectors, canvas_width=550)
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":
Exemple #5
0
import math

from mesa.visualization.ModularVisualization import ModularServer
from mesa.visualization.UserParam import UserSettableParameter
from mesa.visualization.modules import BarChartModule, NetworkModule
from .model import WasteNet
from .enums import WasteNetMode
from .visualization import network_portrayal, level_fields, ResultsElement


network = NetworkModule(network_portrayal, 400, 500, library="d3")
barchart = BarChartModule(level_fields, canvas_width=500, scope="agent")
text = ResultsElement()


model_params = {
    "mode": UserSettableParameter(
        "choice",
        "Agent Mode",
        value=WasteNetMode.COMPLETE.name,
        choices=WasteNetMode.names(),
    ),
    "nb_episodes": UserSettableParameter(
        "slider",
        "Number of Episodes",
        value=1,
        min_value=1,
        max_value=2000,
        step=1,
    ),
}
Exemple #6
0
        portrayal["r"] = 0.5
        portrayal["text"] = str(agent.unique_id)
        portrayal["text_color"] = "black"
        if (agent.status != Status.Comeback and agent.status != Status.Loading and agent.status != Status.Free):
            portrayal["Color"] = "blue"
        elif (agent.status == Status.Loading):
            portrayal["Color"] = "orange"
        else:
            portrayal["Color"] = "yellow"
    return portrayal


grid = CanvasGrid(agent_portrayal, 10, 10, 800, 800)
total_moving_step_graph = BarChartModule(
    [{"Label": "Total_Moving_Seconds", "Color": "Red"}],
    scope="agent",
    data_collector_name='data_collector'
)

total_working_step_graph = BarChartModule(
    [{"Label": "Total_Working_Seconds", "Color": "Red"}],
    scope="agent",
    data_collector_name='data_collector'
)

total_waiting_step_graph = BarChartModule(
    [{"Label": "Total_Waiting_Seconds", "Color": "Red"}],
    scope="agent",
    data_collector_name='data_collector'
)
Exemple #7
0
    "Color": "orange"
}, {
    "Label": "Strategies Min Score",
    "Color": "blue"
}],
                              data_collector_name='datacollector')

fluctuation_chart = ChartModule([{
    "Label": "Fluctuation",
    "Color": "purple"
}],
                                data_collector_name='datacollector')

agent_bar = BarChartModule([{
    "Label": "Wealth",
    "Color": "blue"
}],
                           scope="agent")

producer_pie_chart = PieChartModule([{
    "Label": "Good Producer",
    "Color": "red"
}, {
    "Label": "Bad Producer",
    "Color": "green"
}])

speculator_pie_chart = PieChartModule([{
    "Label": "Good Speculator",
    "Color": "red"
}, {
Exemple #8
0
    "Label": "min_elo",
    "Color": "Black"
}],
                            data_collector_name='datacollector')

# Bar Charts
rank_pop_chart = BarChartModule([{
    "Label": "rank_zero_pop",
    "Color": _COLORS[0]
}, {
    "Label": "rank_one_pop",
    "Color": _COLORS[1]
}, {
    "Label": "rank_two_pop",
    "Color": _COLORS[2]
}, {
    "Label": "rank_three_pop",
    "Color": _COLORS[3]
}, {
    "Label": "rank_four_pop",
    "Color": _COLORS[4]
}],
                                canvas_height=250,
                                canvas_width=500,
                                scope='model')

# Sliders
init_elo = UserSettableParameter('slider', 'Initial ELO Rating', 1500, 10,
                                 3000, 10)
n_agents = UserSettableParameter('slider', 'Number of Agents', 500, 2, 2000, 5)
Exemple #9
0
overcrowding_threshold = 60
# tamanho do grid definido em função do número de pessoas
grid_size = round(2 * round(math.sqrt(number_persons)))

crowded_element = CrowdedElement()
reward_element = RewardElement()
# 500 é o tamanho do grid em pixels
grid = CanvasGrid(agent_portrayal, grid_size, grid_size, 500, 500)
chart = ChartModule([{"Label": "Attendance", "Color": "Black"}])
# esse histograma mostra o valor das recompensas de cada agente
# a extensão três do NetLogo, diferentemente, mostra quantos agentes têm
# determinado valro de recompensas, do mínimo ao máximo
hist_agents_reward = BarChartModule([{
    "Label": "Reward",
    "Color": "Black"
}],
                                    scope="agent",
                                    sorting="ascending",
                                    sort_by="unique_id")

# TERCEIRA EXTENSÃO
# tentativa de criar um histograma como o do NetLogo, mas aparentemente
# não é trivial; os valores a exibir não podem ser listas ou arrays;
# assim, optei por fixar em 5 o número de segmentos do histograma, mas isso
# aparentemente não é parametrizável e, portanto, não é uma boa solução
hist_reward_agents = BarChartModule([{
    "Label": "Bin0",
    "Color": "Blue"
}, {
    "Label": "Bin1",
    "Color": "Blue"