Production graph search
Now I want the player to be able to set a production goal, that is a desired number of items he wants produced of a give type.
The task is now for the computer to find the most efficient way of fulfilling the goal. There can be a number of material items already in store, and there can be a cost in time and energy for the processes. The cost in time and energy should be minimized.
Which search algorithm should I use? Neither A* nor BFS seem appropriate...
I Create Games to Help Tell Stories
This sounds very similar to max-flow (but not quite identical).
If you have n conversion processes and T time steps, picture a graph with n T nodes. Each node represents doing a particular process at a particular time. Then, you link all the nodes from one time to all the nodes at the next time. I'm picturing a vertical column of nodes for each time, and those columns arranged in order from early times to late times from left to right.
What you're going to do is optimize over flows on the edges.
What are our constraints? Let's look at an individual node. Say you have a process with two inputs and two outputs. The conversion it does is,
INPUT: 2 units of input resource 1 and 3 units of input resource 2
OUTPUT: 4 units of output resource 1 and 7 units of output resource 2.
Say the amounts of input resources you put in are a and b, and the amounts of output resources are x and y. Then, introducing a new variable z to represent the total number of "trades" done, the above is summarized by the constraints,
z <= a/2
z <= b/3
x <= 4 z
y <= 7 z
so you have inequality constraints relating the flows on your edges. Additionally, all the flows need to be nonnegative, meaning that they go the right direction in time:
x >= 0
y >= 0
a >= 0
b >= 0 .
You also have some equality constraints: The flows into the nodes at the far left of the graph (the "earliest" ones) are fixed; these are the quantities you start out with. And the flows at the far right of the graph have "greater-than" constraints, to say that you want produced at least this much of each resource.
Finally, you have a cost, which is just a weighted sum of the flows.
So what does this boil down to?
- You have as many variables as you have edges [EDIT: plus nodes; you also have the "z" variables]
- You have a linear cost (a weighted sum)
- You have linear inequality constraints
You can solve this exactly as an integer linear program, or you can relax the answer to be real (instead of just integer), in which case you just have a standard LP.
Does this formulation leave anything out?
With this solution, will it be possible to present the user with a production plan for each of his orders, that he can inspect (and possibly cancel)?
The production plan would be: "Produce x items a, y items b" and so on.
Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play
"Reducing the world to mathematical equations!"
Also, this is probably a good place for either MCTS or a straight up GA. Anything that converges on a solution rather than trying to build one from scratch is a good bet.
Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play
"Reducing the world to mathematical equations!"