QpRandomDriver.cxx

Go to the documentation of this file.
00001 #include <stdlib.h>
00002 #include "Riostream.h"
00003 
00004 #include "TQpDataDens.h"
00005 #include "TQpVar.h"
00006 #include "TQpProbDens.h"
00007 #include "TGondzioSolver.h"
00008 
00009 Bool_t SolutionMatches(TQpVar *vars,TQpVar *soln,TQpVar *temp,Double_t tol);
00010 
00011 int main(int argc,char *argv[])
00012 {
00013   Int_t n1 = 5, m1 = 2, m2 = 2;
00014   if (argc >= 4) {
00015     n1 = atoi(argv[1]);
00016     m1 = atoi(argv[2]);
00017     m2 = atoi(argv[3]);
00018   } else {
00019     cout << endl 
00020          << " Usage: QpRandomDriver n my mz " << endl
00021          << " where n  = # primal variables, " << endl
00022          << "       my = # equality constraints, " << endl
00023          << "       mz = # inequality constraints " << endl << endl;
00024     return 1;
00025   }
00026 
00027   Int_t nnzQ = (Int_t) .20*(n1*n1);
00028   Int_t nnzA = (Int_t) .15*(m1*n1);
00029   Int_t nnzC = (Int_t) .10*(m2*n1);
00030 
00031   if (nnzQ < 3*n1) nnzQ = 3*n1;
00032   if (nnzA < 3*m1) nnzA = 3*m1;
00033   if (nnzC < 3*m2) nnzC = 2*m2;
00034 
00035   TQpProbDens *qp = new TQpProbDens(n1,m1,m2);
00036   TQpDataDens *prob;
00037   TQpVar *soln;
00038   qp->MakeRandomData(prob,soln,0,0,0);
00039 //  qp->MakeRandomData(prob,soln,nnzQ,nnzA,nnzC);
00040   TQpVar      *vars  = qp->MakeVariables(prob);
00041   TQpResidual *resid = qp->MakeResiduals(prob);
00042 
00043   TGondzioSolver *s = new TGondzioSolver(qp,prob);
00044   
00045   const Int_t status = s->Solve(prob,vars,resid);
00046   delete s;
00047 
00048   if (status == 0) {
00049     cout.precision(4);
00050     cout << endl << "Computed solution:\n\n" <<endl <<endl;
00051     vars->fX.Print();
00052 
00053     TQpVar *temp = qp->MakeVariables(prob);
00054 
00055     cout << endl << "Checking the solution...";
00056     if (SolutionMatches(vars,soln,temp,1e-4)) {
00057       cout << "The solution appears to be correct." <<endl;
00058     } else {
00059       cout << endl << "The solution may be wrong "
00060         "(or the generated problem may be ill conditioned.)" <<endl;
00061     }
00062     delete temp;
00063   } else {
00064     cout << "Could not solve this problem." <<endl;
00065   }
00066 
00067   delete vars;
00068   delete soln;
00069   delete prob;
00070   delete qp;
00071 
00072   return status;
00073 }
00074 
00075 Bool_t SolutionMatches(TQpVar *vars,TQpVar *soln,TQpVar *temp,double tol)
00076 {
00077   temp = vars;
00078 
00079   // Only x is  significant
00080   temp->fX -= soln->fX;
00081 
00082   if ((temp->fX).NormInf()/(1+(soln->fX).NormInf()) < tol)
00083     return kTRUE;
00084   else
00085     return kFALSE;
00086 }
00087 

Generated on Tue Jul 5 15:15:07 2011 for ROOT_528-00b_version by  doxygen 1.5.1