2023-02-27 22:02:46 +08:00
|
|
|
import agentpy as ap
|
|
|
|
|
|
|
|
|
|
|
|
class ProductAgent(ap.Agent):
|
|
|
|
def setup(self, code, name):
|
|
|
|
self.product_network = self.model.product_network
|
|
|
|
|
|
|
|
self.code = code
|
|
|
|
self.name = name
|
|
|
|
|
|
|
|
def a_successors(self):
|
|
|
|
nodes = self.product_network.graph.successors(
|
|
|
|
self.product_network.positions[self])
|
|
|
|
return ap.AgentList(
|
|
|
|
self.model,
|
|
|
|
[ap.AgentIter(self.model, node).to_list()[0] for node in nodes])
|
2023-05-15 13:37:05 +08:00
|
|
|
|
2023-03-06 22:38:57 +08:00
|
|
|
def a_predecessors(self):
|
2023-05-15 13:37:05 +08:00
|
|
|
nodes = self.product_network.graph.predecessors(
|
|
|
|
self.product_network.positions[self])
|
|
|
|
return ap.AgentList(
|
|
|
|
self.model,
|
|
|
|
[ap.AgentIter(self.model, node).to_list()[0] for node in nodes])
|