Advertisement

Production graph prediction

Started by November 16, 2015 06:40 PM
13 comments, last by captain_crunch 8 years, 9 months ago

I added an extra condition to account for more inputs and tools. Not sure if it will still work.


Create a queue

Foreach entity you own
  Mark it attainable and put it in the queue

While the queue is not empty
  Dequeue an entity
  Foreach process using this entity as an input
    If all other inputs and tools are attainable    <- extra condition - works?
       Foreach output in that process
         If the output entity is not already marked attainable         <- key step to avoid looping forever.
           Mark it attainable
           Foreach process using this output as an input
             Put it in the queue

I ran a small example but could not see how it would work. The problem seems to be that my condition "If all other inputs and tools are attainable" filters out some processes that may become valid later on, but they are never revisited.

Advertisement
I'm probably misunderstanding your goal, then.

Note that I am disregarding the amounts needed, I am just looking to give a hint about what is possible to attain, so any item that is present in greater than 0 amounts will be attainable, and fulfill the next process step.


I've been interpreting this as: If you own at least one of any input, it considers the entire process and all of its outputs attainable.

If you meant that you need at least one of every input before you show hints for a process's output, then the problem with my algorithm is that it is not traversing the graph in topological order - i.e. it can traverse a process before all of its OTHER predecessor processes have marked its inputs.

The easiest way to solve this is to iteratively brute force it.


Foreach entity you own
  Mark it attainable

todoList = all processes;

bool needToLoop = true;
While (needToLoop)
  needToLoop = false;
  Foreach process in todoList
    If the process is valid (all inputs and tools are attainable, or any other condition checks you want)
      Remove process from todoList
      Foreach output in process
        If it is not yet marked attainable
          needToLoop = true;
          Mark it attainable
This just continues checking all "todo" processes until it no longer finds anything it can mark attainable.

If you want to fill out hint information with missing inputs, you can do this at the end by using whatever's left in the todoList - those are the processes that the player can't make.

This looks useful, I am implementing it now.

It works like a charm. Not sure why I could not see the solution... I guess I got really stuck on that graph search.

This topic is closed to new replies.

Advertisement