00001
00002
00003
00004
00005 # ifndef realroot_solver_run_hpp
00006 # define realroot_solver_run_hpp
00007
00008 # include <string>
00009 # include <fstream>
00010 # include <realroot/polynomial_xml.hpp>
00011 # include <realroot/solver.hpp>
00012 # define begin_polynomial "<polynomial"
00013 # define end_polynomial "</polynomial>"
00014
00015 namespace mmx {
00016
00017 template<class POL, class SLV>
00018 void run_solver(int argc, char** argv){
00019 double total=0,start,end;
00020
00021 using std::cout;
00022 using std::endl;
00023 using std::string;
00024
00025 int N=0;
00026 bool verbose=true;
00027 for(int i=0;i<argc;i++)
00028 if (string(argv[i]) == string("-h")) {
00029 std::cout<<"Usage: "<<argv[0]<<" file [-h|-q|-v|-prec]\n"
00030 <<" -q : quiet computation\n"
00031 <<" -v : verbose computation\n"
00032 <<" -prec N : precision of result with N digits"
00033 <<std::endl;
00034 return;
00035 } else if (string(argv[i]) == string("-v"))
00036 verbose=true;
00037 else if (string(argv[i]) == string("-q"))
00038 verbose=false;
00039 else if (string(argv[i]) == string("-prec"))
00040 N = atoi(argv[i+1]);
00041
00042 std::ifstream in(argv[1],std::ios::in);
00043 if(!in.good()) {
00044 std::cout<<"file: "<<argv[1]<<std::endl;
00045 return;
00046 }
00047 std::string s;
00048 typedef POL upol_t;
00049 Seq<POL> L;
00050 POL p;
00051 int nbp=0;
00052 int deg=0;
00053 variables Vr("x");
00054 while(xml::read(in,p,Vr) && (N==0 || nbp < N)) {
00055 L<<p;
00056 deg= std::max(deg,degree(p));
00057 nbp++;
00058 }
00059 int nr=0;
00060 for(typename Seq<POL>::const_iterator it = L.begin(); it != L.end(); ++it) {
00061 if(verbose) {
00062 xml::print(std::cout,*it,"polynomial")<<std::endl;
00063 typename SLV::Solutions sol;
00064 if(N>0) SLV::set_precision(N);
00065 SLV::solve(sol,*it);
00066 nr+= sol.size();
00067 xml::print(std::cout,sol,"solution")<<std::endl;
00068 } else {
00069 typename SLV::Solutions sol;
00070 start = clock();
00071 SLV::solve(sol,*it);
00072 end = clock(); total += (end - start);
00073 nr+= sol.size();
00074 }
00075 }
00076 cout << "<nb_pol>" << nbp << "</nb_pol>";
00077 cout << "<degree>" << deg << "</degree>";
00078 cout << "<nb_root>" <<nr<<"</nb_root>";
00079 if(!verbose) {
00080 cout << "<time>" << (total / CLOCKS_PER_SEC) << "</time> ";
00081 cout << "<speed>" << int(nr/(total / CLOCKS_PER_SEC)) << "</speed>";
00082 }
00083 std::cout<<std::endl;
00084 }
00085
00086 }
00087
00088 #endif //realroot_solver_hpp