Looking for an algorithm - calculate ingredients for a set of recipes

Paul Moore p.f.moore at gmail.com
Mon Sep 25 10:20:53 EDT 2017


On 25 September 2017 at 14:23, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> You have a DAG, so you can sort it topologically. Then you can process
> it in that order so that everything that uses X will be processed
> before X so that when you get to X you'll know exactly how much of it
> you need and you don't have to worry about "feedback". For actual
> production, run through it in the opposite order so that you'll
> produce all your precursors before the things that require them.

Hmm, yes that makes sense. I was thinking of a topological sort in the
other direction (ingredient before product) and that way round doesn't
work. For some reason, when thinking about topological sorts, I tend
to get fixated on one direction and forget they are actually
reversible...

Paul



More information about the Python-list mailing list