Paramotopy
parallel parameter homotopy through bertini
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
xml_preferences.cpp
Go to the documentation of this file.
1 #include "xml_preferences.hpp"
2 
3 //NUMPOSSIBLE_SAVEFILES is set in xml_preferences.hpp
4 const char * const ProgSettings::possible_savefiles[NUMPOSSIBLE_SAVEFILES] =
5 { "real_solutions", "nonsingular_solutions", "singular_solutions", "raw_data", "raw_solutions","main_data","midpath_data" };
6 
7 
8 //NUMMANDATORY_SAVEFILES is set in xml_preferences.hpp
9 const char * const ProgSettings::mandatory_savefiles[NUMMANDATORY_SAVEFILES] =
10 { "failed_paths" };
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 //writes a config header for a bertini input file to the configname file.
24 //this is based entirely off data stored in the preferences, eliminating the need for the user to have to
25 //carry around their own config files.
27 
28  std::stringstream config;
29  //note that bertini parses right over white space. input files can also be commented.
30  config << "CONFIG\n%this config automatically generated by paramotopy\n\n";
31  settingmap::iterator iter;
32  for (iter=settings["step1bertini"].begin(); iter != settings["step1bertini"].end(); iter++){
33  std::string setting_name = (*iter).first;
34  config << setting_name << ": "
35  << settings["step1bertini"][setting_name].value() << ";\n";
36  }
37 
38  config << "END;\n\n";
39  return config.str();
40 }
41 
42 
43 
44 //writes a config header for a bertini input file to the configname file.
45 //this is based entirely off data stored in the preferences, eliminating the need for the user to have to
46 //carry around their own config files.
48 
49 
50 
51  std::stringstream config;
52  //note that bertini parses right over white space. input files can also be commented with percent signs.
53  config << "CONFIG\n%this config automatically generated by paramotopy\n\n";
54 
55  settingmap::iterator iter;
56 
57  for (iter=settings["step2bertini"].begin(); iter != settings["step2bertini"].end(); iter++){
58  std::string setting_name = (*iter).first;
59  config << setting_name << ": "
60  << settings["step2bertini"][setting_name].value() << ";\n";
61  }
62  if (this->settings["mode"]["standardstep2"].intvalue==1){ // if not a standard step2, doing regular bertini runs on multiple
63  // parameter points
64  config << "USERHOMOTOPY: 1;\n";
65  }
66  config << "END;\n\n";
67 
68  return config.str();
69 }
70 
71 
72 //writes a config header for a bertini input file to the configname file.
73 //this is based entirely off data stored in the preferences, eliminating the need for the user to have to
74 //carry around their own config files.
76 
77 
78  std::stringstream config;
79  //note that bertini parses right over white space. input files can also be commented with percent signs.
80  config << "CONFIG\n%this config automatically generated by paramotopy\n\n";
81 
82  settingmap::iterator iter;
83 
84  for (iter=settings["PathFailureBertiniCurrent"].begin(); iter != settings["PathFailureBertiniCurrent"].end(); iter++){
85  std::string setting_name = (*iter).first;
86  config << setting_name << ": "
87  << settings["PathFailureBertiniCurrent"][setting_name].value() << ";\n";
88  }
89  if (this->settings["mode"]["standardstep2"].intvalue==1){ // if not a standard step2, doing regular bertini runs on multiple
90  // parameter points
91  config << "USERHOMOTOPY: 1;\n";
92  }
93  config << "END;\n\n";
94 
95  return config.str();
96 }
97 
98 
99 
100 
101 
102 
103 
104 
105 
106 
107 
108 
109 
110 //related to path failure analysis
112  settings["PathFailureBertiniCurrent"]["TRACKTOLBEFOREEG"].doubvalue = 0.1*settings["PathFailureBertiniCurrent"]["TRACKTOLBEFOREEG"].doubvalue;
113  settings["PathFailureBertiniCurrent"]["TRACKTOLDURINGEG"].doubvalue = 0.1*settings["PathFailureBertiniCurrent"]["TRACKTOLDURINGEG"].doubvalue;
114  settings["PathFailureBertiniCurrent"]["FINALTOL"].doubvalue = 0.1*settings["PathFailureBertiniCurrent"]["FINALTOL"].doubvalue;
115 
117 
118  return;
119 }
120 
121 
123 
124  settings["PathFailureBertiniBase"].clear();
125  settingmap::iterator iter;
126 
127  for (iter=settings["step2bertini"].begin(); iter != settings["step2bertini"].end(); iter++){
128  std::string setting_name = (*iter).first;
129  switch (settings["step2bertini"][setting_name].type) {
130  case 0:
131  setValue("PathFailureBertiniBase",setting_name,settings["step2bertini"][setting_name].value());
132  break;
133  case 1:
134  setValue("PathFailureBertiniBase",setting_name,settings["step2bertini"][setting_name].intvalue);
135  break;
136  case 2:
137  setValue("PathFailureBertiniBase",setting_name,settings["step2bertini"][setting_name].doubvalue);
138  break;
139  default:
140  break;
141  }
142  }
143 
145 
146  return;
147 }
148 //sets path failure settings from the PathFailureBertiniBase settings
150 
151  settings["PathFailureBertiniCurrent"].clear();
152  settingmap::iterator iter;
153 
154  for (iter=settings["PathFailureBertiniBase"].begin(); iter != settings["PathFailureBertiniBase"].end(); iter++){
155  std::string setting_name = (*iter).first;
156  switch (settings["PathFailureBertiniBase"][setting_name].type) {
157  case 0:
158  setValue("PathFailureBertiniCurrent",setting_name,settings["PathFailureBertiniBase"][setting_name].value());
159  break;
160  case 1:
161  setValue("PathFailureBertiniCurrent",setting_name,settings["PathFailureBertiniBase"][setting_name].intvalue);
162  break;
163  case 2:
164  setValue("PathFailureBertiniCurrent",setting_name,settings["PathFailureBertiniBase"][setting_name].doubvalue);
165  break;
166  default:
167  break;
168  }
169  }
170 
172 
173  return;
174 }
175 
176 
177 
178 
179 
180 
181 
182 
183 
184 
185 
186 
187 
189 
190  setValue("files","writemeshtomc",int(0));
191  setValue("files","customtmplocation",0);
192  setValue("files","tempfilelocation",boost::filesystem::path("."));
193  setValue("files","newfilethreshold",67108864);
194 
195  setValue("system","buffersize",65536);
196  setValue("system","stifle",int(0));
197 
198  for (int j=0; j<NUMMANDATORY_SAVEFILES; ++j) {
199  setValue("SaveFiles",mandatory_savefiles[j],1);
200  }
201 
202  for (int j = 0; j < NUMPOSSIBLE_SAVEFILES;++j){
203  setValue("SaveFiles",possible_savefiles[j],0);
204  // if (settings["SaveFiles"][possible_savefiles[j]].intvalue != 1){//!FilePrefVector[j]
205  // std::cout << j+1 << ") " << possible_savefiles[j] << "\n";
206  // }
207  }
208 
209  setValue("SaveFiles","nonsingular_solutions",1);
210  setValue("SaveFiles","real_solutions",1);
211 
212 
213  setValue("parallelism","usemachine",int(0));
214  setValue("parallelism","parallel",int(1));
215  setValue("parallelism","architecture",std::string("mpiexec"));
216  setValue("parallelism","numprocs",int(2));
217  setValue("parallelism","numfilesatatime",100);
218 
219  setValue("files","newrandom_newfolder",0);
220  setValue("files","previousdatamethod",1);
221  setValue("files","deletetmpfilesatend",1);
222 
223  setValue("mode","main_mode",0);
224  setValue("mode","startfilename",std::string("nonsingular_solutions"));
225  setValue("mode","standardstep2",1); // do a parameter homotopy from a start file by default
226  return;
227 }
228 
229 
231 
232  // these should all be the same as default bertini settings.
233  settings["step1bertini"].clear();
234  setValue("step1bertini","TRACKTOLBEFOREEG",1e-5);
235  setValue("step1bertini","TRACKTOLDURINGEG",1e-6);
236  setValue("step1bertini","FINALTOL",1e-11);
237  setValue("step1bertini","IMAGTHRESHOLD",1e-8);
239  return;
240 }
241 
242 
244 
245  // these should all be the same as default bertini settings.
246  settings["step2bertini"].clear();
247  setValue("step2bertini","TRACKTOLBEFOREEG",1e-5);
248  setValue("step2bertini","TRACKTOLDURINGEG",1e-6);
249  setValue("step2bertini","FINALTOL",1e-11);
250  setValue("step2bertini","IMAGTHRESHOLD",1e-8);
252  return;
253 }
254 
256  settings["PathFailureBertiniBase"].clear();
257  //the bertini defaults from the user's manual
258  setValue("PathFailureBertiniBase","TRACKTOLBEFOREEG",1e-5);
259  setValue("PathFailureBertiniBase","TRACKTOLDURINGEG",1e-6);
260  setValue("PathFailureBertiniBase","FINALTOL",1e-11);
261  setValue("PathFailureBertiniBase","IMAGTHRESHOLD",1e-8);
263  return;
264 }
265 
267 
268  setValue("PathFailure","newrandommethod",1);
269  setValue("PathFailure","tightentolerances",1);
270  setValue("PathFailure","maxautoiterations",1);
272  return;
273 }
274 
275 
276 
277 //switching for calling specific functions to get required settings. i did this to try to avoid a mess of if then statements.
279 
280  switch (settingcase) {
281 
282 
283 
284 
285 
286 
287 
288 
289 
290  //parallelism
291  case 001:
293  break;
294  case 002:
296  break;
297  case 003:
299  break;
300 
301  //files
302 
303 
304  case 102:
306  break;
307  case 103:
309  break;
310 
311  case 105:
313  break;
314  case 106:
316  break;
317  case 107:
319  break;
320  case 108:
322  break;
323  case 109:
325  break;
326 
327 
328 
329 
330  //mode
331  case 201:
333  break;
334  case 202:
336  break;
337  case 203:
339  break;
340 
341 
342 
343  //system
344  case 300:
345  ProgSettings::FindProgram("bertini","system","bertinilocation");//step2 is the program name
346  break;
347  case 301:
348  ProgSettings::FindProgram("step2","system","step2location");//step2 is the program name
349  break;
350  case 302:
352  break;
353  case 303:
355  break;
356 
357  default:
358 
359  std::cout << "GetPref code not yet written for case " << settingcase << "\n";
360  break;
361  }
362  return;
363 };
364 
365 
366 //checks whether have a set of required settings
368 
369  bool made_changes = false;
370 
371  std::stringstream menustream;
372  std::map<std::string,std::pair< int, std::string > >::iterator iter;
373 
374  static std::map< std::string,std::pair< int, std::string> > main_required_values;
375 
376  //parallelism
377  main_required_values["architecture"].first = 001; main_required_values["architecture"].second = "parallelism";
378  main_required_values["parallel"].first = 002; main_required_values["parallel"].second = "parallelism";
379  main_required_values["numfilesatatime"].first = 003; main_required_values["numfilesatatime"].second = "parallelism";
380 
381  //files
382  main_required_values["writemeshtomc"].first = 102; main_required_values["writemeshtomc"].second = "files";
383  main_required_values["deletetmpfilesatend"].first = 103; main_required_values["deletetmpfilesatend"].second = "files";
384  main_required_values["previousdatamethod"].first = 105; main_required_values["previousdatamethod"].second = "files";
385  main_required_values["newrandom_newfolder"].first = 106; main_required_values["newrandom_newfolder"].second = "files";
386  main_required_values["saveprogresseverysomany"].first = 107; main_required_values["saveprogresseverysomany"].second = "files";
387  main_required_values["newfilethreshold"].first = 108; main_required_values["newfilethreshold"].second = "files";
388  main_required_values["tempfilelocation"].first = 109; main_required_values["tempfilelocation"].second = "files";
389 
390 
391 
392 
393 
394  //mode
395  main_required_values["standardstep2"].first = 201; main_required_values["standardstep2"].second = "mode";
396  main_required_values["main_mode"].first = 202; main_required_values["main_mode"].second = "mode";
397  main_required_values["startfilename"].first = 203; main_required_values["startfilename"].second = "mode";
398  //adding a required value here requires adding a ProgSettings::Get___() function, and adding an option to switch
399 
400 
401 
402 
403 
404  //system
405  main_required_values["bertinilocation"].first = 300; main_required_values["bertinilocation"].second = "system";
406  main_required_values["step2location"].first = 301; main_required_values["step2location"].second = "system";
407  main_required_values["stifle"].first = 302; main_required_values["stifle"].second = "system";
408  main_required_values["buffersize"].first = 303; main_required_values["buffersize"].second = "system";
409 
410  //iterate over the main setting map, for each of the above settings.
411  for (iter=main_required_values.begin(); iter != main_required_values.end(); iter++) {
412  if (settings[(*iter).second.second].find( (*iter).first) == settings[(*iter).second.second].end() )
413  // search in cat name for setting of cat name
414  { // if fail to find a setting of the name in the category.
415  ProgSettings::RequiredSettingsSwitcharoo( (*iter).second.first ); // feed in the integer
416  made_changes = true;
417  }
418  }
419  return made_changes;
420 }
421 
422 
423 
424 
425 
426 
427 
428 
429 
430 
431 void ProgSettings::GetProgramLocationManual(std::string program_name, std::string category_name, std::string setting_name){
432 
433  size_t found;
434  std::string path_to_detect;
435  std::cout << "please supply the path to " << program_name << ". (% cancels) \n: \n";
436  path_to_detect = getAlphaNumeric();
437 
438  path_to_detect = replace_tilde_with_home(path_to_detect);
439 
440  found=path_to_detect.find('%');
441  if ( (int(found)==0) ) {
442  return;
443  }
444 
445  boost::filesystem::path temp_path(path_to_detect);
446  temp_path /= program_name;
447  while (! boost::filesystem::exists(temp_path)) {
448  std::cout << program_name << " program not found at " << temp_path.string() << ". please supply the path (% cancels)\n: \n";
449  path_to_detect = getAlphaNumeric();
450  found=path_to_detect.find('%');
451  if ( (int(found)==0) ) {
452  return;
453  }
454  temp_path = boost::filesystem::path(path_to_detect);
455  temp_path /= program_name;
456  }
457 
458  boost::filesystem::path final_path = boost::filesystem::canonical(boost::filesystem::absolute(path_to_detect));
459 
460  setValue(category_name,setting_name,final_path);
461 
462  std::cout << program_name << " location set to " << final_path.string() << std::endl;
463  return;
464 }
465 
466 //locates the .
467 void ProgSettings::FindProgram(std::string program_name, std::string category_name, std::string setting_name){
468 
469  bool found_program = false;
470 
471 
472  if (haveSetting(category_name,setting_name)) {
473  boost::filesystem::path stored_location(settings[category_name][setting_name].pathvalue);
474  stored_location /= program_name;
475  if (boost::filesystem::exists(stored_location)){
476  stored_location = boost::filesystem::canonical(boost::filesystem::absolute(stored_location));
477  setValue(category_name,setting_name,stored_location.parent_path());
478  found_program = true;
479  }
480 
481 
482  }
483 
484  if (found_program == false ){
485  boost::filesystem::path here = "./";
486  here /= program_name;
487 
488  if (boost::filesystem::exists(here)){ // if have the step2 program in current directory, set location of it to here.
489  here = boost::filesystem::absolute(here);
490  setValue(category_name,setting_name,here.parent_path());
491  found_program = true;
492  }
493  else{ //if step2 is not in the current directory, then scan the path for it.
494 
495  char * temp_path;
496  temp_path = getenv ("PATH");
497  if (temp_path!=NULL){
498  std::string path = std::string(temp_path);
499  //have the path variable. will scan for the mystep2 program.
500 
501 
502 
503  size_t found;
504  found = path.find(':');
505  while (found!=std::string::npos) { //if found the delimiter ':'
506  boost::filesystem::path path_to_detect(path.substr(0,found)); //the part of the path to scan for mystep2
507  path = path.substr(found+1,path.length()-found); // the remainder of the path. will scan later.
508  found = path.find(':'); // get the next indicator of the ':' delimiter.
509  path_to_detect /= program_name;
510  if (boost::filesystem::exists(path_to_detect)){
511  //found the mystep2 program!
512 
513  setValue(category_name,setting_name,path_to_detect.parent_path());
514  found_program = true;
515  break;
516 
517  }
518  else{
519  //did not find it yet...
520  }
521  }// re:while
522  }//re: if temp_path!=null
523  else{ //the path variable was null. WTF?
524  std::cerr << "unable to scan $PATH for step2.\n";
525 
526  }
527  }
528  }
529 
530 
531  if (found_program == false){
532  std::string path_to_detect;
533  std::cout << program_name << " program not found in current directory or PATH.\nplease supply the path to " << program_name << ".\n: ";
534  path_to_detect = getAlphaNumeric();
535  boost::filesystem::path temp_path(path_to_detect);
536  temp_path /= program_name;
537  while (! boost::filesystem::exists(temp_path)) {
538  std::cout << program_name << " program not found at that location. please supply the path: \n";
539  path_to_detect = getAlphaNumeric();
540  temp_path = boost::filesystem::path(path_to_detect);
541  temp_path /= program_name;
542  }
543  setValue(category_name,setting_name,boost::filesystem::path(path_to_detect) );
544  }
545 
546 
547  boost::filesystem::path final_path = boost::filesystem::canonical(boost::filesystem::absolute(settings[category_name][setting_name].pathvalue));
548 
549  setValue(category_name,setting_name,final_path);
550 
551  return;
552 }// re: find_program
553 
554 
555 
556 
557 
558 
559 //gets files to save from user. also sets to save all mandatory files.
561 
562  for (int j = 0; j < NUMPOSSIBLE_SAVEFILES; ++j) {
563  setValue("SaveFiles",possible_savefiles[j],0);
564  }
565 
566 
567  int selection = -1;
568  while (selection!=0){
569  std::cout << "\n\nPossible files to save:\n\n";
570  for (int j = 0; j < NUMPOSSIBLE_SAVEFILES;++j){
571  if (settings["SaveFiles"][possible_savefiles[j]].intvalue != 1){
572  std::cout << j+1 << ") " << possible_savefiles[j] << "\n";
573  }
574  }
575  std::cout << "*\n" << 0 << ") Done.\n";
576  selection = get_int_choice("Select the file you would like to save : ",0,NUMPOSSIBLE_SAVEFILES);
577 
578 
579  if (selection!=0){
580  setValue("SaveFiles",possible_savefiles[selection-1],1);
581  }
582  }
583  //done setting files to save for this run.
584 
585 
586  for (int j=0; j<NUMMANDATORY_SAVEFILES; ++j) {
587  setValue("SaveFiles",mandatory_savefiles[j],1);
588  }
590 };
591 
592 
593 //gives false bool if didn't have all the files previously noted for saving state. true if did.
595  bool had_all = true;
596  for (int j=0; j<NUMPOSSIBLE_SAVEFILES; ++j) {
597  if (settings["SaveFiles"].find( possible_savefiles[j] ) == settings["SaveFiles"].end()) {
598  had_all = false;
599  }
600  }
601  return had_all;
602 };
603 
604 //
606 //void ProgSettings::GetIndividualFileSave(std::string datafilename){
607 // std::stringstream ss;
608 // ss << "Would you like to save data contained in files named '" << datafilename << "'?\n0 no, 1 yes\n:";
609 // setValue("SaveFiles",datafilename, get_int_choice(ss.str(),0,1));
610 //}
611 
612 
613 
614 
615 
616 
617 
618 
619 
620 
621 
622 
623 
624 
625 //the main function to save the preferences to a xml file.
626 void ProgSettings::save(boost::filesystem::path save_filename){
627 
628  TiXmlDocument* doc = new TiXmlDocument;
629  TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "", "" );
630 
631  doc->LinkEndChild( decl );
632 
633  TiXmlElement * root = new TiXmlElement("paramotopy_preferences");
634  categorymap::iterator iter;
635 
636  //save each catergory
637  for (iter=settings.begin(); iter!= settings.end(); iter++) {
638  ProgSettings::SaveCategoryToXml( (*iter).first , (*iter).second ,root);
639  }
640 
641  //wrap it up
642  doc->LinkEndChild( root );
643 
644  //save it
645  if(doc->SaveFile(save_filename.string().c_str())){ //filename is a data member of ProgSettings class
646  // std::cout << "preferences saved\n";
647  }
648  else{
649  //couldn't save for some reason. this may be a problem on queued systems?
650  std::cout << "preferences *failed* to save to " << save_filename.string() << "!\n";
651  };
652 
653 }
654 
655 
656 
657 //saves one category of settings to the xml file. returns to calling function save() for next category or finalization.
658 int ProgSettings::SaveCategoryToXml(std::string catname, settingmap curr_settings , TiXmlElement* root){
659 
660  TiXmlText* setting_name;
661  TiXmlText* setting_value;
662  TiXmlText* setting_type;
663 
664  std::stringstream ss;
665 
666 
667  TiXmlElement * category_name = new TiXmlElement( catname.c_str() );
668 
669  settingmap::iterator iter;
670  for (iter=curr_settings.begin(); iter != curr_settings.end(); iter++){
671  TiXmlElement* setting_elmnt = new TiXmlElement("setting");
672 
673  const std::string & key=(*iter).first;
674  const std::string & type=(*iter).second.typestr();
675  const std::string & value=(*iter).second.value();
676 
677 
678 
679  setting_name = new TiXmlText(key.c_str());
680  setting_value = new TiXmlText(value.c_str());
681  setting_type = new TiXmlText(type.c_str());
682 
683 
684  TiXmlElement* name_elmnt = new TiXmlElement("name");
685  name_elmnt->LinkEndChild(setting_name);
686  TiXmlElement* value_elmnt = new TiXmlElement("value");
687  value_elmnt->LinkEndChild(setting_value);
688  TiXmlElement* type_elmnt = new TiXmlElement("type");
689  type_elmnt->LinkEndChild(setting_type);
690 
691  setting_elmnt->LinkEndChild(name_elmnt );
692  setting_elmnt->LinkEndChild(value_elmnt );
693  setting_elmnt->LinkEndChild( type_elmnt);
694 
695 
696  category_name->LinkEndChild(setting_elmnt);
697 
698 
699  }
700  root->LinkEndChild(category_name);
701 
702  return 0;
703 }
704 
705 
706 
707 int ProgSettings::check_for_existing_prefs_auto(boost::filesystem::path & load_filename, boost::filesystem::path pFilename){
708 
709 
710  int found_a_file;
711  if (boost::filesystem::exists(pFilename)) {
712  load_filename = pFilename;
713  found_a_file = 1;
714  }
715  else{
716  std::cout << "failed to find the desired settings file" << pFilename << std::endl;
717  load_filename = ProgSettings::default_name();
718  if (boost::filesystem::exists(load_filename)) {
719  found_a_file = 2;
720  }
721  else
722  {
723  found_a_file = 0;
724  }
725  }
726 
727 
728  return found_a_file;
729 
730 }
731 
732 
733 
734 boost::filesystem::path ProgSettings::default_name(){
735  boost::filesystem::path defaultsettings(getenv("HOME"));
736  defaultsettings /= ".paramotopy/defaultprefs.xml";
737  return defaultsettings;
738 }
739 
740 
741 boost::filesystem::path ProgSettings::make_settings_name(boost::filesystem::path newfilename){
742 
743  boost::filesystem::path settingsfilename(getenv("HOME"));
744  settingsfilename /= ".paramotopy/";
745  settingsfilename /= newfilename;
746  settingsfilename += "prefs.xml";
747  return settingsfilename;
748 }
749 
750 
752 
753  boost::filesystem::path load_filename;
754 
755  boost::filesystem::path source_folder = getenv("HOME");
756  source_folder /= ".paramotopy";
757 
758  std::string expression = "prefs.xml\\z"; //specify beginning of string
759  expression.append("");
760  std::vector < boost::filesystem::path > filelist = FindFiles(source_folder, expression); //this function is in para_aux_funcs
761 
762 
763  std::stringstream menu;
764  int choice = -1;
765 
766  menu << "found these preferences file:\n-----------------\n0) current (no change)\n";
767  for (int ii=0; ii<int(filelist.size()); ii++) {
768  boost::filesystem::path temppath = filelist[ii];
769 
770  menu << ii+1 << ") " << temppath.filename() << std::endl;
771  }
772  menu << "--------\nwhich to load?";
773 
774  choice = get_int_choice(menu.str(),0,filelist.size());
775  switch (choice) {
776  case 0:
777  //do nothing, not loading.
778  break;
779 
780 
781  default:
782  // load the user's choice.
783  ProgSettings::load(filelist[choice-1].string().c_str());
784  break;
785  }
786 
787 
788 
789 
790 
791 
792 
793 
794 }
795 
796 //attempts to open the pFilename. if cannot, checks for required values. also goes through reset if xml file is broken.
797 void ProgSettings::load(boost::filesystem::path pFilename){
798 
799  // this->filename = pFilename;
800  bool changesmade=false, load_defaults = false, doc_loaded = false;
801 
802  //clear the old settings from memory.
803  //TODO: change this to an iterator operation
804 
805  // this->settings.clear();
806  //
807  settings["parallelism"].clear();
808  settings["step1bertini"].clear();
809  settings["step2bertini"].clear();
810  settings["PathFailure"].clear();
811  settings["SaveFiles"].clear();
812  settings["files"].clear();
813  settings["system"].clear();
814 
815 
816  boost::filesystem::path load_filename;
817  int found_a_file = check_for_existing_prefs_auto(load_filename, pFilename);//set the value of load_filename
818  //returns 0 if neither desired nor default file is found.
819  // 1 if the desired file is found
820  // 2 if only default is found, instead of desired.
821 
822 
823  if (this->filename.string().size()==0) { // unset
824  // std::cout << "changing filename" << std::endl;
825  this->filename = load_filename;
826  }
827 
828  if (found_a_file==0 || found_a_file==2) {
829  changesmade=true;
830  }
831 
832  if (found_a_file>0){
833  std::cout << "loading preferences from " << load_filename.string() << "\n";
834  TiXmlDocument* doc = new TiXmlDocument(load_filename.string().c_str());
835  doc_loaded = doc->LoadFile();
836 
837 
838  if (!doc_loaded) {
839  changesmade = true;
840  load_defaults = true;
841  }
842  else {
843 
844  TiXmlHandle hDoc(doc);
845  TiXmlElement* pElem;
846  TiXmlHandle hRoot(0);
847 
848 
849  pElem=hDoc.FirstChildElement().Element();
850  // should always have a valid root but handle gracefully if it doesn't
851 
852  if (!pElem) {
853  std::cerr << "bad xml file for prefs. :( todo: check for backup\n";
854  load_defaults = true;
855  changesmade=true;
856  }
857  else{
858  std::string main_name =pElem->Value();
859 
860  hRoot=TiXmlHandle(pElem); // the handle for the data we will be reading
861 
862  TiXmlElement* catElem=hRoot.FirstChild().Element();
863  for (catElem; catElem; catElem=catElem->NextSiblingElement()) {
864  ProgSettings::ReadCategoryFromXml(catElem->Value(),hRoot);
865  }
866  }
867  }
868  }
869  else{
870  load_defaults=true;
871  }
872 
873 
874 
875 
876  if (load_defaults) {
877 
878  std::cout << "setting preferences to defaults.\n";
885 
886  changesmade=true;
887  }
888 
889  bool made_changes_required_values = ProgSettings::setRequiredValues(); //check for required settings, and set them if not found already.
890 
891  if (made_changes_required_values) {
892  changesmade = true;
893  }
894 
897  changesmade=true;
898  }
899 
900  ProgSettings::FindProgram("step2","system","step2location");
901  ProgSettings::FindProgram("bertini","system","bertinilocation");
902 
903 
904 
905 
906  if (changesmade) {//only save settings if made a change.
908  }
909 
910  if (load_defaults || (!boost::filesystem::exists(ProgSettings::default_name())) || changesmade) {
912  }
913 
914 
915 
916 }
917 
918 //for reading individual settings categories from the xml file.
919 int ProgSettings::ReadCategoryFromXml(std::string catname, TiXmlHandle hRoot){
920 
921  std::stringstream ss;
922  int type;
923  int intvalue;
924  double doubvalue;
925 
926  TiXmlElement* pElem=hRoot.FirstChild( catname.c_str() ).FirstChild().Element();
927  for( pElem; pElem; pElem=pElem->NextSiblingElement())
928  {
929  TiXmlHandle setting_handle(pElem); //get the handle for the setting
930 
931 
932  TiXmlElement* qElem = setting_handle.FirstChild("name").Element(); //read the name
933  const char *nameText=qElem->GetText();
934 
935  qElem = setting_handle.FirstChild("value").Element(); //read the value
936  const char *valueText=qElem->GetText();
937 
938  qElem = setting_handle.FirstChild("type").Element(); //read the type
939  const char *typeText=qElem->GetText();
940 
941 
942  if (nameText && valueText && typeText)
943  { //setting is ok. set the setting.
944 
945 
946  ss << typeText;
947  ss >> type;
948  ss.clear();
949  ss.str("");
950 
951  //according to type integer (0=string, 1=integer, 2=double), store in the setting map
952  switch (type) {
953  case 0: //string
954  ProgSettings::setValue(catname,nameText,std::string(valueText));
955  break;
956 
957  case 1: //integer
958  ss << valueText;
959  ss >> intvalue;
960  ss.clear();
961  ss.str("");
962  ProgSettings::setValue(catname,nameText,intvalue);
963  break;
964 
965  case 2: //double
966  ss << valueText;
967  ss >> doubvalue;
968  ss.clear();
969  ss.str("");
970  ProgSettings::setValue(catname,nameText,doubvalue);
971  break;
972 
973  case 3: //boost::filesystem::path
974  ProgSettings::setValue(catname,nameText,boost::filesystem::path(valueText));
975  break;
976 
977  default:
978  std::cout << "bad type set somehow, from xml prefs file.\n"
979  << "cat: " << catname << " name: " << nameText << " type: " << type << std::endl;
980  break;
981  }
982 
983  }
984  }
985 
986  return 0;
987 }
988 
989 
990 
991 
992 
993 
994 
995 
996 
997 
998 
999 
1000 
1001 
1002 
1003 
1004 
1006  std::stringstream menu;
1007  menu << "\n\nManage Path Failure Bertini:\n\n"
1008  << "1) Change Setting\n"
1009  << "2) Remove Setting\n"
1010  << "3) Add Setting\n"
1011  << "4) Reset to Default Path Failure Bertini Settings\n"
1012  << "5) Import From current Step2 Settings\n"
1013  << "*\n"
1014  << "0) Go Back\n"
1015  << "\n: ";
1016  int choice = -1001;
1017  while (choice!=0) {
1018  ProgSettings::DisplayCurrentSettings("PathFailureBertiniBase");
1019 
1020  choice = get_int_choice(menu.str(),0,5);
1021 
1022  switch (choice) {
1023  case 0:
1024  break;
1025 
1026  case 1:
1027  ProgSettings::ChangeSetting("PathFailureBertiniBase");
1028  break;
1029 
1030  case 2:
1031  ProgSettings::RemoveSetting("PathFailureBertiniBase");
1032  break;
1033 
1034  case 3:
1035  ProgSettings::AddSetting("PathFailureBertiniBase");
1036  break;
1037 
1038  case 4:
1039  settings["PathFailureBertiniBase"].clear();
1041  break;
1042 
1043  case 5:
1044  settings["PathFailureBertiniBase"].clear();
1046  break;
1047 
1048  default:
1049  std::cout << "somehow an unacceptable entry submitted :(\n";
1050  break;
1051  }
1053 
1054  }
1055  return;
1056 }
1057 
1058 
1059 void ProgSettings::ChangeSetting(std::string category_name){
1060  //first, get setting name
1061  std::string setting_name = "neverusethisname";
1062  size_t found;
1063 
1064  while ( 1 ) {
1065  std::cout << "what is the exact name of setting? % cancels\n: ";
1066  setting_name = getAlphaNumeric();
1067 
1068  boost::to_upper(setting_name);
1069 
1070  found=setting_name.find('%');
1071  if ( (haveSetting(category_name,setting_name)) || (int(found)==0) ) {
1072  break;
1073  }
1074  }
1075 
1076  if (int(found)==0) {
1077  std::cout << "canceling\n";
1078  return;
1079  }
1080 
1081 
1082 
1083 
1084  std::cout << "new value\n:";
1085  std::string newvalue;
1086  newvalue = getAlphaNumeric(); // do type-specific stuff in the switch below.
1087 
1088  std::stringstream converter;
1089  int intie;
1090  double doubie;
1091  switch (settings[category_name][setting_name].type) {
1092  case 0:
1093  setValue(category_name,setting_name,newvalue);
1094  break;
1095  case 1:
1096  converter << newvalue;
1097  converter >> intie;
1098  setValue(category_name,setting_name,intie);
1099  break;
1100  case 2:
1101  converter << newvalue;
1102  converter >> doubie;
1103  setValue(category_name,setting_name,doubie);
1104  break;
1105  default:
1106  break;
1107  }
1109 }
1110 
1111 
1112 // adds a setting to category_name. prompts the user for setting name, type, and value.
1113 void ProgSettings::AddSetting(std::string category_name){
1114  //first, get setting name
1115  std::string setting_name = "neverusethisname";
1116 
1117 
1118  std::cout << "what is the exact name of setting? % cancels\n: ";
1119  setting_name = getAlphaNumeric();
1120 
1121  boost::to_upper(setting_name);
1122 
1123  size_t found=setting_name.find('%');
1124  if ( int(found)==0 ) {
1125  std::cout << "canceling\n";
1126  return;
1127  }
1128 
1129 
1130 
1131  std::stringstream prompt;
1132  prompt << "what is the type of "
1133  << setting_name
1134  << "?\n 0 = string\n 1 = integer / 0-1 bool\n 2= float/double\n\n:";
1135  int typeint = get_int_choice(prompt.str(),0,2);
1136 
1137 
1138  std::cout << "enter setting value" << std::endl << ": ";
1139 
1140 
1141  std::string newvalue = getAlphaNumeric();
1142  std::stringstream converter;
1143  converter << newvalue;
1144  int intie;
1145  double doubie;
1146  switch (typeint) {
1147  case 0:
1148  setValue(category_name,setting_name,converter.str());
1149  break;
1150  case 1:
1151  converter >> intie;
1152  setValue(category_name,setting_name,intie);
1153  break;
1154  case 2:
1155  converter >> doubie;
1156  setValue(category_name,setting_name,doubie);
1157  break;
1158  default:
1159  break;
1160  }
1162  return;
1163 }
1164 
1165 
1166 //removes a setting from a category.
1167 void ProgSettings::RemoveSetting(std::string category_name){
1168  std::string setting_name = "neverusethisname";
1169 
1170  size_t found;
1171 
1172  while (1) {
1173 
1174  std::cout << "what is the exact name of setting? % cancels\n";
1175  setting_name = getAlphaNumeric();
1176 
1177  boost::to_upper(setting_name);
1178 
1179  found=setting_name.find('%');
1180  if ( (haveSetting(category_name,setting_name)) || (int(found)==0) ) {
1181  std::cout << "no setting of that name." << std::endl;
1182  break;
1183  }
1184  }
1185 
1186  if (int(found)==0) {
1187  std::cout << "canceling\n";
1188  return;
1189  }
1190 
1191 
1192  settings[category_name].erase(setting_name);
1193 
1195  return;
1196 }
1197 
1198 
1199 //for a category_name, writes setting names and values to the screen
1200 
1201 void ProgSettings::DisplayCurrentSettings(std::string category_name){
1202 
1203  settingmap::iterator iter;
1204 
1205  int max_name_length = 0;
1206  for (iter=settings[category_name].begin(); iter != settings[category_name].end(); iter++){
1207  std::string setting_name = (*iter).first;
1208  if (int(setting_name.size())>max_name_length) {
1209  max_name_length = int(setting_name.size());
1210  }
1211  }
1212 
1213  int min_dist = 5;
1214 
1215  std::cout << "\n\n" << category_name << " current settings:\n"
1216  << " -name-";
1217  for (int i=0; i< max_name_length+min_dist-9; ++i) {
1218  std::cout << " ";
1219  }
1220  std::cout << "-value-\n";
1221  for (iter=settings[category_name].begin(); iter != settings[category_name].end(); iter++){
1222  std::string setting_name = (*iter).first;
1223  std::cout << setting_name;
1224  for (int i=0; i<(max_name_length+min_dist-int(setting_name.length())); ++i) {
1225  std::cout << " ";
1226  }
1227  std::cout << settings[category_name][(*iter).first].value() << "\n";
1228  }
1229 
1230  return;
1231 }
1232 
1233 
1234 
1235 
1236 
1237 
1238 
1239 
1240 
1241 
1242 
1243 
1244 
1245 
1246 
1247 
1248 
1249 
1250 
1251 
1252 
1253 
1254 
1256  std::stringstream menu;
1257  int choice = -1;
1258  menu << "\n\n\nPreferences Main Menu:\n\n"
1259  << "1) Bertini settings\n"
1260  << "2) Solver Modes\n"
1261  << "3) Path failure resolution\n"
1262  << "4) Parallelism\n"
1263  << "5) Set files to save\n"
1264  << "6) System Settings\n"
1265  << "7) File IO\n"
1266  << "8) MetaSettings\n"
1267  << "*\n0) return to paramotopy\n"
1268  << "\n: ";
1269 
1270 
1271  while (choice!=0) {
1272  choice = get_int_choice(menu.str(),0,8);
1273 
1274  switch (choice) {
1275  case 0:
1276  break;
1277 
1278  case 1:
1280  break;
1281 
1282  case 2:
1284  break;
1285 
1286  case 3:
1288  break;
1289 
1290  case 4:
1292  break;
1293 
1294  case 5:
1296  break;
1297 
1298  case 6:
1300  break;
1301 
1302  case 7:
1304  break;
1305 
1306 
1307  case 8:
1309  break;
1310 
1311  default:
1312  std::cout << "somehow an unacceptable entry submitted to MainMenu :(\n";
1313  break;
1314  }
1315  // ProgSettings::save();
1316  }
1317  return;
1318 }
1319 
1320 
1322  std::stringstream menu;
1323  int choice=-10;
1324 
1325  menu << "\n\nBertini Settings:\n\n"
1326  << "1) Step 1 Settings\n"
1327  << "2) Step 2 Settings\n"
1328  << "3) Path Failure Bertini Settings\n"
1329  << "*\n"
1330  << "0) go back\n"
1331  << "\n: ";
1332  while (choice!=0) {
1333  choice = get_int_choice(menu.str(),0,3);
1334 
1335  switch (choice) {
1336  case 0:
1337 
1338  break;
1339 
1340  case 1:
1342  break;
1343 
1344  case 2:
1346  break;
1347 
1348  case 3:
1350  break;
1351 
1352 
1353  default:
1354  std::cout << "somehow an unacceptable entry submitted to BertiniMenu\n";
1355  //seriously, how did you get here?
1356  break;
1357  }
1358  }
1359  return;
1360 }
1361 
1362 
1363 
1364 
1365 
1366 
1368  std::stringstream menu;
1369  int choice=-10;
1370 
1371  menu << "\n\nSolver Mode Settings:\n\n"
1372  << "1) Brute-force -vs- Search.\n"
1373  << "2) Standard step2 run.\n"
1374  << "3) File to use for step2 start file\n"
1375  << "*\n"
1376  << "0) go back\n"
1377  << "\n: ";
1378  while (choice!=0) {
1380  choice = get_int_choice(menu.str(),0,3);
1381 
1382  switch (choice) {
1383  case 0:
1384 
1385  break;
1386 
1387 
1388  case 1:
1390  break;
1391 
1392 
1393  case 2:
1395  break;
1396 
1397 
1398  case 3:
1400  break;
1401 
1402 
1403  default:
1404  std::cout << "somehow an unacceptable entry submitted to SolverModeMenu\n";
1405  //seriously, how did you get here?
1406  break;
1407  }
1408  }
1409  return;
1410 
1411 
1412 }
1413 
1414 
1416 
1417  std::stringstream menu;
1418  int choice=-10;
1419 
1420  while (choice!=0) {
1421 
1422 
1423  int upper_limit = 1;
1424  menu << "\n\nSearch Settings:\n\n";
1425 
1426 
1427 
1428 
1429  if (this->settings["mode"]["main_mode"].intvalue==1) {
1430  menu
1431  << "1) Turn Search Mode Off.\n"
1432  << "2) Max num searches\t\t" << settings["mode"]["search_iterations"].value() << "\n"
1433  << "3) Desired number solutions\t" << settings["mode"]["search_desirednumber"].value() << "\n"
1434  << "4) Submode -- thresholding for number of posreal\n";
1435  upper_limit = 4;
1436 
1437  if (this->settings["mode"]["search_submode"].intvalue==1) {
1438  menu
1439  << "5) Threshold number for number of posreal solutions at a point\t"
1440  << this->settings["mode"]["search_numposrealthreshold_lower"].intvalue
1441  << " <= numsolns <= ";
1442 
1443  if (this->settings["mode"]["search_numposrealthreshold_upper"].intvalue==-1) {
1444  menu << "inf";}
1445  else{
1446  menu << this->settings["mode"]["search_numposrealthreshold_upper"].intvalue;
1447  }
1448  menu << "\n";
1449  upper_limit = 5;
1450  }
1451 
1452  }
1453  else{
1454  menu
1455  << "1) Turn Search Mode On.\n";
1456  }
1457 
1458 
1459  menu << "*\n"
1460  << "0) go back\n"
1461  << "\n: ";
1462 
1463 
1465  choice = get_int_choice(menu.str(),0,upper_limit);
1466 
1467  switch (choice) {
1468  case 0:
1469 
1470  break;
1471 
1472 
1473  case 1:
1474  if (this->settings["mode"]["main_mode"].intvalue==1) {
1475  setValue("mode","main_mode",0);
1476  }
1477  else{
1478  setValue("mode","main_mode",1);
1479 
1480  if (this->settings["mode"].find("search_iterations") == settings["mode"].end() )
1481  // search in cat name for setting of cat name
1482  { // if fail to find a setting of the name in the category.
1484  }
1485 
1486  if (this->settings["mode"].find("search_desirednumber") == settings["mode"].end() )
1487  // search in cat name for setting of cat name
1488  { // if fail to find a setting of the name in the category.
1490  }
1491 
1492 
1493  }
1495  break;
1496 
1497 
1498  case 2:
1500  break;
1501 
1502  case 3:
1504  break;
1505 
1506 
1507  case 4:
1509  break;
1510 
1511  case 5:
1513  break;
1514 
1515 
1516  default:
1517  std::cout << "somehow an unacceptable entry submitted to SearchMenu\n";
1518  //seriously, how did you get here?
1519  break;
1520  }
1521  }
1522  return;
1523 
1524 }
1525 
1527  std::stringstream menu;
1528  int choice=-10;
1529 
1530  menu << "\n\nSystem Settings:\n\n"
1531  << "1) Stifle Step2 Output\n"
1532  << "2) Change Buffer Size\n"
1533  << "3) Set location of bertini executable\n"
1534  << "4) Set location of step2 executable\n"
1535 
1536  << "*\n"
1537  << "0) go back\n"
1538  << "\n: ";
1539  while (choice!=0) {
1540 
1542  choice = get_int_choice(menu.str(),0,4);
1543 
1544  switch (choice) {
1545  case 0:
1546 
1547  break;
1548 
1549  case 1:
1551  break;
1552 
1553  case 2:
1555  break;
1556 
1557  case 3:
1558  ProgSettings::GetProgramLocationManual("bertini","system","bertinilocation");
1559  break;
1560 
1561  case 4:
1562  ProgSettings::GetProgramLocationManual("step2","system","step2location");
1563  break;
1564 
1565 
1566 
1567  default:
1568  std::cout << "somehow an unacceptable entry submitted to SystemMenu\n";
1569  //seriously, how did you get here?
1570  break;
1571  }
1572  }
1573  return;
1574 }
1575 
1577 
1578  std::stringstream menu;
1579  int choice = -10;
1580  menu << "\n\nFiles, &c:\n\n"
1581  << "1) Which folder to load at startup\n"
1582  << "2) Generation of random values when creating new folder\n"
1583  << "3) Set temp file location / Use ramdisk for temp files\n"
1584  << "4) Max data file Size / New file threshold\n"
1585  << "5) Deletion of temp files at end of run\n"
1586  << "6) Generation of mc mesh file for non-user-def runs\n"
1587 
1588  << "*\n"
1589  << "0) go back\n"
1590  << "\n: ";
1591 
1592 
1593  while (choice!=0) {
1595  choice = get_int_choice(menu.str(),0,6);
1596 
1597  switch (choice) {
1598  case 0:
1599  break;
1600 
1601  case 1:
1603  break;
1604 
1605  case 2:
1607  break;
1608 
1609 
1610  case 3:
1612  break;
1613 
1614 
1615  case 4:
1617  break;
1618 
1619  case 5:
1621  break;
1622 
1623  case 6:
1625  break;
1626 
1627  default:
1628  std::cout << "somehow an unacceptable entry submitted to FileMenu\n";
1629  break;
1630  }
1631  }
1632 
1633 
1634 }
1635 
1636 
1637 //submenu for settings. this one for settings related to parallel
1639 
1640  std::stringstream menu;
1641  int choice = -10;
1642 
1643  menu << "\n\nParallelism:\n\n"
1644  << "1) Switch Parallel On/Off, and consequential others\n"
1645  << "2) Number of Files to send to workers at a time\n"
1646  << "3) Machinefile\n"
1647  << "4) Architecture / calling\n"
1648  << "5) Number of processors used\n"
1649  << "*\n"
1650  << "0) go back\n"
1651  << "\n: ";
1652 
1653  while (choice!=0) {
1654  ProgSettings::DisplayCurrentSettings("parallelism");
1655  choice = get_int_choice(menu.str(),0,5);
1656 
1657  switch (choice) {
1658  case 0:
1659 
1660  break;
1661 
1662  case 1:
1664  break;
1665 
1666  case 2:
1668  break;
1669 
1670  case 3:
1672  break;
1673 
1674  case 4:
1676  break;
1677 
1678  case 5:
1680  break;
1681 
1682 
1683  default:
1684  std::cout << "somehow an unacceptable entry submitted :(\n";
1685  break;
1686  }
1687  }//while
1688  return;
1689 }
1690 
1691 //submenu, for step 1 solve settings.
1693  std::stringstream menu;
1694 
1695  menu << "\n\nStep1 Settings:\n\n"
1696  << "1) Change Setting\n"
1697  << "2) Remove Setting\n"
1698  << "3) Add Setting\n"
1699  << "4) Reset to Default Settings\n"
1700  << "*\n"
1701  << "0) Go Back\n"
1702  << "\n: ";
1703  int choice = -1001;
1704  while (choice!=0) {
1705  ProgSettings::DisplayCurrentSettings("step1bertini");
1706 
1707  choice = get_int_choice(menu.str(),0,4);
1708 
1709  switch (choice) {
1710  case 0:
1711  break;
1712 
1713  case 1:
1714  ProgSettings::ChangeSetting("step1bertini");
1715  break;
1716 
1717  case 2:
1718  ProgSettings::RemoveSetting("step1bertini");
1719  break;
1720 
1721  case 3:
1722  ProgSettings::AddSetting("step1bertini");
1723  break;
1724 
1725  case 4:
1726  settings["step1bertini"].clear();
1728  break;
1729 
1730  default:
1731  std::cout << "somehow an unacceptable entry submitted :(\n";
1732  break;
1733  }
1734  // ProgSettings::save();
1735  }
1736 
1737 
1738  return;
1739 }
1740 
1741 
1742 //sets options for step2 bertini whatnot
1744 
1745  std::stringstream menu;
1746  menu << "\n\nBasic Step2 Settings:\n\n"
1747 
1748  << "1) Change Setting\n"
1749  << "2) Remove Setting\n"
1750  << "3) Add Setting\n"
1751  << "4) Reset to Default Settings\n"
1752  << "*\n"
1753  << "0) Go Back\n"
1754  << "\n: ";
1755  int choice = -1001;
1756  while (choice!=0) {
1757  ProgSettings::DisplayCurrentSettings("step2bertini");
1758 
1759  choice = get_int_choice(menu.str(),0,4);
1760 
1761  switch (choice) {
1762  case 0:
1763  break;
1764 
1765  case 1:
1766  ProgSettings::ChangeSetting("step2bertini");
1767  break;
1768 
1769  case 2:
1770  ProgSettings::RemoveSetting("step2bertini");
1771  break;
1772 
1773  case 3:
1774  ProgSettings::AddSetting("step2bertini");
1775  break;
1776 
1777  case 4:
1778  settings["step2bertini"].clear();
1780  break;
1781 
1782  default:
1783  std::cout << "somehow an unacceptable entry submitted :(\n";
1784  break;
1785  }
1786  // ProgSettings::save();
1787  }
1788  return;
1789 }
1790 
1791 
1792 
1793 //for choosing options for dealing with path failure
1795  std::stringstream menu;
1796  menu << "\n\nPath Failure Settings:\n\n"
1797  << "1) Choose random-start-point Method\n"
1798  << "2) Tolerance Tightening\n"
1799  << "3) Set Num Iterations\n"
1800  << "5) Manage Bertini Settings\n"
1801  << "7) Reset fully to Default path failure Settings\n"
1802  << "*\n"
1803  << "0) Go Back\n"
1804  << "\n: ";
1805  int choice = -1001;
1806  while (choice!=0) {
1807  ProgSettings::DisplayCurrentSettings("PathFailure");
1808  choice = get_int_choice(menu.str(),0,7);
1809 
1810  switch (choice) {
1811  case 0:
1812  break;
1813 
1814  case 1:
1816  break;
1817 
1818 
1819  case 2:
1821  break;
1822 
1823  case 3:
1825  break;
1826 
1827  case 5:
1829  break;
1830  case 7:
1831  settings["PathFailure"].clear();
1833  settings["PathFailureBertiniBase"].clear();
1835  break;
1836  default:
1837  break;
1838  }
1839  }
1840 
1841 
1843  return;
1844 }
1845 
1846 
1847 
1848 //sets the saving of output files from bertini in the step2 process.
1850 
1851  std::stringstream menu;
1852  menu << "\n\nFiles to Save:\n\n"
1853  << "1) Change Files to Save\n"
1854  << "*\n"
1855  << "0) Go Back\n"
1856  << "\n: ";
1857  int choice = -1001;
1858  while (choice!=0) {
1860  choice = get_int_choice(menu.str(),0,1);
1861  switch (choice) {
1862  case 0:
1863  break;
1864 
1865  case 1:
1867  break;
1868 
1869  default:
1870  break;
1871  }
1872  }
1873 
1874 
1875  return;
1876 }
1877 
1878 
1880 
1881 
1882  std::stringstream menu;
1883  menu << "\n\nMeta Settings:\n\n"
1884  << "1) Load a set of settings\n"
1885  << "2) Save current settings as default\n"
1886  << "3) Save the system settings to file\n"
1887  << "*\n"
1888  << "0) Go Back\n"
1889  << "\n: ";
1890  int choice = -1001;
1891  while (choice!=0) {
1892  choice = get_int_choice(menu.str(),0,3);
1893  switch (choice) {
1894  case 0:
1895  break;
1896 
1897  case 1:
1899  break;
1900 
1901  case 2:
1903  break;
1904  case 3:
1906  std::cout << "Saved preferences to " << this->filename << "\n";
1907  break;
1908  default:
1909  break;
1910  }
1911  }
1912  return;
1913 
1914 }
1915 
1916 
1917 
1918 
1919 
1920 
1921 
1922 
1923 
1924 
1925 
1926 
1927 
1928 
1929 
1930 
1931 
1932 
1933 
1934 
1935 
1936 
1937 
1938 
1939 
1940 
1941 
1942 
1943 
1944 
1945 
1946 
1947 
1948 
1949 
1950 
1951 
1952 
1953 
1954 
1955 
1956 
1957 
1958 
1959 
1960 
1961 
1962 
1964  std::stringstream menustream;
1965  std::string valstr;
1966  menustream << "Run Parallel?\n"
1967  << "0) No.\n"
1968  << "1) Yes.\n"
1969  << "Enter choice : ";
1970  int parselect = get_int_choice(menustream.str(), 0, 1);
1971 
1972  if (parselect==0)
1973  setValue("parallelism","parallel",0);
1974  else
1975  setValue("parallelism","parallel",1);
1976 
1977  if (parselect==1){
1980  }//re: if parselect
1981  else{
1982  setValue("parallelism","numfilesatatime",1);
1983  }//re: else
1984  return;
1985 }
1986 
1987 
1988 //changing/setting the archtecture for parallel calling step2 and bertini. eventually this will be deprecated
1990  std::string valstr;
1991  std::stringstream menustream;
1992 
1993  menustream << "Select your command for running parallel processes:\n"
1994  << "0) mpiexec\n"
1995  << "1) aprun\n"
1996  << "2) other... (you will enter your own command [sadly not calling pattern yet :( ])\n:";
1997  int val = get_int_choice(menustream.str(), 0, 2);
1998 
1999  switch (val) {
2000  case 0:
2001  valstr = "mpiexec";
2002  break;
2003  case 1:
2004  valstr = "aprun";
2005  break;
2006  case 2:
2007  std::cout << "enter your own command:\n";
2008  valstr = getAlphaNumeric_WithSpaces();
2009  break;
2010  default:
2011  //how did you get here?
2012  break;
2013  }
2014 
2015  setValue("parallelism","architecture",valstr);
2016 
2017  return;
2018 };
2019 
2021  std::string valstr = "";
2022  int valint = get_int_choice("Does your machine use a machinefile?\n0) No.\n1) Yes.\n: ",0,1);
2023 
2024 
2025 
2026 
2027  if (valint==1) {
2028  boost::filesystem::path home(getenv("HOME"));
2029  size_t found;
2030 
2031  while (1) {
2032  std::cout << "Enter the machine file to be used, relative to your home directory: (% cancels)" << std::endl;
2033 
2034 
2035  if (settings["parallelism"].find("machinefile") != settings["parallelism"].end()) {
2036  std::cout << " enter @ to use previous machinefile " << this->settings["parallelism"]["machinefile"].value() << std::endl;
2037  }
2038 
2039  valstr = getAlphaNumeric();
2040 
2041 
2042 
2043 
2044  found=valstr.find('%');
2045  if ( (int(found)==0) && (settings["parallelism"].find("usemachine") != settings["parallelism"].end()) ) {
2046  return;
2047  }
2048 
2049  found=valstr.find('@');
2050  if ( (settings["parallelism"].find("machinefile") != settings["parallelism"].end()) && (int(found)==0) ) {
2051  valstr = this->settings["parallelism"]["machinefile"].value();
2052  }
2053 
2054  boost::filesystem::path testme = home;
2055  testme /= valstr;
2056 
2057  if (boost::filesystem::exists(testme)) {
2058  break;
2059  }
2060  else{
2061  std::cout << "cannot find that file." << std::endl;
2062  }
2063  }
2064 
2065 
2066 
2067  setValue("parallelism","machinefile",valstr);
2068  }
2069 
2070  setValue("parallelism","usemachine",valint);
2071  return;
2072 };
2073 
2075 
2076  setValue("parallelism","numprocs",get_int_choice( "Enter the number of processes to be run: ",0,9000000));
2077  return;
2078 };
2079 
2081 
2082  int valint = get_int_choice("Enter step2 number of files at a time per processor: (0 for default of 100)",0,9000000);
2083 
2084  if (valint==0){
2085  setValue("parallelism","numfilesatatime",100);
2086  }
2087  else{
2088  setValue("parallelism","numfilesatatime",valint);
2089  }
2090  return;
2091 };
2092 
2094  int val = get_int_choice("Delete temp files at end of runs? (0 for no, 1 for yes)\n:",0,1);
2095  setValue("files","deletetmpfilesatend",val);
2096  return;
2097 };
2098 
2099 
2101 
2102  std::stringstream menustream;
2103 
2104  setValue("files","saveprogresseverysomany",1);
2105  return;
2106 };
2107 
2109 
2110 
2111  int val = get_int_choice("Threshold in bytes for new data file \n (press 0 for default of 67108864 = 2^26): ",0,2147483647);
2112  if (val == 0) {
2113  setValue("files","newfilethreshold",67108864);
2114  }
2115  else{
2116  setValue("files","newfilethreshold",val);
2117  }
2118  return;
2119 };
2120 
2122  std::stringstream menustream;
2123  int val = get_int_choice("How many KB should step2 buffer before writing data to disk? (max 65536K = 64MB)\n (press 0 for default of 64K): ",0,65536);
2124  if (val == 0) {
2125  ProgSettings::setValue("system","buffersize",65536);
2126  }
2127  else{
2128  ProgSettings::setValue("system","buffersize",val*1024);
2129  }
2130  return;
2131 }
2132 
2133 
2134 //detects whether /dev/shm is a location, and if so, offers to use /dev/shm for the temporary files.
2136  std::stringstream menustream;
2137  size_t found;
2138  std::vector< boost::filesystem::path > tmpfile_location_possibilities;
2139 
2140  std::vector< boost::filesystem::path > standard_places_to_look;
2141  standard_places_to_look.push_back("/dev/shm");
2142  standard_places_to_look.push_back("/tmp");
2143 
2144  if (get_int_choice("Would you like to use a custom location for temp files?\n0) No.\n1) Yes.\n: ",0,1)==1){
2145 
2146  setValue("files","customtmplocation",1);
2147  for (int ii=0; ii<int(standard_places_to_look.size()); ++ii) {
2148  if (boost::filesystem::exists(standard_places_to_look[ii])){
2149  tmpfile_location_possibilities.push_back(standard_places_to_look[ii]);
2150  }
2151  }
2152 
2153  if (tmpfile_location_possibilities.size()>0){ //if actually found places
2154  std::cout << "Found these possibilities:\n\n";
2155 
2156  for (int ii = 0; ii< int(tmpfile_location_possibilities.size()); ++ii) {
2157  std::cout << ii << ": " << tmpfile_location_possibilities[ii].string() << std::endl;
2158  }
2159  std::cout << "-or-\n" << tmpfile_location_possibilities.size() << ": specify your own location. (will not check it exists or even works) todo: perform these checks\n\n";
2160 
2161  int choice=get_int_choice(": ",0,tmpfile_location_possibilities.size());
2162  if (choice==int(tmpfile_location_possibilities.size())) {
2163  std::string tmplocation;
2164  std::cout << "where should the root directory for temp files be?\n: " << std::endl;
2165  tmplocation = getAlphaNumeric();
2166  setValue("files","tempfilelocation",boost::filesystem::path(tmplocation));
2167  }
2168  else{
2169  setValue("files","tempfilelocation",standard_places_to_look[choice]);
2170  }
2171  }
2172  else{//found none of the standard places to look
2173  std::string tmplocation;
2174  std::cout << "Did not find any of the standard places to look for shared memory access :(\n\n";
2175  std::cout << "where should the root directory for temp files be? (% cancels, and chooses not to use ramdisk)\n: " << std::endl;
2176  tmplocation = getAlphaNumeric();
2177  found=tmplocation.find('%');
2178  if ( (int(found)==0) ) {
2179  setValue("files","customtmplocation",0);
2180  setValue("files","tempfilelocation",boost::filesystem::path("."));
2181  }
2182  else{
2183  setValue("files","tempfilelocation",boost::filesystem::path(tmplocation));
2184  }
2185  }
2186 
2187 
2188 
2189  }
2190  else {
2191  setValue("files","customtmplocation",0);
2192  setValue("files","tempfilelocation",boost::filesystem::path("."));
2193  }
2194 
2196  return;
2197 };
2198 
2199 
2200 //offers to use /dev/null to redirect step2 output
2202  std::stringstream menustream;
2203 
2204  setValue("system","stifle",get_int_choice("Stifle step2 output (to /dev/null) ?\n0) No.\n1) Yes.\n:",0,1));
2206  return;
2207 };
2208 
2209 
2210 
2211 
2213  setValue("files","writemeshtomc",get_int_choice("would you like to produce an mc file during step2, when using computer-generated mesh?",0,1));
2215  return;
2216 }
2217 
2218 
2220 {
2221 
2222  int choice = -10;
2223  std::stringstream menu;
2224  menu << "\n\n"
2225  << "How many points/solutions of desired type do you want?\n\n"
2226  << " (Max value 1e6)\n"
2227  << "\n"
2228  << "\n: ";
2229 
2230  choice = get_int_choice(menu.str(),1,1e6);
2231 
2232  setValue("mode","search_desirednumber",choice);
2233 
2234 
2236 
2237 }
2238 
2240 
2241  int choice = -10;
2242  std::stringstream menu;
2243  menu << "\n\n"
2244  << "What is the max number of point searches?\n\n"
2245  << "0 for default of 100K. Max value 1e8\n"
2246  << "\n"
2247  << "\n: ";
2248 
2249  choice = get_int_choice(menu.str(),0,1e8);
2250  switch (choice) {
2251  case 0:
2252  setValue("mode","search_iterations",int(1e5));
2253  break;
2254  default:
2255  setValue("mode","search_iterations",int(choice));
2256  break;
2257 
2258 
2259  }
2261 
2262 }
2263 
2264 
2266 {
2267 
2268  int choice = -10;
2269  std::stringstream menu;
2270  menu << "\n\n"
2271  << "Search for:\n"
2272  << "0) total number of posreal solutions\n"
2273  << "1) points with at least/most ___ solutions\n"
2274  << "\n"
2275  << "\n: ";
2276 
2277  choice = get_int_choice(menu.str(),0,1);
2278  setValue("mode","search_submode",choice);
2279 
2280 
2281  if (this->settings["mode"].find("search_numposrealthreshold_lower") == settings["mode"].end() ||
2282  this->settings["mode"].find("search_numposrealthreshold_upper") == settings["mode"].end())
2283  // search in cat name for setting of cat name
2284  { // if fail to find a setting of the name in the category.
2286  }
2287  else{
2288  setValue("mode","search_numposrealthreshold_upper",int(1));
2289  setValue("mode","search_numposrealthreshold_lower",int(1));
2290  }
2292 
2293 }
2294 
2295 
2297 
2298  int choice = -10;
2299  std::stringstream menu;
2300  menu << "\n\n"
2301  << "What is LOWER threshold number of posreal solutions for valid point? (max 1e6)\n"
2302  << "\n"
2303  << "\n: ";
2304 
2305  choice = get_int_choice(menu.str(),0,1e6);
2306  setValue("mode","search_numposrealthreshold_lower",choice);
2307  menu.clear();
2308  menu.str("");
2309 
2310  menu << "\n\n"
2311  << "What is UPPER threshold number of posreal solutions for valid point? (max 1e6)\n"
2312  << "-1 is no limit\n"
2313  << "\n: ";
2314 
2315  choice = get_int_choice(menu.str(),-1,1e6);
2316  setValue("mode","search_numposrealthreshold_upper",choice);
2317 
2318 
2319 
2321 }
2322 
2323 
2325  int choice = -10;
2326  std::stringstream menu;
2327  menu << "\n\n"
2328  << "Which primary mode?\n\n"
2329  << "0) Brute force, solve for all parameter points\n"
2330  << "1) Search for posreal solutions in a space\n"
2331  << "\n: ";
2332 
2333  choice = get_int_choice(menu.str(),0,1);
2334  switch (choice) {
2335  case 0:
2336  setValue("mode","main_mode",0);
2337  break;
2338  case 1:
2339  setValue("mode","main_mode",1);
2340  break;
2341  default:
2342 
2343  break;
2344  }
2345 
2346  if (this->settings["mode"]["main_mode"].intvalue==1) {
2347  setValue("SaveFiles","real_solutions",1);
2348 
2349  if (this->settings["mode"].find("search_iterations") == settings["mode"].end() )
2350  // search in cat name for setting of cat name
2351  { // if fail to find a setting of the name in the category.
2353  }
2354 
2355  if (this->settings["mode"].find("search_desirednumber") == settings["mode"].end() )
2356  // search in cat name for setting of cat name
2357  { // if fail to find a setting of the name in the category.
2359  }
2360 
2361  if (this->settings["mode"].find("search_submode") == settings["mode"].end() )
2362  // search in cat name for setting of cat name
2363  { // if fail to find a setting of the name in the category.
2365  }
2366 
2367 
2368 
2369 
2370  }
2371 
2372 
2374 }
2375 
2376 
2377 
2379  int choice = -10;
2380  std::stringstream menu;
2381  menu << "Which method for the Step 2 run?\n\n"
2382  << "0) Total Degree Step 2\n"
2383  << "1) Standard Step 2\n"
2384  << ": ";
2385  choice = get_int_choice(menu.str(),0,1);
2386  setValue("mode", "standardstep2", choice);
2388 }
2389 
2390 
2392  int choice = -10;
2393  std::stringstream menu;
2394  menu << "\n\n"
2395  << "What to do at startup for folders?\n\n"
2396  << "1) Use most recently used folder\n"
2397  << "2) Make new folder\n"
2398  << "3) Prompt if found previous folder\n"
2399  << "\n: ";
2400 
2401  choice = get_int_choice(menu.str(),1,3);
2402  setValue("files","previousdatamethod",choice);
2404  return;
2405 
2406 }
2407 
2409  int choice = -10;
2410  std::stringstream menu;
2411  menu << "\n\n"
2412  << "Which file to use for the start for step2?\n\n"
2413  << "1) nonsingular_solutions\n"
2414  << "2) finite_solutions\n"
2415  << "\n: ";
2416 
2417  choice = get_int_choice(menu.str(),1,2);
2418  switch (choice) {
2419  case 1:
2420  setValue("mode","startfilename",std::string("nonsingular_solutions"));
2421  break;
2422  case 2:
2423  setValue("mode","startfilename",std::string("finite_solutions"));
2424  break;
2425  default:
2426 
2427  break;
2428  }
2429 
2431  return;
2432 }
2433 
2434 
2435 
2437 
2438  int choice = -11;
2439  std::stringstream menu;
2440  menu << "\n\n"
2441  << "If you make a new folder with program running do you want\n"
2442  << "to automatically create new random values, or keep previous?\n"
2443  << "0) no (keep old)\n"
2444  << "1) yes (make new)\n"
2445  << "\n: ";
2446 
2447  choice = get_int_choice(menu.str(),0,1);
2448 
2449  setValue("files","newrandom_newfolder",choice);
2451  return;
2452 }
2453 
2454 
2455 
2456 
2457 
2458 
2459 
2461  int choice = get_int_choice("use a new random start point for each resolve? 0 no, 1 yes\n: ",0,1);
2462  setValue("PathFailure","newrandommethod",choice);
2464  return;
2465 }
2466 
2467 
2469  int choice = get_int_choice("Tighten tolerance by 10x each iteration? 0 no, 1 yes\n: ",0,1);
2470  setValue("PathFailure","tightentolerances",choice);
2472 }
2473 
2475  int choice = get_int_choice("How many iterations to perform per re-run?\n: ",1,99999);
2476  setValue("PathFailure","maxautoiterations",choice);
2478  return;
2479 }
void GetProgramLocationManual(std::string program_name, std::string category_name, std::string setting_name)
void GetTightenTolerancesPathFailure()
std::string WriteConfigFail()
static const char *const possible_savefiles[NUMPOSSIBLE_SAVEFILES]
void ChangeSetting(std::string category_name)
std::string replace_tilde_with_home(std::string workwithme)
std::string getAlphaNumeric()
bool CheckPrevSetFiles()
void DisplayCurrentSettings(std::string category_name)
std::string getAlphaNumeric_WithSpaces()
void FindProgram(std::string program_name, std::string category_name, std::string setting_name)
void RequiredSettingsSwitcharoo(int settingcase)
void default_main_values()
int check_for_existing_prefs_auto(boost::filesystem::path &load_filename, boost::filesystem::path pFilename)
void SetSearchIterations()
void set_path_failure_settings_from_steptwo()
void GetDataFolderMethod()
void SetSearchDesiredNumber()
bool setRequiredValues()
void default_path_failure_settings()
void GetWriteMCFileUserDef()
std::vector< boost::filesystem::path > FindFiles(boost::filesystem::path dir, std::string expression)
void default_basic_bertini_values_steptwo()
bool haveSetting(std::string category_name, std::string setting_name)
void tightentolerances()
int get_int_choice(std::string display_string, int min_value, int max_value)
void RemoveSetting(std::string category_name)
int SaveCategoryToXml(std::string catname, settingmap curr_settings, TiXmlElement *root)
boost::filesystem::path filename
boost::filesystem::path default_name()
static const char *const mandatory_savefiles[NUMMANDATORY_SAVEFILES]
void set_path_failure_settings()
std::string WriteConfigStepOne()
int ReadCategoryFromXml(std::string catname, TiXmlHandle hroot)
void AddSetting(std::string category_name)
categorymap settings
boost::filesystem::path make_settings_name(boost::filesystem::path basename)
void default_basic_bertini_values_pathfailure()
void default_basic_bertini_values_stepone()
void ManagePathFailureBertini()
std::map< std::string, setting > settingmap
std::string WriteConfigStepTwo()
void GetTemporaryFileLocation()
void SetSearchPosRealThresh()
void GetNewRandomAtNewFolder()
void setValue(std::string categoryName, std::string settingName, std::string settingValue)