-
Notifications
You must be signed in to change notification settings - Fork 16
Blog ‐ 2025 June
June 9, 2025
I restarted the trading algorithm to better understand its behavior with a much smaller number of variables, this time in Python with minimal boilerplate that outputs some graphs and some debug log so I can iterate on ideas without getting bogged down with maintaining various classes and interfaces.
There are just 3 professions: farmers, loggers, and carpenters. Farmers and loggers generate food and wood each round. The longer they are alive the more they generate per round (logarithmically). Carpenters take wood and create furnitures. Everyone eats food, everyone wants wood for heating or shelter, and everyone wants furnitures to sit on. So there's demand for everything by everyone.
So far I have a base implementation with no concept of money but with private inventory. Money was causing all sorts of problems for me so I wanted to remove that from the equation for now. I was hearing how price is a signal for supply and demand, and since I know supply and demand from the simulation, I can skip pricing for now and deal with it later. So trade is communistic: from those who can provide to those who need it. All trade is based on supply and demand, where supply is everything produced and demand is based on available capacity based on max inventory. All goods are pooled together and then redistributed based on their demand. Everyone is honest and bid only what will fill their inventory. Supply is distributed proportionally and prioritized based on demand in integer units. So when demand > supply, as is usually the case so far, the most needy gets it first.
So far so good. Population and inventory explodes with time as new pop takes up trades in most demand.

But agents age so at some point they die off. This slows population growth but they will still explode after 1000 rounds. It just depends on the rate of death vs the rate of new agents, I still need to tweak that based on actual stats, or maybe stats from a century ago. Maybe the stats of death will depend on technological progress??

I added a maximum food production limit, because at some point we run out of land. So I have a max_prod_rate and agents are clamped to max_prod_rate / num_agents. But this combined with truncating the production numbers resulted in total production per farmer going from 2 to 1 after the number of farmers are higher than half the max_prod_rate. While this created an issue where non farmers died off and then farmers started dying off, I liked the boom and bust cycles, which I'll pursue next.
I should probably explain the phase plot. I got the idea from another blog to illustrate the stability of the population as a function of one another. So when there are boom and busts you'll see a circular shape which means the system is in some sort of equilibrium. If this plot is neat and tidy than I can say it'll always be that way, but there is so much noise in this... I guess it means it's pretty chaotic!
After I removed the artificial production cut off, the population cliffs disappeared and population stabilized pretty well.

I added famine/feast multipliers at t=800 and t=1300, respectively. You can see food inventory was already going down around t=700 as population was going up to 200. Demand for food goes up while production remains flat at 200, so new agents go into farming to no avail. When famine hits and production is capped to 50, loggers and carpenters die off in a cliff and farmers start to shrink. At t=1300 you see farmers slowly drop due to natural aging and no agents go into farming due to sudden supply (demand doesn't change as a result of supply, currently) and new agents go into logging and carpentry until t=1800 when food inventory has dropped by a lot so demand for food goes up and new agents all go into farming due to sudden demand. This economy makes so much sense when there is a perfect allocation of resources!

Added a third event around t=2300 to bring it back. The system adapts pretty nicely. I guess it's time to introduce money into the system.
