Exemplo n.º 1
0
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()
Exemplo n.º 2
0
                           'label': None if not agents else 'Agent:{} Trolling Delta:{} Total: {}'.format(agents[0].unique_id,
                                                                                        agents[0].trolling_received_snapshot, agents[0].trolling_received),
                            }
                          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": "Average Delta Trolling", "Color": "Black"}],
    data_collector_name='datacollector'
)


model_params = {
    "num_agents": UserSettableParameter('slider', "Number of agents", 50, 0, 100, 10,
                                        description="Choose how many total agents to include in the model"),
    "percent_trolls": UserSettableParameter('slider', "Percent trolls", .1, 0, 1.0, 0.05,
                                       description="Choose what percent trolls to include in the model"),
    "percent_mods": UserSettableParameter('slider', "Percent mods", .2, 0, 1.0, 0.05,
                                       description="Choose what percent mods to include in the model")
}
Exemplo n.º 3
0
        "tooltip":
        "id: {}<br>opinion: {}".format(agents[0].unique_id, agents[0].opinion)
    } for (_, agents) in G.nodes.data("agent")]

    portrayal["edges"] = [{
        "source": source,
        "target": target,
        "color": edge_color(*get_edges(source, target)),
        "width": edge_width(*get_edges(source, target))
    } for (source, target) in G.edges]

    return portrayal


# instantiate network module
network = NetworkModule(network_portrayal, 500, 500, library="d3")

# map data to chart in the ChartModule
chart = ChartModule([{
    "Label": "Neutral",
    'Color': neutral_color
}, {
    "Label": "Negative",
    'Color': negative_color
}, {
    "Label": "Positive",
    'Color': positive_color
}])


class MyTextElement(TextElement):
Exemplo n.º 4
0
        'color': '#CC0000',
        'label': 'Bank{}'.format(node_id),
    } for node_id in G.node]

    portrayal['edges'] = [{
        'id': edge_id,
        'source': source,
        'target': target,
        'color': '#000000',
    } for edge_id, (source, target) in enumerate(G.edges)]

    return portrayal


canvas_network = NetworkModule(mesa_abba_network_portrayal,
                               500,
                               600,
                               library='sigma')
chart_element = ChartModule([{"Label": "BankAsset", "Color": "#AA0000"}])

model_params = {
    "write_db":
    UserSettableParameter("checkbox", 'Write DB', value=True),
    "max_steps":
    UserSettableParameter("slider", "Max steps", 20, 10, 200, 1),
    "initial_saver":
    UserSettableParameter("slider", "# of Saver", 10000, 10000, 20000, 100),
    "initial_bank":
    UserSettableParameter("slider", "# of Bank", 10, 10, 20, 1),
    "initial_loan":
    UserSettableParameter("slider", "# of Loan", 20000, 10000, 30000, 100),
    "initial_equity":
        'tooltip':
        "id: {}<br>state: {}".format(agents[0].unique_id,
                                     agents[0].disease_health_state.name),
    } for (_, agents) in G.nodes.data('agent')]

    portrayal['edges'] = [{
        'source': source,
        'target': target,
        'color': edge_color(*get_agents(source, target)),
        'width': edge_width(*get_agents(source, target)),
    } for (source, target) in G.edges]

    return portrayal


network = NetworkModule(network_portrayal, 700, 730, library='d3')

chart_all_counts = ChartModule([
    {
        'Label': 'Susceptible',
        'Color': '#008000'
    },
    {
        'Label': 'Infectious',
        'Color': '#FF0000'
    },
    {
        'Label': 'Recovered',
        'Color': '#00C5CD'
    },
    {
Exemplo n.º 6
0
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()
Exemplo n.º 7
0
    elif type(agent) is FindRoadHoomin or type(agent) is SocialHoomin:
        portrayal["Shape"] = "realhoomin/resources/base_hoomin.png"
        portrayal["scale"] = 0.9
        portrayal["Layer"] = 1

    elif type(agent) is Home:
        portrayal["Shape"] = "realhoomin/resources/home.png"
        portrayal["scale"] = 1.5
        portrayal["Layer"] = 0

    return portrayal


canvas_element = CanvasGrid(hoomin_portrayal, settings.width, settings.height,
                            500, 500)
chart_element = ChartModule([{
    "Label": "Messages Exchanged",
    "Color": "#CACACA"
}, {
    "Label": "FriendGraph Node Count",
    "Color": "#FF0000"
}])

friendgraph = NetworkModule(friendgraph_portrayal, 50, 50, library='d3')

model_params = {}
server = ModularServer(HoominWorld, [canvas_element, chart_element],
                       "Hoomin World", model_params)
server.port = 8083
Exemplo n.º 8
0
    } for (source, target) in G.edges]

    return portrayal


class JournalElement(TextElement):
    def __init__(self):
        pass

    def render(self, model):
        return "<h3>Journal</h3>" + "<br/>".join(model.journal)


network = NetworkModule(network_portrayal,
                        500,
                        889,
                        canvas_background="/assets/images/map889x500.jpg",
                        library='d3')
journal = JournalElement()
# armies_line = ChartModule([{"Label": "Armies", "Color": "Black"}, {"Label": "Cards", "Color": "Red"}, {"Label": "Trash", "Color": "Green"}])
# cards_bar = BarChartModule([{"Label": "PlayerCards", "Color": "Black"}], scope="agent")

model_params = {
    'n_players':
    UserSettableParameter(
        'slider',
        'Number of players',
        4,
        3,
        5,
        1,
Exemplo n.º 9
0
    portrayal = dict()
    portrayal["nodes"] = [{
        "size":
        6,
        "color":
        node_color(agents[0]),
        "tooltip":
        "id: {} | A: {} | I: {} | O: {}".format(
            agents[0].unique_id, round(agents[0].attention, 2),
            round(agents[0].information, 2), round(agents[0].opinion, 2))
    } for (_, agents) in G.nodes.data("agent")]

    portrayal["edges"] = [{
        "source": source,
        "target": target,
        "color": edge_color(*get_agents(source, target)),
        "width": edge_width(*get_agents(source, target)),
    } for (source, target) in G.edges]

    return portrayal


# Drawing the grid, initialising elements and launching server
canvas_element = NetworkModule(network_portrayal, 500, 500, library="d3")
element_list = [canvas_element]

server = ModularServer(HIOM, element_list, "HIOM", model_params)

server.launch()
Exemplo n.º 10
0
         "color": "black" if agents[0].behavior == 1 else "#CCCCCC"}
        for (node_id, agents) in G.nodes.data('agent')
    ]

    portrayal['edges'] = [
        {"id": id,
         "source": tuple[0],
         "target": tuple[1],
         "color": "#CCCCCC",
         "width": .5
         } for (id, tuple) in enumerate(G.edges)
    ]

    return portrayal

network = NetworkModule(network_portrayal, 800, 800, library='sigma')


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

AveSens = ChartModule([{"Label": "AverageSens",
                        "Color": "Black"}],
                      data_collector_name="datacollector")

class MyTextElement(TextElement):
    def render(self, model):
        ad = model.avg_degree
        md = model.big_nodes
        ncn = model.connectivity