Lollipop graph

Example I - Simple Lollipop using networkx

[7]:
import networkx as nx

import pop2net as p2n

model = p2n.Model()
creator = p2n.Creator(model)
inspector = p2n.NetworkInspector(model)


class Lollipop(p2n.LocationDesigner):
    n_agents = 7
    nxgraph = nx.lollipop_graph(5, 3)


for _ in range(20):
    p2n.Agent(model)

creator.create_locations(
    location_designers=[
        Lollipop,
    ]
)
[7]:
LocationList (36 objects)
[8]:
inspector.plot_bipartite_network()
[9]:
inspector.plot_agent_network()

Example II - A Lollipop flower

[10]:
model = p2n.Model()
creator = p2n.Creator(model)
inspector = p2n.NetworkInspector(model)


class Lollipop(p2n.LocationDesigner):
    n_locations = 5
    nxgraph = nx.lollipop_graph(5, 3)
    only_exact_n_agents = True


class Center(p2n.LocationDesigner):
    def filter(self, agent):
        return agent.Lollipop_tail or not agent.Lollipop

    def bridge(self, agent):
        return agent.Lollipop_assigned


for _ in range(41):
    p2n.Agent(model)

creator.create_locations(
    location_designers=[
        Lollipop,
        Center,
    ]
)
[10]:
LocationList (70 objects)
[11]:
inspector.plot_bipartite_network()
[12]:
inspector.plot_agent_network()