Submitting a model
Modelpy is a modern python framework for agent based models.
If you intend to submit a model, your model.py file should meet the following requirements:
- Only imports standard library packages, or one of
{modelpy_abm, numpy, networkx}
- Defines an initial data generator function.
- Defines a timestep data generator function.
- Defines a function "constructModel", with that exact name.
- The "constructModel" function returns an instance of the AgentModel class with the timestep and initial_data functions set accordingly, and with the desired initial parameters.
Here is an example:
import networkx as nx
import numpy as np
import random
from modelpy_abm.main import AgentModel
import jsonpickle
def generateInitialData(model: AgentModel):
initial_data = {"wealth": 1}
return initial_data
def generateTimestepData(model: AgentModel):
graph = model.get_graph()
for _node, node_data in graph.nodes(data=True):
if node_data["wealth"] > 0:
other_agent = random.choice(list(graph.nodes.keys()))
if other_agent is not None:
graph.nodes[other_agent]["wealth"] += 1
node_data["wealth"] -= 1
model.set_graph(graph)
def constructModel() -> AgentModel:
model = AgentModel()
model.set_initial_data_function(generateInitialData)
model.set_timestep_function(generateTimestepData)
model.update_parameters({"num_nodes": 3})
return model