@@ -47,6 +47,21 @@ function matching(g::BipartiteGraph, varwhitelist=nothing, eqwhitelist=nothing)
47
47
return assign
48
48
end
49
49
50
+ throw_unbalanced (n_highest_vars, neqs, msg, values) = throw (InvalidSystemException (
51
+ " The system is unbalanced. "
52
+ * " There are $n_highest_vars highest order derivative variables "
53
+ * " and $neqs equations.\n "
54
+ * msg
55
+ * values
56
+ ))
57
+
58
+ function fill_unassigned! (unassigned_list, vars, fullvars)
59
+ for (vj, eq) in enumerate (vars)
60
+ if eq === UNASSIGNED
61
+ push! (unassigned_list, fullvars[vj])
62
+ end
63
+ end
64
+ end
50
65
# ##
51
66
# ## Structural check
52
67
# ##
@@ -56,11 +71,25 @@ function check_consistency(s::SystemStructure)
56
71
neqs = nsrcs (graph)
57
72
is_balanced = n_highest_vars == neqs
58
73
59
- (neqs > 0 && ! is_balanced) && throw (InvalidSystemException (
60
- " The system is unbalanced. "
61
- * " There are $n_highest_vars highest order derivative variables "
62
- * " and $neqs equations."
63
- ))
74
+ if neqs > 0 && ! is_balanced
75
+ varwhitelist = varassoc .== 0
76
+ assign = matching (graph, varwhitelist) # not assigned
77
+ unassigned_var = []
78
+ if n_highest_vars > neqs
79
+ fill_unassigned! (unassigned_var, assign, fullvars)
80
+ io = IOBuffer ()
81
+ Base. print_array (io, unassigned_var)
82
+ unassigned_var_str = String (take! (io))
83
+ throw_unbalanced (n_highest_vars, neqs, " More variables than equations:\n " , unassigned_var_str)
84
+ else
85
+ inv_assign = inverse_mapping (assign) # extra equations
86
+ fill_unassigned! (unassigned_var, inv_assign, fullvars)
87
+ io = IOBuffer ()
88
+ Base. print_array (io, unassigned_var)
89
+ unassigned_var_str = String (take! (io))
90
+ throw_unbalanced (n_highest_vars, neqs, " More equations than variables:\n " , unassigned_var_str)
91
+ end
92
+ end
64
93
65
94
# This is defined to check if Pantelides algorithm terminates. For more
66
95
# details, check the equation (15) of the original paper.
0 commit comments