Cycle
Example I - One Cycle
[13]:
import networkx as nx
import pop2net as p2n
[14]:
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])
[14]:
LocationList (10 objects)
[15]:
inspector.plot_bipartite_network()
[16]:
inspector.plot_agent_network()
Example II - Two Cycles
[17]:
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])
[17]:
LocationList (10 objects)
[18]:
inspector.plot_bipartite_network()
[19]:
inspector.plot_agent_network()
Example III - Connected cycles
[20]:
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
n_agents = 1
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,
]
)
[20]:
LocationList (24 objects)
[21]:
inspector.plot_bipartite_network()
[22]:
inspector.plot_agent_network()