Lollipop graph

Example I - Simple Lollipop using networkx

[1]:
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,
    ]
)
/Users/lukas/git/pop2net/src/pop2net/creator.py:603: UserWarning: You cannot define location.n_agents if location.nxgraph is used.
                        It will be set to the number of nodes in location.nxgraph automatically.
  warnings.warn(msg)
[1]:
LocationList (36 objects)
[2]:
inspector.plot_bipartite_network()
[3]:
inspector.plot_agent_network()

Example II - A Lollipop flower

[4]:
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,
    ]
)
[4]:
LocationList (70 objects)
[5]:
inspector.plot_bipartite_network()
[6]:
inspector.plot_agent_network()