@@ -27,18 +27,18 @@ using ..BLTandPantelidesUtilities
2727const log = false
2828
2929"""
30- function augmentPath!(G, i, assign, vColour, eColour, vActive )
30+ function augmentPath!(G, i, assign, vColour, eColour, vPassive )
3131Construction of augmenting path
3232
3333Reference:
3434Pantelides, C.: The consistent initialization of differential-algebraic systems. SIAM Journal
3535of Scientific and Statistical Computing, 9(2), pp. 213–231 (1988).
3636"""
37- function augmentPath! (G, i, assign, vColour, eColour, vActive )
37+ function augmentPath! (G, i, assign, vColour, eColour, vPassive )
3838 # returns pathFound
3939 # assign: assign[j] contains the E-node to which V-node j is assigned or 0 if V-node j not assigned
4040 # i: E-node
41- # vActive : set to false has the same effect as deleting V-node and corresponding edges
41+ # vPassive : set to != 0 has the same effect as deleting V-node and corresponding edges
4242 # j: V-node
4343
4444 if log
@@ -50,7 +50,7 @@ function augmentPath!(G, i, assign, vColour, eColour, vActive)
5050
5151 # If a V-node j exists such that edge (i-j) exists and assign[j] == 0
5252 for j in G[i]
53- if vActive [j] && assign[j] == 0
53+ if vPassive [j] == 0 && assign[j] == 0
5454 pathFound = true
5555 assign[j] = i
5656 return pathFound
@@ -59,10 +59,10 @@ function augmentPath!(G, i, assign, vColour, eColour, vActive)
5959
6060 # For every j such that edge (i-j) exists and j is uncoloured
6161 for j in G[i]
62- if vActive [j] && ! vColour[j]
62+ if vPassive [j] == 0 && ! vColour[j]
6363 vColour[j] = true
6464 k = assign[j]
65- pathFound = augmentPath! (G, k, assign, vColour, eColour, vActive )
65+ pathFound = augmentPath! (G, k, assign, vColour, eColour, vPassive )
6666
6767 if pathFound
6868 assign[j] = i
@@ -74,11 +74,11 @@ function augmentPath!(G, i, assign, vColour, eColour, vActive)
7474end
7575
7676
77- function checkAssign (assign, VSizes, VTypes, ESizes, ETypes, equationsInfix, variableNames, A, vActive = [a == 0 for a in A] )
77+ function checkAssign (assign, VSizes, VTypes, ESizes, ETypes, equationsInfix, variableNames, A, vPassive = A )
7878 println (" Checking assignment" )
7979 assignmentOK = true
8080 for j in 1 : length (assign)
81- if vActive [j]
81+ if vPassive [j] == 0
8282 i = assign[j]
8383 if i > 0 && VSizes[j] != ESizes[i]
8484 assignmentOK = false
@@ -114,10 +114,11 @@ function matching(G, M, vActive=fill(true, M))
114114 assign:: Array{Int,1} = fill (0 , M)
115115 eColour:: Array{Bool,1} = fill (false , length (G))
116116 vColour:: Array{Bool,1} = fill (false , M)
117+ vPassive:: Array{Int,1} = [if va; 0 else 1 end for va in vActive]
117118 for i in 1 : length (G)
118119 fill! (eColour, false )
119120 fill! (vColour, false )
120- pathFound = augmentPath! (G, i, assign, vColour, eColour, vActive )
121+ pathFound = augmentPath! (G, i, assign, vColour, eColour, vPassive )
121122 end
122123 return assign
123124end
@@ -142,18 +143,28 @@ of Scientific and Statistical Computing, 9(2), pp. 213–231 (1988).
142143function pantelides! (G, M, A)
143144 assign:: Array{Int,1} = fill (0 , M)
144145 B:: Array{Int,1} = fill (0 , length (G))
146+ eColour:: Array{Bool,1} = fill (false , length (G))
147+ vColour:: Array{Bool,1} = fill (false , M)
145148 N = length (G)
146149 N2 = N
147150 for k in 1 : N2
148151 pathFound = false
149152 i = k
150153 while ! pathFound
151154 # Delete all V-nodes with A[.] != 0 and all their incidence edges from the graph
152- vActive:: Array{Bool,1} = [a == 0 for a in A]
153155 # Designate all nodes as "uncoloured"
154- eColour:: Array{Bool,1} = fill (false , length (G))
155- vColour:: Array{Bool,1} = fill (false , M)
156- pathFound = augmentPath! (G, i, assign, vColour, eColour, vActive)
156+ if length (eColour) == length (G)
157+ fill! (eColour, false )
158+ else
159+ eColour = fill (false , length (G))
160+ end
161+ if length (vColour) == length (M)
162+ fill! (vColour, false )
163+ else
164+ vColour = fill (false , M)
165+ end
166+
167+ pathFound = augmentPath! (G, i, assign, vColour, eColour, A)
157168 if ! pathFound
158169 if log
159170 println (" \n Differentiate:" )
0 commit comments