Cycle

Example I - One Cycle

[1]:
import networkx as nx

import pop2net as p2n
[2]:
model = p2n.Model()
creator = p2n.Creator(model)
inspector = p2n.NetworkInspector(model)


class Cycle(p2n.LocationDesigner):
    nxgraph = nx.cycle_graph(10)


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

creator.create_locations(location_designers=[Cycle])
[2]:
LocationList (10 objects)
[3]:
inspector.plot_bipartite_network()
[4]:
inspector.plot_agent_network()

Example II - Two Cycles

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


class Cycle(p2n.LocationDesigner):
    nxgraph = nx.cycle_graph(5)


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

creator.create_locations(location_designers=[Cycle])
[5]:
LocationList (10 objects)
[6]:
inspector.plot_bipartite_network()
[7]:
inspector.plot_agent_network()

Example III - Connected cycles

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


class InnerCycle(p2n.LocationDesigner):
    nxgraph = nx.cycle_graph(4)
    n_locations = 1


class OuterCycle(p2n.LocationDesigner):
    nxgraph = nx.cycle_graph(4)

    def filter(self, agent):
        return not agent.InnerCycle


class Bridge(p2n.LocationDesigner):
    n_locations = 4

    def filter(self, agent):
        return agent.OuterCycle_head or agent.InnerCycle

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


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

creator.create_locations(
    location_designers=[
        InnerCycle,
        OuterCycle,
        Bridge,
    ]
)
[8]:
LocationList (24 objects)
[9]:
inspector.plot_bipartite_network()
[10]:
inspector.plot_agent_network()