Cycle
Example I - One Cycle
[2]:
import networkx as nx
import pop2net as p2n
[4]:
env = p2n.Environment()
creator = p2n.Creator(env)
inspector = p2n.NetworkInspector(env)
class Cycle(p2n.LocationDesigner):
nxgraph = nx.cycle_graph(10)
env.add_actors([p2n.Actor() for _ in range(10)])
creator.create_locations(location_designers=[Cycle])
inspector.plot_networks()
Example II - Two Cycles
[6]:
env = p2n.Environment()
creator = p2n.Creator(env)
inspector = p2n.NetworkInspector(env)
class Cycle(p2n.LocationDesigner):
nxgraph = nx.cycle_graph(10)
env.add_actors([p2n.Actor() for _ in range(20)])
creator.create_locations(location_designers=[Cycle])
inspector.plot_networks()
Example III - Connected cycles
[9]:
env = p2n.Environment()
creator = p2n.Creator(env)
inspector = p2n.NetworkInspector(env)
class InnerCycle(p2n.LocationDesigner):
nxgraph = nx.cycle_graph(4)
n_locations = 1
class OuterCycle(p2n.LocationDesigner):
nxgraph = nx.cycle_graph(4)
def filter(self, actor):
return not actor.InnerCycle
class Bridge(p2n.LocationDesigner):
n_locations = 4
def filter(self, actor):
return actor.OuterCycle_head or actor.InnerCycle
def bridge(self, actor):
return actor.InnerCycle_assigned
for _ in range(20):
actor = p2n.Actor()
env.add_actor(actor)
creator.create_locations(
location_designers=[
InnerCycle,
OuterCycle,
Bridge,
]
)
inspector.plot_networks()