The ordering algorithm is defined as a rule set that takes the model recognized by Problem 2 as an input. Essentially this problem can be represented as a topological sort with constraints.