thalerjonathan / chimera

A library for pure functional Agent-Based Simulation in Haskell
GNU General Public License v3.0
13 stars 0 forks source link

Make Conversations / Transactions work #7

Open thalerjonathan opened 6 years ago

thalerjonathan commented 6 years ago

At the moment they are not working and need to be carefully redesigned. The solution would be probably to pass a SF which handles the conversation and switch into it during a conversation and back to the original one. State which needs to be passed from the main agent SF to the conversation SF needs to be passed explicitly as well.

thalerjonathan commented 6 years ago

Due to the major restructurings happening in issue #11, we need to explore the use of STM. It would be great to really run a transactional block of code where agents directly interact through messages but which are executed synchronously.

thalerjonathan commented 6 years ago

After experimenting with STM I (finally understood STM) and realised that it is the wrong approach to implement conversations. In conversations we need a transactional behaviour, which is indeed what STM provides BUT the difference is that we explicitly have to advance the transaction step-wise using locks for the receiving and sending. This is what STM removes: relying on complex locking orderings - but this is what we would need here in conversations, so STM is NOT a solution. What we would need are MVars but those run in IO which is absolutely not an option so we abandon this direction.

thalerjonathan commented 6 years ago

Conversations are to be called Transactions by now as this is a more accurate term describing the idea behind it.

thalerjonathan commented 6 years ago

New Idea: One could see transactional agent-behaviour as acting instantaneous without time-passing. Theoretically no time passes when we run the agents SF with dt=0 (of course one need to implement an agent always being time-aware). So we could then implement transactions by repeatedly executing the agents but with dt=0 until all transactions have commited. Care must be taken that an agent be only active in a single transaction e.g. in Sugarscape an Agent could receive requests to trade from multiple different other agents but every agent must be active only in one single transaction. For performance reasons only run the agents which are involved in the transaction: initiator and receiver.

thalerjonathan commented 6 years ago

Implemented.

Replace Conversations example by the trading agents example of ABSTX

thalerjonathan commented 6 years ago

ABSTX are way to complicated and too fragile, we need to implement something like the old conversation mechanism which we can do now with the AgentMonad