3 static int cs_bfs (
const cs *
A,
int n,
int *wi,
int *wj,
int *queue,
4 const int *imatch,
const int *jmatch,
int mark)
6 int *Ap, *Ai,
head = 0,
tail = 0, j, i, p, j2 ;
8 for (j = 0 ; j < n ; j++)
10 if (imatch [j] >= 0) continue ;
14 if (
tail == 0)
return (1) ;
17 Ap = C->
p ; Ai = C->
i ;
21 for (p = Ap [j] ; p < Ap [j+1] ; p++)
24 if (wi [i] >= 0) continue ;
27 if (wj [j2] >= 0) continue ;
37 static void cs_matched (
int n,
const int *wj,
const int *imatch,
int *p,
int *q,
38 int *cc,
int *rr,
int set,
int mark)
40 int kc = cc [
set], j ;
42 for (j = 0 ; j < n ; j++)
44 if (wj [j] != mark) continue ;
45 p [kr++] = imatch [j] ;
53 static void cs_unmatched (
int m,
const int *wi,
int *p,
int *rr,
int set)
55 int i, kr = rr [
set] ;
56 for (i = 0 ; i < m ; i++)
if (wi [i] == 0) p [kr++] = i ;
61 static int cs_rprune (
int i,
int j,
double aij,
void *other)
63 int *rr = (
int *) other ;
64 return (i >= rr [1] && i < rr [2]) ;
70 int m, n, i, j, k, cnz, nc, *jmatch, *imatch, *wi, *wj, *pinv, *
Cp, *Ci,
71 *ps, *rs, nb1, nb2, *p, *q, *cc, *rr, *r, *s, ok ;
75 if (!
CS_CSC (A))
return (NULL) ;
78 if (!D)
return (NULL) ;
79 p = D->
p ; q = D->
q ; r = D->
r ; s = D->
s ; cc = D->
cc ; rr = D->
rr ;
82 if (!jmatch)
return (
cs_ddone (D, NULL, jmatch, 0)) ;
85 for (j = 0 ; j < n ; j++) wj [j] = -1 ;
86 for (i = 0 ; i < m ; i++) wi [i] = -1 ;
87 cs_bfs (A, n, wi, wj, q, imatch, jmatch, 1) ;
88 ok =
cs_bfs (A, m, wj, wi, p, jmatch, imatch, 3) ;
89 if (!ok)
return (
cs_ddone (D, NULL, jmatch, 0)) ;
91 cs_matched (n, wj, imatch, p, q, cc, rr, 1, 1) ;
92 cs_matched (n, wj, imatch, p, q, cc, rr, 2, -1) ;
93 cs_matched (n, wj, imatch, p, q, cc, rr, 3, 3) ;
98 if (!pinv)
return (
cs_ddone (D, NULL, NULL, 0)) ;
101 if (!C)
return (
cs_ddone (D, NULL, NULL, 0)) ;
103 nc = cc [3] - cc [2] ;
104 if (cc [2] > 0)
for (j = cc [2] ; j <= cc [3] ; j++) Cp [j-cc[2]] = Cp [j] ;
106 if (rr [2] - rr [1] < m)
111 if (rr [1] > 0)
for (k = 0 ; k < cnz ; k++) Ci [k] -= rr [1] ;
115 if (!scc)
return (
cs_ddone (D, C, NULL, 0)) ;
120 for (k = 0 ; k < nc ; k++) wj [k] = q [ps [k] + cc [2]] ;
121 for (k = 0 ; k < nc ; k++) q [k + cc [2]] = wj [k] ;
122 for (k = 0 ; k < nc ; k++) wi [k] = p [ps [k] + rr [1]] ;
123 for (k = 0 ; k < nc ; k++) p [k + rr [1]] = wi [k] ;
126 if (cc [2] > 0) nb2++ ;
127 for (k = 0 ; k < nb1 ; k++)
129 r [nb2] = rs [k] + rr [1] ;
130 s [nb2] = rs [k] + cc [2] ;
static int cs_bfs(const cs *A, int n, int *wi, int *wj, int *queue, const int *imatch, const int *jmatch, int mark)
cs * cs_permute(const cs *A, const int *pinv, const int *q, int values)
csd * cs_dalloc(int m, int n)
int cs_fkeep(cs *A, int(*fkeep)(int, int, double, void *), void *other)
cs * cs_transpose(const cs *A, int values)
static void cs_unmatched(int m, const int *wi, int *p, int *rr, int set)
static int cs_rprune(int i, int j, double aij, void *other)
static void cs_matched(int n, const int *wj, const int *imatch, int *p, int *q, int *cc, int *rr, int set, int mark)
int * cs_maxtrans(const cs *A, int seed)
SegmentReturnType tail(Index vecSize)
csd * cs_ddone(csd *D, cs *C, void *w, int ok)
SegmentReturnType head(Index vecSize)
int * cs_pinv(const int *p, int n)
csd * cs_dmperm(const cs *A, int seed)