realroot_doc 0.1.1
|
00001 /******************************************************************* 00002 * This file is part of the source code of the realroot kernel. 00003 * Author(s): B. Mourrain, GALAAD, INRIA 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]"<<std::endl; 00030 return; 00031 } else if (string(argv[i]) == string("-v")) 00032 verbose=true; 00033 else if (string(argv[i]) == string("-q")) 00034 verbose=false; 00035 else if (string(argv[i]) == string("-n")) 00036 N = atoi(argv[i+1]); 00037 00038 std::ifstream in(argv[1],std::ios::in); 00039 if(!in.good()) { 00040 std::cout<<"file: "<<argv[1]<<std::endl; 00041 return; 00042 } 00043 std::string s; 00044 typedef POL upol_t; 00045 Seq<POL> L; 00046 POL p; 00047 int nbp=0; 00048 int deg=0; 00049 variables Vr("x"); 00050 while(xml::read(in,p,Vr) && (N==0 || nbp < N)) { 00051 L<<p; 00052 deg= std::max(deg,degree(p)); 00053 nbp++; 00054 } 00055 int nr=0; 00056 for(typename Seq<POL>::const_iterator it = L.begin(); it != L.end(); ++it) { 00057 if(verbose) { 00058 xml::print(std::cout,*it,"polynomial")<<std::endl; 00059 typename SLV::Solutions sol; 00060 SLV::solve(sol,*it); 00061 nr+= sol.size(); 00062 xml::print(std::cout,sol,"solution")<<std::endl; 00063 } else { 00064 typename SLV::Solutions sol; 00065 start = clock(); 00066 SLV::solve(sol,*it); 00067 end = clock(); total += (end - start); 00068 nr+= sol.size(); 00069 } 00070 } 00071 cout << "<nb_pol>" << nbp << "</nb_pol>"; 00072 cout << "<degree>" << deg << "</degree>"; 00073 cout << "<nb_root>" <<nr<<"</nb_root>"; 00074 if(!verbose) { 00075 cout << "<time>" << (total / CLOCKS_PER_SEC) << "</time> "; 00076 cout << "<speed>" << int(nr/(total / CLOCKS_PER_SEC)) << "</speed>"; 00077 } 00078 std::cout<<std::endl; 00079 } 00080 00081 } 00082 //==================================================================== 00083 #endif //realroot_solver_hpp