Barbell graph
Example I - Simple Barbell from scratch
[2]:
import pop2net as p2n
model = p2n.Model()
creator = p2n.Creator(model)
inspector = p2n.NetworkInspector(model)
class Bell(p2n.LocationDesigner):
n_locations = 2
class Bar(p2n.LocationDesigner):
n_locations = 1
def bridge(self, agent):
return agent.Bell
for _ in range(20):
p2n.Agent(model)
creator.create_locations(
location_designers=[
Bell,
Bar,
]
)
[2]:
LocationList (3 objects)
[3]:
inspector.plot_bipartite_network()
[4]:
inspector.plot_agent_network()
Example II - Connected opinion cluster
[7]:
class OpinionCluster(p2n.LocationDesigner):
def split(self, agent):
return agent.opinion
class Bridge(p2n.LocationDesigner):
n_locations = 1
def bridge(self, agent):
return agent.opinion
model = p2n.Model()
creator = p2n.Creator(model)
inspector = p2n.NetworkInspector(model)
for i in range(30):
agent = p2n.Agent(model=model)
agent.opinion = i % 3
creator.create_locations(location_designers=[OpinionCluster, Bridge])
inspector.plot_networks(agent_color="opinion")
Example III - Barbells with long bars
[8]:
import networkx as nx
model = p2n.Model()
creator = p2n.Creator(model)
inspector = p2n.NetworkInspector(model)
class Bell(p2n.LocationDesigner):
n_agents = 5
n_locations = 4
class Bar(p2n.LocationDesigner):
n_locations = 2
nxgraph = nx.path_graph(5)
def filter(self, agent):
return not agent.Bell
class Bridge(p2n.LocationDesigner):
def filter(self, agent):
return agent.Bar_head or agent.Bar_tail or agent.Bell_head
def bridge(self, agent):
return agent.Bar_assigned
for _ in range(30):
p2n.Agent(model)
creator.create_locations(
location_designers=[
Bell,
Bar,
Bridge,
]
)
[8]:
LocationList (16 objects)
[9]:
inspector.plot_bipartite_network()
[10]:
inspector.plot_agent_network()