1 #include "cs_mex.h"
2 /* cs_dmperm: maximum matching or Dulmage-Mendelsohn permutation. */
mexFunction(int nargout,mxArray * pargout[],int nargin,const mxArray * pargin[])3 void mexFunction
4 (
5 int nargout,
6 mxArray *pargout [ ],
7 int nargin,
8 const mxArray *pargin [ ]
9 )
10 {
11 double seed ;
12 cs_dl *A, Amatrix ;
13 cs_dld *D ;
14 CS_INT m, n, *jmatch, iseed ;
15 if (nargin < 1 || nargin > 2 || nargout > 6)
16 {
17 mexErrMsgTxt ("Usage: [p,q,r,s,cc,rr] = cs_dmperm (A,seed)") ;
18 }
19 seed = (nargin > 1) ? mxGetScalar (pargin [1]) : 0 ; /* get seed */
20 iseed = (seed > 0 && seed < 1) ? (seed * RAND_MAX) : seed ;
21 A = cs_dl_mex_get_sparse (&Amatrix, 0, 0, pargin [0]) ; /* get A */
22 n = A->n ;
23 m = A->m ;
24 if (nargout <= 1)
25 {
26 jmatch = cs_dl_maxtrans (A, iseed) ; /* max. matching */
27 pargout [0] = cs_dl_mex_put_int (jmatch+m, n, 1, 0) ; /* return imatch */
28 cs_free (jmatch) ;
29 }
30 else
31 {
32 D = cs_dl_dmperm (A, iseed) ; /* Dulmage-Mendelsohn decomposition */
33 pargout [0] = cs_dl_mex_put_int (D->p, m, 1, 0) ;
34 pargout [1] = cs_dl_mex_put_int (D->q, n, 1, 0) ;
35 pargout [2] = cs_dl_mex_put_int (D->r, D->nb+1, 1, 0) ;
36 pargout [3] = cs_dl_mex_put_int (D->s, D->nb+1, 1, 0) ;
37 pargout [4] = cs_dl_mex_put_int (D->cc, 5, 1, 0) ;
38 pargout [5] = cs_dl_mex_put_int (D->rr, 5, 1, 0) ;
39 cs_dl_dfree (D) ;
40 }
41 }
42