Developer documentation

solver_run.hpp
Go to the documentation of this file.
1 /*******************************************************************
2  * This file is part of the source code of the realroot kernel.
3  * Author(s): B. Mourrain, GALAAD, INRIA
4  ********************************************************************/
5 # ifndef realroot_solver_run_hpp
6 # define realroot_solver_run_hpp
7 //====================================================================
8 # include <string>
9 # include <fstream>
11 # include <realroot/solver.hpp>
12 #include <ctime>
13 # define begin_polynomial "<polynomial"
14 # define end_polynomial "</polynomial>"
15 //====================================================================
16 namespace mmx {
17 
18  template<class POL, class SLV>
19  void run_solver(int argc, char** argv){
20  double total=0,start,end;
21 
22  using std::cout;
23  using std::endl;
24  using std::string;
25 
26  int N=0;
27  bool verbose=true;
28  for(int i=0;i<argc;i++)
29  if (string(argv[i]) == string("-h")) {
30  std::cout<<"Usage: "<<argv[0]<<" file [-h|-q|-v]"<<std::endl;
31  return;
32  } else if (string(argv[i]) == string("-v"))
33  verbose=true;
34  else if (string(argv[i]) == string("-q"))
35  verbose=false;
36  else if (string(argv[i]) == string("-n"))
37  N = atoi(argv[i+1]);
38 
39  std::ifstream in(argv[1],std::ios::in);
40  if(!in.good()) {
41  std::cout<<"file: "<<argv[1]<<std::endl;
42  return;
43  }
44  std::string s;
45  //typedef POL upol_t;
46  Seq<POL> L;
47  POL p;
48  int nbp=0;
49  int deg=0;
50  variables Vr("x");
51  while(xml::read(in,p,Vr) && (N==0 || nbp < N)) {
52  L<<p;
53  deg= std::max(deg,degree(p));
54  nbp++;
55  }
56  int nr=0;
57  for(typename Seq<POL>::const_iterator it = L.begin(); it != L.end(); ++it) {
58  if(verbose) {
59  xml::print(std::cout,*it,"polynomial")<<std::endl;
60  typename SLV::Solutions sol;
61  SLV::solve(sol,*it);
62  nr+= sol.size();
63  xml::print(std::cout,sol,"solution")<<std::endl;
64  } else {
65  typename SLV::Solutions sol;
66  start = clock();
67  SLV::solve(sol,*it);
68  end = clock(); total += (end - start);
69  nr+= sol.size();
70  }
71  }
72  cout << "<nb_pol>" << nbp << "</nb_pol>";
73  cout << "<degree>" << deg << "</degree>";
74  cout << "<nb_root>" <<nr<<"</nb_root>";
75  if(!verbose) {
76  cout << "<time>" << (total / CLOCKS_PER_SEC) << "</time> ";
77  cout << "<speed>" << int(nr/(total / CLOCKS_PER_SEC)) << "</speed>";
78  }
79  std::cout<<std::endl;
80  }
81 
82 }
83 //====================================================================
84 #endif //realroot_solver_hpp
iterator end()
Definition: Seq.hpp:88
bool read(ISTREAM &is, polynomial< C, R > &p, variables &V)
Read a polynomial, enclosed in polynomial tags.
Definition: polynomial_xml.hpp:41
dynamic_exp< E >::degree_t degree(const dynamic_exp< E > &t)
Definition: dynamicexp.hpp:191
iterator begin()
Definition: Seq.hpp:87
TMPL int N(const MONOMIAL &v)
Definition: monomial_glue.hpp:60
Seq< typename ContFrac< NT, LB >::root_t > solve(const typename ContFrac< NT >::Poly &f, ContFrac< NT, LB >)
Definition: contfrac.hpp:164
OSTREAM & print(OSTREAM &os, const X &x, const char *tag)
Definition: polynomial_xml.hpp:16
bool in(const T &x, const Interval< T, r > &y)
Definition: Interval_fcts.hpp:100
TMPL POL
Definition: polynomial_dual.hpp:74
void run_solver(int argc, char **argv)
Definition: solver_run.hpp:19
Interval< T, r > max(const Interval< T, r > &a, const Interval< T, r > &b)
Definition: Interval_fcts.hpp:135
Definition: array.hpp:12
Definition: variables.hpp:65
Home