/* * 将row,col位置变成1,列的其他元素消元为0 * 运算作用于附加区 */ static int pivot(real *M,int row,int col,int n,int m,int skip) { int i; real d = M[row*skip+col]; //printf("pivot[%d,%d]\n",row,col); //printM(M,NULL,n+m,skip); if( d == 0 )return 0; multiply_line(M,(real)1.0/d,row,n,skip); M[row*skip+col] = 1; for(i=0;i<n;i++){ if( i != row&&M[i*skip+col]!=0 ) elimination(M,i,row,col,n,skip); } /* 对附加区进行变换,应用于mlcp求解程序 */ for(i=0;i<m;i++){ if( M[(n+i)*skip+col]!=0 ) elimination(M,n+i,row,col,n,skip); } return 1; }
// Deterministic solves the board as much as possible using the "deterministic" algorithms // The "deterministic" algorithms use a set of logical deductions on the possible values. // This will completely solve boards which require no "guessing" at values to solve. void Sudoku::deterministic() { Sudoku oldBoard; while( oldBoard != *this ) { oldBoard = *this; fillSingles(); elimination(); lockedCandidates(); } }
void main () { real_t **allocate_real_matrix(int, int, int, int); void free_real_matrix(real_t **, int, int, int); void richardson(real_t **, int, int, int, int, int, void (*)(int, int, int, int, real_t **), real_t, real_t, int *, real_t [], int *, real_t *, real_t *, void (*)(real_t **, int, int, int, int, int *, real_t [], int, real_t, real_t)); void elimination(real_t **, int, int, int, int, void (*)(int, int, int, int, real_t **), real_t, real_t, int *, real_t [], int *, real_t *, real_t *, void (*)(real_t **, int, int, int, int, int *, real_t [], int, real_t, real_t)); int j,l,lj,uj,ll,ul,n,p,k; real_t pi,domeigval,rateconvr,rateconve,rateconv,a,b,discr[3],**u; u=allocate_real_matrix(0,11,0,11); printf("RICHARDSON and ELIMINATION deliver:\n\n"); pi=3.14159265358979; lj=0; uj=11; ll=0; ul=11; n=50; a=0.326; b=7.83; h=pi/(uj-lj); h2=h*h; for (j=lj; j<=uj; j++) for (l=ll; l<=ul; l++) u[j][l] = (j==lj || j==uj || l==ll || l==ul) ? (j*h)*(j*h)*(l*h)*(l*h) : 1.0; nn=n; richardson(u,lj,uj,ll,ul,1,residual,a,b,&n,discr,&k,&rateconv, &domeigval,out1); rateconvr=rateconv; printf("\n dominant eigenvalue: %e\n\n",domeigval); elimination(u,lj,uj,ll,ul,residual,a,b,&p,discr,&k,&rateconv, &domeigval,out2); rateconve=rateconv; nn=n+p; printf("\nTotal number of iterations: %2d\n" "Rate of convergence with respect to\n" " the zeroth iterand of RICHARDSON: %e\n", nn,(n*rateconvr+p*rateconve)/nn); free_real_matrix(u,0,11,0); }