### Ordering the amendments (Problem #3)

Warning: this section has not been implemented and presents only the conceptual idea of the implementation.

Ordering amendments in voting order is a time-consuming task. The order is defined by a set of rules. This problem can be solved with a topological sort with constraints. The conceptual algorithm is straightforward:

Gather all amendments graphs extracted from the amendment document.

Create a fictitious root node in the merged graph G_{m}.

For each graph G_{a} in the gathered amendments graphs:

Add to- or reuse in G_{m} the location nodes in G_{m} for each location part in G_{a}.

Add to- or reuse in G_{m} the action node.

Add the amendment node to G_{m}.

Assign weights to all the location and action nodes.

Sort the amendment nodes based on the weight of the shortest path to the root node.

Once the amendment nodes are sorted it is easy to create the ordered list as the system thinks it should be. The system can then use that ordered list to determine whether it differs from the current ordering in the amendment document and warn the user if they differ.

The tricky part of such an implementation is not the algorithm: it is understanding the ordering rules and defining a weighting scheme based on those rules. These ordering rules are different for each legal system. It may very well be that for some systems it may not be possible to express the rules as a weighting scheme. In all cases, the final order must be left to the user.