LEMUR Packages: ompl_lemur or_lemur pr_bgl prpy_lemur
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Groups Pages
params_lemur.h
Go to the documentation of this file.
1 
7 namespace or_lemur
8 {
9 
10 // remember, <startstate> and <goalstate> can be specified multiple times
11 class LEMURParameters : public OpenRAVE::PlannerBase::PlannerParameters
12 {
13 public:
14 
15  bool has_roadmap_type;
16  std::string roadmap_type;
17 
18  // key/value strings for roadmap (keys without roadmap. prefix)
19  std::vector< std::pair<std::string,std::string> > roadmap_params;
20 
21  bool has_do_roadmap_save;
22  bool do_roadmap_save;
23 
24  bool has_num_batches_init;
25  unsigned int num_batches_init;
26 
27  bool has_alglog;
28  std::string alglog;
29 
30  bool has_do_alglog_append;
31  bool do_alglog_append;
32 
33  bool has_graph;
34  std::string graph;
35 
36  bool has_check_cost;
37  double check_cost;
38 
39  bool has_coeff_distance;
40  double coeff_distance;
41 
42  bool has_coeff_checkcost;
43  double coeff_checkcost;
44 
45  bool has_coeff_batch;
46  double coeff_batch;
47 
48  bool has_do_timing;
49  bool do_timing;
50 
51  bool has_persist_roots;
52  bool persist_roots;
53 
54  bool has_max_batches;
55  unsigned int max_batches;
56 
57  bool has_time_limit;
58  double time_limit;
59 
60  bool has_search_type;
61  std::string search_type;
62 
63  bool has_search_incbi_heur_interp;
64  double search_incbi_heur_interp;
65 
66  bool has_search_incbi_balancer_type;
67  std::string search_incbi_balancer_type;
68 
69  bool has_search_incbi_balancer_goalfrac;
70  double search_incbi_balancer_goalfrac;
71 
72  bool has_eval_type;
73  std::string eval_type;
74 
75  bool has_solve_all;
76  bool solve_all;
77 
78  bool has_do_baked;
79  bool do_baked;
80 
82  has_roadmap_type(false),
83  has_do_roadmap_save(false),
84  has_num_batches_init(false),
85  has_alglog(false),
86  has_do_alglog_append(false),
87  has_graph(false),
88  has_check_cost(false),
89  has_coeff_distance(false),
90  has_coeff_checkcost(false),
91  has_coeff_batch(false),
92  has_do_timing(false),
93  has_persist_roots(false),
94  has_max_batches(false),
95  has_time_limit(false),
96  has_search_type(false),
97  has_search_incbi_heur_interp(false),
98  has_search_incbi_balancer_type(false),
99  has_search_incbi_balancer_goalfrac(false),
100  has_eval_type(false),
101  has_solve_all(false),
102  has_do_baked(false)
103  {
104  // top-level tags we can process
105  _vXMLParameters.push_back("roadmap_type");
106  _vXMLParameters.push_back("roadmap_param");
107  _vXMLParameters.push_back("do_roadmap_save");
108  _vXMLParameters.push_back("num_batches_init");
109  _vXMLParameters.push_back("alglog");
110  _vXMLParameters.push_back("do_alglog_append");
111  _vXMLParameters.push_back("graph");
112  _vXMLParameters.push_back("check_cost");
113  _vXMLParameters.push_back("coeff_distance");
114  _vXMLParameters.push_back("coeff_checkcost");
115  _vXMLParameters.push_back("coeff_batch");
116  _vXMLParameters.push_back("do_timing");
117  _vXMLParameters.push_back("persist_roots");
118  _vXMLParameters.push_back("max_batches");
119  _vXMLParameters.push_back("time_limit");
120  _vXMLParameters.push_back("search_type");
121  _vXMLParameters.push_back("search_incbi_heur_interp");
122  _vXMLParameters.push_back("search_incbi_balancer_type");
123  _vXMLParameters.push_back("search_incbi_balancer_goalfrac");
124  _vXMLParameters.push_back("eval_type");
125  _vXMLParameters.push_back("solve_all");
126  _vXMLParameters.push_back("do_baked");
127  }
128 
129 private:
130  std::string lemur_deserializing;
131 
132 protected:
133  bool serialize(std::ostream& sout, int options=0) const
134  {
135  if (!OpenRAVE::PlannerBase::PlannerParameters::serialize(sout,options))
136  return false;
137  if (has_roadmap_type)
138  sout << "<roadmap_type>" << roadmap_type << "</roadmap_type>";
139  for (unsigned int ui=0; ui<roadmap_params.size(); ui++)
140  {
141  sout << "<roadmap_param>"
142  << roadmap_params[ui].first << "=" << roadmap_params[ui].second
143  << "</roadmap_param>";
144  }
145  if (has_do_roadmap_save)
146  sout << "<do_roadmap_save>" << (do_roadmap_save?"true":"false") << "</do_roadmap_save>";
147  if (has_num_batches_init)
148  sout << "<num_batches_init>" << num_batches_init << "</num_batches_init>";
149  if (has_alglog)
150  sout << "<alglog>" << alglog << "</alglog>";
151  if (has_do_alglog_append)
152  sout << "<do_alglog_append>" << (do_alglog_append?"true":"false") << "</do_alglog_append>";
153  if (has_graph)
154  sout << "<graph>" << graph << "</graph>";
155  if (has_check_cost)
156  sout << "<check_cost>" << check_cost << "</check_cost>";
157  if (has_coeff_distance)
158  sout << "<coeff_distance>" << coeff_distance << "</coeff_distance>";
159  if (has_coeff_checkcost)
160  sout << "<coeff_checkcost>" << coeff_checkcost << "</coeff_checkcost>";
161  if (has_coeff_batch)
162  sout << "<coeff_batch>" << coeff_batch << "</coeff_batch>";
163  if (has_do_timing)
164  sout << "<do_timing>" << (do_timing?"true":"false") << "</do_timing>";
165  if (has_persist_roots)
166  sout << "<persist_roots>" << (persist_roots?"true":"false") << "</persist_roots>";
167  if (has_max_batches)
168  sout << "<max_batches>" << max_batches << "</max_batches>";
169  if (has_time_limit)
170  sout << "<time_limit>" << time_limit << "</time_limit>";
171  if (has_search_type)
172  sout << "<search_type>" << search_type << "</search_type>";
173  if (has_search_incbi_heur_interp)
174  sout << "<search_incbi_heur_interp>" << search_incbi_heur_interp << "</search_incbi_heur_interp>";
175  if (has_search_incbi_balancer_type)
176  sout << "<search_incbi_balancer_type>" << search_incbi_balancer_type << "</search_incbi_balancer_type>";
177  if (has_search_incbi_balancer_goalfrac)
178  sout << "<search_incbi_balancer_goalfrac>" << search_incbi_balancer_goalfrac << "</search_incbi_balancer_goalfrac>";
179  if (has_eval_type)
180  sout << "<eval_type>" << eval_type << "</eval_type>";
181  if (has_solve_all)
182  sout << "<solve_all>" << (solve_all?"true":"false") << "</solve_all>";
183  if (has_do_baked)
184  sout << "<do_baked>" << (do_baked?"true":"false") << "</do_baked>";
185  return !!sout;
186  }
187 
188  OpenRAVE::BaseXMLReader::ProcessElement startElement(
189  const std::string & name, const OpenRAVE::AttributesList & atts)
190  {
191  if (lemur_deserializing.size())
192  return PE_Ignore;
193  // ask base calss
194  enum OpenRAVE::BaseXMLReader::ProcessElement base;
195  base = OpenRAVE::PlannerBase::PlannerParameters::startElement(name,atts);
196  if (base != PE_Pass) return base;
197  // can we handle it?
198  if (name == "roadmap_type"
199  || name == "roadmap_param"
200  || name == "do_roadmap_save"
201  || name == "num_batches_init"
202  || name == "alglog"
203  || name == "do_alglog_append"
204  || name == "graph"
205  || name == "check_cost"
206  || name == "coeff_distance"
207  || name == "coeff_checkcost"
208  || name == "coeff_batch"
209  || name == "do_timing"
210  || name == "persist_roots"
211  || name == "max_batches"
212  || name == "time_limit"
213  || name == "search_type"
214  || name == "search_incbi_heur_interp"
215  || name == "search_incbi_balancer_type"
216  || name == "search_incbi_balancer_goalfrac"
217  || name == "eval_type"
218  || name == "solve_all"
219  || name == "do_baked")
220  {
221  lemur_deserializing = name;
222  _ss.str("");
223  return PE_Support;
224  }
225  return PE_Pass;
226  }
227 
228  bool endElement(const std::string & name)
229  {
230  if (!lemur_deserializing.size())
231  return OpenRAVE::PlannerBase::PlannerParameters::endElement(name);
232  if (name == lemur_deserializing)
233  {
234  if (lemur_deserializing == "roadmap_type")
235  {
236  roadmap_type = _ss.str();
237  has_roadmap_type = true;
238  }
239  if (lemur_deserializing == "roadmap_param")
240  {
241  std::string roadmap_param = _ss.str();
242  size_t eq = roadmap_param.find('=');
243  if (eq != roadmap_param.npos)
244  roadmap_params.push_back(std::make_pair(
245  roadmap_param.substr(0,eq), roadmap_param.substr(eq+1)));
246  else
247  RAVELOG_WARN("no = found in roadmap_param!\n");
248  }
249  if (lemur_deserializing == "do_roadmap_save")
250  {
251  std::ios state(0);
252  state.copyfmt(_ss);
253  _ss >> std::boolalpha >> do_roadmap_save;
254  _ss.copyfmt(state);
255  has_do_roadmap_save = true;
256  }
257  if (lemur_deserializing == "num_batches_init")
258  {
259  _ss >> num_batches_init;
260  has_num_batches_init = true;
261  }
262  if (lemur_deserializing == "alglog")
263  {
264  alglog = _ss.str();
265  has_alglog = true;
266  }
267  if (lemur_deserializing == "do_alglog_append")
268  {
269  std::ios state(0);
270  state.copyfmt(_ss);
271  _ss >> std::boolalpha >> do_alglog_append;
272  _ss.copyfmt(state);
273  has_do_alglog_append = true;
274  }
275  if (lemur_deserializing == "graph")
276  {
277  graph = _ss.str();
278  has_graph = true;
279  }
280  if (lemur_deserializing == "check_cost")
281  {
282  _ss >> check_cost;
283  has_check_cost = true;
284  }
285  if (lemur_deserializing == "coeff_distance")
286  {
287  _ss >> coeff_distance;
288  has_coeff_distance = true;
289  }
290  if (lemur_deserializing == "coeff_checkcost")
291  {
292  _ss >> coeff_checkcost;
293  has_coeff_checkcost = true;
294  }
295  if (lemur_deserializing == "coeff_batch")
296  {
297  _ss >> coeff_batch;
298  has_coeff_batch = true;
299  }
300  if (lemur_deserializing == "do_timing")
301  {
302  std::ios state(0);
303  state.copyfmt(_ss);
304  _ss >> std::boolalpha >> do_timing;
305  _ss.copyfmt(state);
306  has_do_timing = true;
307  }
308  if (lemur_deserializing == "persist_roots")
309  {
310  std::ios state(0);
311  state.copyfmt(_ss);
312  _ss >> std::boolalpha >> persist_roots;
313  _ss.copyfmt(state);
314  has_persist_roots = true;
315  }
316  if (lemur_deserializing == "max_batches")
317  {
318  _ss >> max_batches;
319  has_max_batches = true;
320  }
321  if (lemur_deserializing == "time_limit")
322  {
323  _ss >> time_limit;
324  has_time_limit = true;
325  }
326  if (lemur_deserializing == "search_type")
327  {
328  search_type = _ss.str();
329  has_search_type = true;
330  }
331  if (lemur_deserializing == "search_incbi_heur_interp")
332  {
333  _ss >> search_incbi_heur_interp;
334  has_search_incbi_heur_interp = true;
335  }
336  if (lemur_deserializing == "search_incbi_balancer_type")
337  {
338  search_incbi_balancer_type = _ss.str();
339  has_search_incbi_balancer_type = true;
340  }
341  if (lemur_deserializing == "search_incbi_balancer_goalfrac")
342  {
343  _ss >> search_incbi_balancer_goalfrac;
344  has_search_incbi_balancer_goalfrac = true;
345  }
346  if (lemur_deserializing == "eval_type")
347  {
348  eval_type = _ss.str();
349  has_eval_type = true;
350  }
351  if (lemur_deserializing == "solve_all")
352  {
353  std::ios state(0);
354  state.copyfmt(_ss);
355  _ss >> std::boolalpha >> solve_all;
356  _ss.copyfmt(state);
357  has_solve_all = true;
358  }
359  if (lemur_deserializing == "do_baked")
360  {
361  std::ios state(0);
362  state.copyfmt(_ss);
363  _ss >> std::boolalpha >> do_baked;
364  _ss.copyfmt(state);
365  has_do_baked = true;
366  }
367  }
368  else
369  RAVELOG_WARN("closing tag doesnt match opening tag!\n");
370  lemur_deserializing.clear();
371  return false;
372  }
373 };
374 
375 typedef boost::shared_ptr<LEMURParameters> LEMURParametersPtr;
376 typedef boost::shared_ptr<LEMURParameters const> LEMURParametersConstPtr;
377 
378 } // namespace or_lemur
Definition: params_lemur.h:11