I think that the most reasonable way to measure the quality of a particular order is the amount of relationship data that it violates. If you decide to use this measure, the problem will be equivalent to the (minimal) Arc Arc Arc . Unfortunately, this problem is NP-hard, so there is no efficient (polynomial-time) algorithm.
In the task βFeedback taskβ you were given a directed graph and asked to find a set of edges of the minimum size, which, if deleted, will destroy all cycles in the graph.
To see how this fits your problem, note that we can represent each element as a vertex in a graph, and each relation as a directed edge between two vertices (indicating, say, a smaller one). There is a conflict if and only if there is a cycle on this graph, i.e. If there is an ordered list of two or more different vertices v_1, v_2, ..., v_k, such that v_i <v_ (i + 1) for all i <k, and also v_k <v_1. It is impossible to order these k vertices without violating at least one constraint. And vice versa, if there is no cycle, i.e. If a graph is a <a hcf = "https://en.wikipedia.org/wiki/Directed_acyclic_graph"> directed acyclic graph, then topological sorting can quickly (in linear time) find a real order that does not violate restrictions. Thus, the size of the feedback arc set is the smallest number of edges that must be removed in order to get a graph that can be ordered without breaking any restriction - or, which is the same, the smallest number of edges that must be broken in any ordering.
source share