Easy Stock and Flow modelling through cadCAD

Hi guys, I’ve created some Python objects for easy and intuitive S&F modelling on cadCAD. Maybe we’ll evolve it someday to an proper auxiliary library, anyway, an colab with batteries included is in https://colab.research.google.com/drive/1HPC3iOgM3xfu4Sd2fENSBeji9Z9gfOY8#scrollTo=HW7LvYft8Z_V

and an actual cadCAD prey predator model through S&F is as follows:

## The actual stock and flow modelling code block ##

# System
s = System()
nowhere = s.nowhere

# Stocks
prey = s.add_stock('prey', 100)
predator = s.add_stock('predator', 10)

# Parameters
dt = 0.01
params = {'prey_birth_rate': 1.0 * dt,
          'predator_birth_rate': 0.0 * dt,
          'prey_death_rate': 0.03 * dt,
          'predator_death_rate': 1.0 * dt,
          'prey_predator_interaction': 0.05 * dt}

# Flows
s.add_flow('1', nowhere >> prey, lambda src, dst, params, s: dst * params['prey_birth_rate'])
s.add_flow('2', nowhere >> predator, lambda src, dst, params, s: dst * params['predator_birth_rate'])
s.add_flow('3', predator >> nowhere, lambda src, dst, params, s: src * params['predator_death_rate'])
s.add_flow('4', prey >> nowhere, lambda src, dst, params, s: src * params['prey_death_rate'])
s.add_flow('5', prey >> predator, lambda src, dst, params, s: src * dst * params['prey_predator_interaction'])

# Simulation
results = pd.DataFrame(s.run(T=3000, params=params))
7 Likes