Bertini 2 - C++ Core
Software for Numerical Algebraic Geometry
Loading...
Searching...
No Matches
io/parsing/settings_parsers/endgames.hpp
Go to the documentation of this file.
1//This file is part of Bertini 2.
2//
3//bertini2/io/parsing/settings_parsers/endgames.hpp is free software: you can redistribute it and/or modify
4//it under the terms of the GNU General Public License as published by
5//the Free Software Foundation, either version 3 of the License, or
6//(at your option) any later version.
7//
8//bertini2/io/parsing/settings_parsers/endgames.hpp is distributed in the hope that it will be useful,
9//but WITHOUT ANY WARRANTY; without even the implied warranty of
10//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11//GNU General Public License for more details.
12//
13//You should have received a copy of the GNU General Public License
14//along with bertini2/io/parsing/settings_parsers/endgames.hpp. If not, see <http://www.gnu.org/licenses/>.
15//
16// Copyright(C) 2015 - 2017 by Bertini2 Development Team
17//
18// See <http://www.gnu.org/licenses/> for a copy of the license,
19// as well as COPYING. Bertini2 is provided with permitted
20// additional terms in the b2/licenses/ directory.
21
22
28
29#pragma once
30
31
34
35
36namespace bertini {
37 namespace parsing {
38 namespace classic {
39
40
41
45 template<typename Iterator, typename Skipper> //boost::spirit::unused_type
46 struct ConfigSettingParser<Iterator, bertini::endgame::SecurityConfig, Skipper> : qi::grammar<Iterator, bertini::endgame::SecurityConfig(), Skipper>
47 {
48 using T = double;
49
50 ConfigSettingParser() : ConfigSettingParser::base_type(root_rule_, "SecurityConfig")
51 {
52
53 namespace phx = boost::phoenix;
54 using qi::_1;
55 using qi::_2;
56 using qi::_3;
57 using qi::_4;
58 using qi::_val;
59 using qi::eps;
60 using qi::lit;
61 using qi::char_;
62 using qi::omit;
63 using boost::spirit::lexeme;
64 using boost::spirit::as_string;
65 using boost::spirit::ascii::no_case;
66
67
68
69 std::string level_name = "securitylevel";
70 std::string maxnorm_name = "securitymaxnorm";
71
72
73 root_rule_.name("config::Security");
74
75 root_rule_ = ((security_level_[phx::bind( [this](bertini::endgame::SecurityConfig & S, int l)
76 {
77 S.level = l;
78 }, _val, _1 )]
79 ^ security_max_norm_[phx::bind( [this](bertini::endgame::SecurityConfig & S, T norm)
80 {
81 S.max_norm = norm;
82 }, _val, _1 )])
83 >> -no_setting_) | no_setting_;
84
85 all_names_ = (no_case[level_name] >> ':') | (no_case[maxnorm_name] >> ':');
86
87 security_level_.name("security_level_");
88 security_level_ = *(char_ - all_names_) >> (no_case[level_name] >> ':') >> qi::int_[_val = _1] >> ';';
89
90 security_max_norm_.name("security_max_norm_");
91 security_max_norm_ = *(char_ - all_names_) >> (no_case[maxnorm_name] >> ':')
92 >> mpfr_rules.number_string_[phx::bind( [this](T & num, std::string str)
93 {
94 num = bertini::NumTraits<T>::FromString(str);
95 }, _val, _1 )] >> ';';
96
97 no_setting_.name("no_setting_");
98 no_setting_ = *(char_ - all_names_);
99
100 no_decl_.name("no_decl_");
101 no_decl_ = *(char_);
102
103
104
105
106 using phx::val;
107 using phx::construct;
108 using namespace qi::labels;
109 qi::on_error<qi::fail>
110 ( root_rule_ ,
111 std::cout<<
112 val("config parser could not complete parsing. Expecting ")<<
113 _4<<
114 val(" here: ")<<
115 construct<std::string>(_3,_2)<<
116 std::endl
117 );
118
119
120
121 }
122
123
124 private:
125 qi::rule<Iterator, bertini::endgame::SecurityConfig(), ascii::space_type > root_rule_;
126 qi::rule<Iterator, int(), ascii::space_type > security_level_;
127 qi::rule<Iterator, T(), ascii::space_type > security_max_norm_;
128 qi::rule<Iterator, ascii::space_type, std::string()> no_decl_, no_setting_, all_names_;
129 rules::LongNum<Iterator> mpfr_rules;
130
131
132
133 }; //re: SecurityParser
134
135
136
137
138
142 template<typename Iterator, typename Skipper> //boost::spirit::unused_type
143 struct ConfigSettingParser<Iterator, bertini::endgame::EndgameConfig, Skipper> : qi::grammar<Iterator, bertini::endgame::EndgameConfig(), Skipper>
144 {
145 using T = double;
146 using R = mpq_rational;
147
148 ConfigSettingParser() : ConfigSettingParser::base_type(root_rule_, "EndgameConfig")
149 {
150 namespace phx = boost::phoenix;
151 using qi::_1;
152 using qi::_2;
153 using qi::_3;
154 using qi::_4;
155 using qi::_val;
156 using qi::eps;
157 using qi::lit;
158 using qi::char_;
159 using qi::omit;
160 using boost::spirit::lexeme;
161 using boost::spirit::as_string;
162 using boost::spirit::ascii::no_case;
163
164
165
166 std::string samplefactor_name = "samplefactor";
167 std::string numpoints_name = "numsamplepoints";
168 std::string mintrack_name = "nbhdradius";
169
170
171 root_rule_.name("config::Endgame");
172
173 root_rule_ = ((sample_factor_[phx::bind( [this](bertini::endgame::EndgameConfig & S, R num)
174 {
175 S.sample_factor = num;
176 }, _val, _1 )]
177 ^ min_track_[phx::bind( [this](bertini::endgame::EndgameConfig & S, T num)
178 {
179 S.min_track_time = num;
180 }, _val, _1 )]
181 ^ num_sample_[phx::bind( [this](bertini::endgame::EndgameConfig & S, unsigned num)
182 {
183 S.num_sample_points = num;
184 }, _val, _1 )])
185
186 >> -no_setting_)
187 | no_setting_;
188
189
190 all_names_ = (no_case[samplefactor_name] >> ':') | (no_case[numpoints_name] >> ':')| (no_case[mintrack_name] >> ':');
191
192 sample_factor_.name("sample_factor_");
193 sample_factor_ = *(char_ - all_names_) >> (no_case[samplefactor_name] >> ':')
194 >> mpfr_rules.rational[phx::bind( [this](R & num, std::string str)
195 {
196 num = bertini::NumTraits<double>::FromString(str);
197 }, _val, _1 )] >> ';';
198
199 min_track_.name("min_track_");
200 min_track_ = *(char_ - all_names_) >> (no_case[mintrack_name] >> ':')
201 >> mpfr_rules.number_string_[phx::bind( [this](T & num, std::string str)
202 {
203 num = bertini::NumTraits<T>::FromString(str);
204 }, _val, _1 )] >> ';';
205
206 num_sample_.name("num_sample_");
207 num_sample_ = *(char_ - all_names_) >> (no_case[numpoints_name] >> ':')
208 >> qi::uint_[_val=_1] >> ';';
209
210 no_setting_.name("no_setting_");
211 no_setting_ = *(char_ - all_names_);
212
213 no_decl_.name("no_decl_");
214 no_decl_ = *(char_);
215
216
217
218
219
220 using phx::val;
221 using phx::construct;
222 using namespace qi::labels;
223 qi::on_error<qi::fail>
224 ( root_rule_ ,
225 std::cout<<
226 val("config parser could not complete parsing. Expecting ")<<
227 _4<<
228 val(" here: ")<<
229 construct<std::string>(_3,_2)<<
230 std::endl
231 );
232
233
234
235 }
236
237
238 private:
239 qi::rule<Iterator, bertini::endgame::EndgameConfig(), ascii::space_type > root_rule_;
240 qi::rule<Iterator, R(), ascii::space_type > sample_factor_;
241 qi::rule<Iterator, T(), ascii::space_type > min_track_;
242 qi::rule<Iterator, unsigned int(), ascii::space_type > num_sample_;
243 qi::rule<Iterator, ascii::space_type, std::string()> no_decl_, no_setting_, all_names_;
244 rules::LongNum<Iterator> mpfr_rules;
245 }; //re: EndgameParser
246
247
248
249
250
254 template<typename Iterator, typename Skipper> //boost::spirit::unused_type
255 struct ConfigSettingParser<Iterator, bertini::endgame::PowerSeriesConfig, Skipper> : qi::grammar<Iterator, bertini::endgame::PowerSeriesConfig(), Skipper>
256 {
257 using T = double;
258
259 ConfigSettingParser() : ConfigSettingParser::base_type(root_rule_, "bertini::endgame::PowerSeriesConfigType")
260 {
261 namespace phx = boost::phoenix;
262 using qi::_1;
263 using qi::_2;
264 using qi::_3;
265 using qi::_4;
266 using qi::_val;
267 using qi::eps;
268 using qi::lit;
269 using qi::char_;
270 using qi::omit;
271 using boost::spirit::lexeme;
272 using boost::spirit::as_string;
273 using boost::spirit::ascii::no_case;
274
275
276
277 std::string maxcycle_name = "maxcyclenum";
278
279
280 root_rule_.name("bertini::endgame::PowerSeriesConfig");
281
282 root_rule_ = (max_cycle_[phx::bind( [this](bertini::endgame::PowerSeriesConfig & S, unsigned num)
283 {
284 S.max_cycle_number = num;
285 }, _val, _1 )]
286
287 >> -no_setting_)
288 | no_setting_;
289
290
291
292 all_names_ = eps >> (no_case[maxcycle_name] >> ':');
293
294 max_cycle_.name("max_cycle_");
295 max_cycle_ = *(char_ - all_names_) >> (no_case[maxcycle_name] >> ':') >> qi::uint_[_val=_1] >> ';';
296
297 no_setting_.name("no_setting_");
298 no_setting_ = *(char_ - all_names_);
299
300 no_decl_.name("no_decl_");
301 no_decl_ = *(char_);
302
303
304
305
306
307 using phx::val;
308 using phx::construct;
309 using namespace qi::labels;
310 qi::on_error<qi::fail>
311 ( root_rule_ ,
312 std::cout<<
313 val("config parser could not complete parsing. Expecting ")<<
314 _4<<
315 val(" here: ")<<
316 construct<std::string>(_3,_2)<<
317 std::endl
318 );
319
320
321
322 }
323
324
325 private:
326 qi::rule<Iterator, bertini::endgame::PowerSeriesConfig(), Skipper> root_rule_;
327 qi::rule<Iterator, unsigned int(), ascii::space_type > max_cycle_;
328 qi::rule<Iterator, ascii::space_type, std::string()> no_decl_, no_setting_, all_names_;
329 }; //re: PowerSeriesParser
330
331
332
333
334
338 template<typename Iterator, typename Skipper> //boost::spirit::unused_type
339 struct ConfigSettingParser<Iterator, bertini::endgame::CauchyConfig, Skipper> : qi::grammar<Iterator, bertini::endgame::CauchyConfig(), Skipper>
340 {
341 using T = double;
342
343 ConfigSettingParser() : ConfigSettingParser::base_type(root_rule_, "bertini::endgame::CauchyConfig")
344 {
345 namespace phx = boost::phoenix;
346 using qi::_1;
347 using qi::_2;
348 using qi::_3;
349 using qi::_4;
350 using qi::_val;
351 using qi::eps;
352 using qi::lit;
353 using qi::char_;
354 using qi::omit;
355 using boost::spirit::lexeme;
356 using boost::spirit::as_string;
357 using boost::spirit::ascii::no_case;
358
359
360
361 std::string cyclecutoff_name = "cycletimecutoff";
362 std::string ratiocutoff_name = "ratiotimecutoff";
363
364
365 root_rule_.name("config::Cauchy");
366
367 root_rule_ = ((cycle_cutoff_[phx::bind( [this](bertini::endgame::CauchyConfig & S, T num)
368 {
369 S.cycle_cutoff_time = num;
370 }, _val, _1 )]
371 ^ ratio_cutoff_[phx::bind( [this](bertini::endgame::CauchyConfig & S, T num)
372 {
373 S.ratio_cutoff_time = num;
374 }, _val, _1 )])
375 >> -no_setting_) | no_setting_;
376
377 all_names_ = (no_case[cyclecutoff_name] >> ':') | (no_case[ratiocutoff_name] >> ':');
378
379 cycle_cutoff_.name("cycle_cutoff_");
380 cycle_cutoff_ = *(char_ - all_names_) >> (no_case[cyclecutoff_name] >> ':')
381 >> mpfr_rules.number_string_[phx::bind( [this](T & num, std::string str)
382 {
383 num = bertini::NumTraits<T>::FromString(str);
384 }, _val, _1 )] >> ';';
385
386 ratio_cutoff_.name("ratio_cutoff_");
387 ratio_cutoff_ = *(char_ - all_names_) >> (no_case[ratiocutoff_name] >> ':')
388 >> mpfr_rules.number_string_[phx::bind( [this](T & num, std::string str)
389 {
390 num = bertini::NumTraits<T>::FromString(str);
391 }, _val, _1 )] >> ';';
392
393 no_setting_.name("no_setting_");
394 no_setting_ = *(char_ - all_names_);
395
396 no_decl_.name("no_decl_");
397 no_decl_ = *(char_);
398
399
400
401
402 using phx::val;
403 using phx::construct;
404 using namespace qi::labels;
405 qi::on_error<qi::fail>
406 ( root_rule_ ,
407 std::cout<<
408 val("config parser could not complete parsing. Expecting ")<<
409 _4<<
410 val(" here: ")<<
411 construct<std::string>(_3,_2)<<
412 std::endl
413 );
414
415
416
417 }
418
419
420 private:
421 qi::rule<Iterator, bertini::endgame::CauchyConfig(), ascii::space_type > root_rule_;
422 qi::rule<Iterator, T(), ascii::space_type > cycle_cutoff_, ratio_cutoff_;
423 qi::rule<Iterator, ascii::space_type, std::string()> no_decl_, no_setting_, all_names_;
424 rules::LongNum<Iterator> mpfr_rules;
425
426
427
428 }; //re: CauchyParser
429
430
431
432 template<typename Iterator, typename Skipper> //boost::spirit::unused_type
433 struct ConfigSettingParser<Iterator, bertini::endgame::TrackBackConfig, Skipper> : qi::grammar<Iterator, bertini::endgame::TrackBackConfig(), Skipper>
434 {
435 using T = double;
436
437 ConfigSettingParser() : ConfigSettingParser::base_type(root_rule_, "bertini::endgame::TrackBackConfig")
438 {
439 namespace phx = boost::phoenix;
440 using qi::_1;
441 using qi::_2;
442 using qi::_3;
443 using qi::_4;
444 using qi::_val;
445 using qi::eps;
446 using qi::lit;
447 using qi::char_;
448 using qi::omit;
449 using boost::spirit::lexeme;
450 using boost::spirit::as_string;
451 using boost::spirit::ascii::no_case;
452
453
454
455 std::string min_cycle_name = "mincycletrackback";
456 std::string junk_removal_name = "junkremovaltrackback";
457 std::string maxdepth_name = "maxldtdepth";
458
459 root_rule_.name("bertini::endgame::TrackBackConfig");
460
461 root_rule_ = root_rule_ = ((min_cycle_[phx::bind( [this](bertini::endgame::TrackBackConfig & S, unsigned num)
462 {
463 S.minimum_cycle = num;
464 }, _val, _1 )]
465 ^ junk_removal_[phx::bind( [this](bertini::endgame::TrackBackConfig & S, int num)
466 {
467 S.junk_removal_test = static_cast<bool>(num);
468 }, _val, _1 )]
469 ^ max_depth_[phx::bind( [this](bertini::endgame::TrackBackConfig & S, unsigned num)
470 {
471 S.max_depth_LDT = num;
472 }, _val, _1 )]
473 )
474 >> -no_setting_) | no_setting_;
475
476
477
478 all_names_ = eps >> (no_case[min_cycle_name] >> ':') |
479 (no_case[junk_removal_name] >> ':') |
480 (no_case[maxdepth_name] >> ':');
481
482 min_cycle_.name("min_cycle_");
483 min_cycle_ = *(char_ - all_names_) >> (no_case[min_cycle_name] >> ':') >> qi::uint_[_val=_1] >> ';';
484
485 junk_removal_.name("junk_removal_");
486 junk_removal_ = *(char_ - all_names_) >> (no_case[junk_removal_name] >> ':') >> qi::int_[_val=_1] >> ';';
487
488 max_depth_.name("max_depth_");
489 max_depth_ = *(char_ - all_names_) >> (no_case[maxdepth_name] >> ':') >> qi::uint_[_val=_1] >> ';';
490
491 no_setting_.name("no_setting_");
492 no_setting_ = *(char_ - all_names_);
493
494 no_decl_.name("no_decl_");
495 no_decl_ = *(char_);
496
497
498
499
500
501 using phx::val;
502 using phx::construct;
503 using namespace qi::labels;
504 qi::on_error<qi::fail>
505 ( root_rule_ ,
506 std::cout<<
507 val("config parser could not complete parsing. Expecting ")<<
508 _4<<
509 val(" here: ")<<
510 construct<std::string>(_3,_2)<<
511 std::endl
512 );
513
514
515
516 }
517
518
519 private:
520 qi::rule<Iterator, bertini::endgame::TrackBackConfig(), Skipper> root_rule_;
521 qi::rule<Iterator, unsigned int(), ascii::space_type > min_cycle_, max_depth_;
522 qi::rule<Iterator, int(), ascii::space_type > junk_removal_;
523 qi::rule<Iterator, ascii::space_type, std::string()> no_decl_, no_setting_, all_names_;
524 }; //re: TrackBackParser
525
526
527
528
529
530 } // re: namespace classic
531
532 }// re: namespace parsing
533}// re: namespace bertini
Provides the base type for config settings parsers.
Configs and settings for endgames.