Can closed forms for the outputs in this production simulation be found?

37 Views Asked by At

(I am not sure whether this question should better be asked on Game Development SE but I think of this more as a mathematical problem than one specific to game development.)

For a game I am implementing a resource production simulation. There are producers, which create a specific amount of a specific resource after a specific duration and may or may not need other resources for doing so.

All these producers share a common storage of resources, called the inventory. The inventory is a set of 2-tuples containing the resource type and the amount.

A producer $P = (P_{res},P_{amt},P_{dur},P_{dep})$ consist of the type of resource it produces $P_{res}$, the amount it produces $P_{amt}$, the duration of the production process $P_{dur}$ and the resources it depends on for production $P_{dep} = \{P_{{dep}_1}, \dots, P_{{dep}_n}\}$, with $P_{dep}$ being a set of 2-tuples containing the resource type and amount. A producer is able to produce, when $P_{dur}$ timesteps have passed and the inventory contains all needed resources.

The producers are updated every timestep $t$. Concerning the order of update, assume that the producers are always updated in the optimal order, i.e. the producers which have the least dependencies and produce the resource the most other producers depend on, are updated first.

For example: Let our producers be

  • $P_1=(\alpha, 1, 1, \{\})$
  • $P_2=(\beta, 1, 3, \{(\alpha, 1)\})$

Let $prod(P,t)$ be the amount produced by $P$ after $t$ timesteps. The production after multiple updates would look like: \begin{array}{|c|c|c|} \hline t & prod(P_1,t) & prod(P_2,t) \\\hline 1 & 1 & 0 \\\hline 2 & 2 & 0 \\\hline 3 & 2 & 1 \\\hline 4 & 3 & 1 \\\hline 5 & 4 & 1 \\\hline 6 & 4 & 2 \\\hline 7 & 5 & 2 \\\hline 8 & 6 & 2 \\\hline 9 & 6 & 3 \\\hline \end{array} $prod(P_1,t)$ can be calculated as $$prod(P_1,t) = \lfloor \frac{2t}{3} \rfloor$$ Were $P_{1_{dur}}$ instead $2$ the table would look like: \begin{array}{|c|c|c|} \hline t & prod(P_1,t) & prod(P_2,t) \\\hline 1 & 0 & 0 \\\hline 2 & 1 & 0 \\\hline 3 & 0 & 1 \\\hline 4 & 1 & 1 \\\hline 5 & 1 & 1 \\\hline 6 & 1 & 2 \\\hline 7 & 1 & 2 \\\hline 8 & 2 & 2 \\\hline 9 & 1 & 3 \\\hline \end{array} and $prod(P_1,t)$ could be calculated as $$prod(P_1,t) = \lfloor \frac{t}{2} \rfloor - \lfloor \frac{t}{3} \rfloor$$

I've got multiple questions:

  1. Has this kind of problem a name?
  2. Is it possible to derive closed forms for the production output of
    • any producer,
    • in any* configuration of producers
    • and with any initial configuration of the inventory?
  3. If the answer to two is negative, when does it stop being possible or rather what is preventing one from finding a closed form?

*= circular dependencies are forbidden

I've implemented the problem as stated above in python and shared it here (the optimal update order is not implemented and is in the responsibility of the user).