You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement isdigraphical and fix isgraphical (#186)
* Make `isgraphical` more robust and add `isdigraphical``
Co-Authored-By: Claudio Moroni <[email protected]>
Co-Authored-By: Pietro Monticone <[email protected]>
Check whether the given indegree sequence and outdegree sequence are digraphical, that is whether they can be the indegree and outdegree sequence of a simple digraph (i.e. a directed graph with no loops). This implies that `indegree_sequence` and `outdegree_sequence` are not independent, as their elements respectively represent the indegrees and outdegrees that the vertices shall have.
767
+
768
+
### Implementation Notes
769
+
According to Fulkerson-Chen-Anstee theorem, a sequence ``\\{(a_1, b_1), ...,(a_n, b_n)\\}`` (sorted in descending order of a) is graphic iff ``\\sum_{i = 1}^{n} a_i = \\sum_{i = 1}^{n} b_i\\}`` and the sequence obeys the property -
# The following approach, which requires substituting the line
805
+
# cum_min = sum([min(sorted_outdegree_sequence[i], r) for i in (1+r):n])
806
+
# with the line
807
+
# cum_min -= mindeg[r]
808
+
# inside the for loop below, work as well, but the values of `cum_min` at each iteration differ. To be on the safe side we implemented it as in https://en.wikipedia.org/wiki/Fulkerson%E2%80%93Chen%E2%80%93Anstee_theorem
809
+
#= mindeg = Vector{Int64}(undef, n)
810
+
@inbounds for i = 1:n
811
+
mindeg[i] = min(i, sorted_outdegree_sequence[i])
812
+
end
813
+
cum_min = sum(mindeg) =#
814
+
# Similarly for `outdegree_min_sum`.
815
+
816
+
@inboundsfor r in1:n
817
+
indegree_sum += sorted_indegree_sequence[r]
818
+
outdegree_min_sum =sum([min(sorted_outdegree_sequence[i], r -1) for i in1:r])
819
+
cum_min =sum([min(sorted_outdegree_sequence[i], r) for i in (1+ r):n])
0 commit comments