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
Return true if the degree sequences `indegree_sequence` and `outdegree_sequence` satisfy the (simple) digraph realization problem.
365
-
366
-
Two sequences of integers of integers satisfy the (simple) digraph realization problem, if there exists a simple directed graph where the indegrees of its vertices form that first sequence and the outdegrees the second.
Check whether the given indegree sequence and outdegree sequence are digraphical, that is whether they can be the indegree and outdegree sequence of a digraph.
367
364
368
365
### Implementation Notes
369
-
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 the sum of vertex degrees is even and the sequence obeys the property -
366
+
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 the sum of vertex degrees is even and ``\\sum_{i = 1}^{n} a_i = \\sum_{i = 1}^{n} b_i\\}`` and the sequence obeys the property -
@@ -395,27 +407,25 @@ function isdigraphical(indegree_sequence::Vector{<:Integer}, outdegree_sequence:
395
407
# with the line
396
408
# cum_min -= mindeg[r]
397
409
# 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
398
-
#= mindeg = Vector{Int64}(undef, n)
399
-
@inbounds for i = 1:n
400
-
mindeg[i] = min(i, sorted_outdegree_sequence[i])
401
-
end
402
-
cum_min = sum(mindeg) =#
410
+
#= mindeg = Vector{Int64}(undef, n)
411
+
@inbounds for i = 1:n
412
+
mindeg[i] = min(i, sorted_outdegree_sequence[i])
413
+
end
414
+
cum_min = sum(mindeg) =#
403
415
# Similarly for `outdegree_min_sum`.
404
416
405
-
@inboundsfor r =1:(n -1)
406
-
417
+
@inboundsfor r in1:(n -1)
407
418
indegree_sum += sorted_indegree_sequence[r]
408
-
outdegree_min_sum =sum([min(sorted_outdegree_sequence[i], r-1) for i in1:r])
409
-
cum_min =sum([min(sorted_outdegree_sequence[i], r) for i in (1+r):n])
410
-
419
+
outdegree_min_sum =sum([min(sorted_outdegree_sequence[i], r -1) for i in1:r])
420
+
cum_min =sum([min(sorted_outdegree_sequence[i], r) for i in (1+ r):n])
0 commit comments