void TensorProductBasis<BASIS0,BASIS1>::reconstruct_1(const Index& lambda, const int j, InfiniteVector<double, Index>& c) const { if (lambda.j() >= j) { // then we can just copy \psi_\lambda c.add_coefficient(lambda, 1.0); } else { // reconstruct by recursion typedef typename BASIS0::Index Index0; typedef typename BASIS1::Index Index1; InfiniteVector<double,Index0> c1; InfiniteVector<double,Index1> c2; basis0().reconstruct_1(lambda.index0(), lambda.j()+1, c1); basis1().reconstruct_1(lambda.index1(), lambda.j()+1, c2); for (typename InfiniteVector<double,Index0>::const_iterator it1(c1.begin()), it1end(c1.end()); it1 != it1end; ++it1) for (typename InfiniteVector<double,Index1>::const_iterator it2(c2.begin()), it2end(c2.end()); it2 != it2end; ++it2) { InfiniteVector<double,Index> d; reconstruct_1(Index(it1.index(), it2.index()), j, d); c.add(*it1 * *it2, d); } } }
void TensorProductBasis<BASIS0,BASIS1>::decompose_1(const Index& lambda, const int j0, InfiniteVector<double, Index>& c) const { assert(lambda.j() >= j0); c.clear(); if (lambda.index0().e() != 0 || lambda.index1().e() != 0) { // the true wavelet coefficients don't have to be modified c.set_coefficient(lambda, 1.0); } else { // a generator on a (possibly) fine level if (lambda.j() == j0) { // generators from the coarsest level can be copied c.set_coefficient(lambda, 1.0); } else { // j>j0, perform multiscale decomposition typedef typename BASIS0::Index Index0; typedef typename BASIS1::Index Index1; InfiniteVector<double,Index0> c1; InfiniteVector<double,Index1> c2; basis0().decompose_1(lambda.index0(), lambda.j()-1, c1); basis1().decompose_1(lambda.index1(), lambda.j()-1, c2); for (typename InfiniteVector<double,Index0>::const_iterator it1(c1.begin()), it1end(c1.end()); it1 != it1end; ++it1) for (typename InfiniteVector<double,Index1>::const_iterator it2(c2.begin()), it2end(c2.end()); it2 != it2end; ++it2) { // if (it1.index().e() == 0 && it2.index().e() == 0) { // generators have to be refined further InfiniteVector<double,Index> d; decompose_1(Index(it1.index(), it2.index()), j0, d); c.add(*it1 * *it2, d); // } else // c.set_coefficient(Index(this, it1.index(), it2.index()), *it1 * *it2); } } } }
int Rsimp(int m, int n, double **A, double *b, double *c, double *x, int *basis, int *nonbasis, double **R, double **Q, double *t1, double *t2){ int i,j,k,l,q,qv; int max_steps=20; double r,a,at; void GQR(int,int,double**,double**); max_steps=4*n; for(k=0; k<=max_steps;k++){ /* ++ Step 0) load new basis matrix and factor it */ for(i=0;i<m;i++)for(j=0;j<m;j++)R0(i,j)=AB0(i,j); GQR(m,m,Q,R); /* ++ Step 1) solving system B'*w=c(basis) ++ a) forward solve R'*y=c(basis) */ for(i=0;i<m;i++){ Y0(i)=0.0; for(j=0;j<i;j++)Y0(i)+=R0(j,i)*Y0(j); if (R0(i,i)!=0.0) Y0(i)=(CB0(i)-Y0(i))/R0(i,i); else { printf("Warning Singular Matrix Found\n"); return LP_FAIL; } } /* ++ b) find w=Q*y ++ note: B'*w=(Q*R)'*Q*y= R'*(Q'*Q)*y=R'*y=c(basis) */ for(i=0;i<m;i++){ W0(i)=0.0; for(j=0;j<m;j++)W0(i)+=Q0(i,j)*Y0(j); } /* ++ Step 2)find entering variable, ++ (use lexicographically first variable with negative reduced cost) */ q=n; for(i=0;i<n-m;i++){ /* calculate reduced cost */ r=CN0(i); for(j=0;j<m;j++) r-=W0(j)*AN0(j,i); if (r<-zero_tol && (q==n || nonbasis0(i)<nonbasis0(q))) q=i; } /* ++ if ratios were all nonnegative current solution is optimal */ if (q==n){ if (verbose>0) printf("optimal solution found in %d iterations\n",k); return LP_OPT; } /* ++ Step 3)Calculate translation direction for q entering ++ by solving system B*d=-A(:,nonbasis(q)); ++ a) let y=-Q'*A(:,nonbasis(q)); */ for(i=0;i<m;i++){ Y0(i)=0.0; for(j=0;j<m;j++) Y0(i)-=Q0(j,i)*AN0(j,q); } /* ++ b) back solve Rd=y (d=R\y) ++ note B*d= Q*R*d=Q*y=Q*-Q'*A(:nonbasis(q))=-A(:,nonbasis(q)) */ for(i=m-1;i>=0;i--){ D0(i)=0.0; for(j=m-1;j>=i+1;j--)D0(i)+=R0(i,j)*D0(j); if (R0(i,i)!=0.0) D0(i)=(Y0(i)-D0(i))/R0(i,i); else { printf("Warning Singular Matrix Found\n"); return LP_FAIL; } } /* ++ Step 4 Choose leaving variable ++ (first variable to become negative, by moving in direction D) ++ (if none become negative, then objective function unbounded) */ a=0; l=-1; for(i=0;i<m;i++){ if (D0(i)<-zero_tol){ at=-1*XB0(i)/D0(i); if (l==-1 || at<a){ a=at; l=i;} } } if (l==-1){ if (verbose>0){ printf("Objective function Unbounded (%d iterations)\n",k); } return LP_UNBD; } /* ++ Step 5) Update solution and basis data */ XN0(q)=a; for(j=0;j<m;j++) XB0(j)+=a*D0(j); XB0(l)=0.0; /* enforce strict zeroness of nonbasis variables */ qv=nonbasis0(q); nonbasis0(q)=basis0(l); basis0(l)=qv; } if (verbose>=0){ printf("Simplex Algorithm did not Terminate in %d iterations\n",k); } return LP_FAIL; }