9 boost::filesystem::path step1path(this->
location);
10 step1path /= (
"step1");
11 boost::filesystem::path nonsingular_solutions = step1path;
12 nonsingular_solutions /= (
"nonsingular_solutions");
14 if (boost::filesystem::exists(nonsingular_solutions)){
16 if (
get_int_choice(
"found completed previous step1 run.\nremove, or bail out?\n0) bail out\n1) remove and continue\n: ",0,1)==1){
17 boost::filesystem::remove_all( step1path );
22 std::cout <<
"returning to paramotopy main menu without running step one"
29 typedef std::vector< boost::filesystem::path > vec;
32 copy(boost::filesystem::directory_iterator(step1path), boost::filesystem::directory_iterator(), back_inserter(v));
33 for (vec::const_iterator it (v.begin()); it != v.end(); ++it)
35 boost::filesystem::remove( *it );
52 std::cerr <<
"failed to open paramotopy_input_file " << this->
inputfilename <<
"for reading" << std::endl;
56 while (getline(fin,tmpstr)) {
72 boost::filesystem::path filetoopen = dir;
73 filetoopen /=
"paramotopy_input_file";
76 fout.open(filetoopen.c_str());
77 if (!fout.is_open()) {
78 std::cerr <<
"writing paramotopy file " << filetoopen.string() <<
" failed." << std::endl;
85 filetoopen /=
"inputfilename";
86 fout.open(filetoopen.c_str());
87 if (!fout.is_open()) {
88 std::cerr <<
"writing inputfilename file " << filetoopen.string() <<
" failed." << std::endl;
99 boost::filesystem::path filetoopen = dir;
100 std::stringstream paramotopy_file_str;
103 for (
int ii=0; ii < this->
numfunct; ++ii) {
104 paramotopy_file_str << this->
Functions[ii] <<
"\n";
107 paramotopy_file_str << this->
VarGroups[ii] <<
"\n";
109 if (this->numconsts > 0) {
110 paramotopy_file_str << this->
Constants[0] <<
"\n";
112 for (
int ii=0; ii < this->
numconsts; ++ii) {
117 paramotopy_file_str <<
"1\n";
118 paramotopy_file_str <<
"failed_points" << iteration <<
"\n";
121 for (
int ii = 0; ii < this->
numparam; ++ii) {
129 filetoopen /=
"paramotopy_input_file";
130 fout.open(filetoopen.c_str());
131 fout << paramotopy_file_str.str();
151 prefix = prefix_path.root_name();
166 std::cout <<
"todo: setlocation whatnot\n";
176 std::stringstream inputfilestream;
177 inputfilestream.precision(15);
180 inputfilestream <<
"\nINPUT\n";
187 inputfilestream <<
"\nEND;\n";
189 return inputfilestream.str();
197 std::stringstream inputfilestream;
198 inputfilestream.precision(15);
200 inputfilestream <<
"\nINPUT\n\n";
202 inputfilestream <<
"variable";
204 inputfilestream <<
"_group ";
207 inputfilestream <<
" ";
209 for (
int ii = 0; ii < int(
VarGroups.size());++ii){
221 inputfilestream <<
"constant ";
222 for (
int ii = 0; ii <
numparam;++ii){
224 << (ii!= numparam-1?
",":
";\n");
226 inputfilestream <<
"constant ";
227 for (
int ii = 0; ii <
numparam;++ii){
229 << (ii!= numparam -1?
",":
";\n");
240 inputfilestream <<
"pathvariable t;\n"
243 inputfilestream <<
ParameterNames[ii] << (ii!= numparam-1?
",":
";\n");
258 inputfilestream <<
"END;\n";
262 inputfilestream <<
"constant ";
263 for (
int ii = 0; ii <
numparam;++ii){
265 << (ii!= numparam-1?
",":
";\n");
287 inputfilestream <<
"END;\n";
292 return inputfilestream.str();
301 bool finfound =
false;
302 std::string filename;
306 std::cout <<
"Enter the input file's name. (% cancels when applicable)\n: ";
309 size_t found=filename.find(
'%');
310 if (found!=std::string::npos) {
311 if ( (
int(found) == 0) && boost::filesystem::exists(this->
inputfilename)) {
312 std::cout <<
"canceling load.\n" << std::endl;
318 if (boost::filesystem::exists(filename)){
322 std::cout <<
"could not open a file of that name... try again.\n";
335 if (boost::filesystem::exists(suppliedfilename)){
339 std::cout <<
"Unable to find file of supplied name (" << suppliedfilename <<
").\n";
353 boost::filesystem::path randpointfilename =
base_dir;
354 randpointfilename /=
"randompoints_step1";
355 fout.open(randpointfilename.c_str());
357 if (!fout.is_open()) {
358 std::cerr <<
"failed to open " << randpointfilename <<
" to write random points\n";
361 for (
int ii = 0; ii <
numparam; ++ii){
372 std::string randpointfilename;
373 std::cout <<
"Enter the filename you want to save the random start points to : ";
379 fout.open(randpointfilename.c_str());
381 for (
int ii = 0; ii <
numparam; ++ii){
393 std::string randfilename;
399 while ( !fin.is_open() ) {
400 std::cout <<
"Enter the filename of the random points you"
401 <<
" want to load (% to cancel): ";
404 size_t found=randfilename.find(
'%');
405 if (found!=std::string::npos) {
406 if (
int(found) == 0) {
407 std::cout <<
"canceling load.\n" << std::endl;
415 fin.open(randfilename.c_str());
423 while(getline(fin,mytemp)){
424 std::stringstream myss;
427 double crandimaginary;
429 myss >> crandimaginary;
452 bool loadedrandom =
false;
455 boost::filesystem::path randomfilename =
base_dir;
457 randomfilename /=
"randompoints_step1";
460 if (boost::filesystem::exists(randomfilename)) {
464 fin.open(randomfilename.c_str());
466 if (!fin.is_open()) {
467 std::cerr <<
"failed to open " << randomfilename <<
" to read previous random values" << std::endl;
474 while(getline(fin,tmpstr)){
475 std::stringstream myss;
477 std::pair<double,double> crand;
479 myss >> crand.second;
488 std::cout <<
"loaded previous random values at " << randomfilename << std::endl;
491 std::cout <<
"tried to read the previous random values and failed.\n"
492 <<
"there were " <<
RandomValues.size() <<
" read values, and " <<
numparam <<
" necessary values"
504 MTRand drand(time(0));
506 std::stringstream menu;
508 menu <<
"1) Default range [0 to 1)\n"
509 <<
"2) User-specified range\n"
510 <<
"Enter in if you would like to use the standard \n"
511 <<
"default range for random floats or if you would \n"
512 <<
"like to specify the range : ";
515 if (randchoice == 1){
518 if (randchoice == 2){
520 int paramrandchoice = 1;
521 while (paramrandchoice != 0){
522 std::cout <<
"0 - Done specifying random values\n";
523 for (
int ii = 0; ii <
numparam;++ii){
527 paramrandchoice =
get_int_choice(
"Enter the parameter you want to rerandomize : ",0,numparam);
529 if (paramrandchoice !=0){
530 std::cout <<
"Enter a low range followed "
531 <<
"by a high range for the"
532 <<
" real and imaginary parts "
533 <<
"of the chosen parameter."
538 double cimaginarylow;
539 double cimaginaryhigh;
540 std::cout <<
"\n" <<
"Real Low : ";
542 std::cout <<
"Real High : ";
544 std::cout <<
"Imaginary Low : ";
546 std::cout <<
"Imaginary High : ";
548 double crandreal = drand();
549 double crandimaginary = drand();
550 crandreal*=(crealhigh-creallow);
551 crandimaginary*=(cimaginaryhigh-cimaginarylow);
553 crandimaginary+=cimaginarylow;
569 std::cout <<
"The random initial values for the parameters are : \n";
575 std::cout << std::endl;
584 boost::filesystem::path fileloc(this->
base_dir);
585 boost::filesystem::create_directories(fileloc);
588 boost::filesystem::path mcfile(this->
mcfname);
589 if (!boost::filesystem::exists(mcfile)) {
590 std::cerr <<
"mcfile specified by the input file does not exist..."
592 std::cerr <<
"mcfile: " << mcfile <<
"\n";
597 std::string thecommand =
"cp ";
598 thecommand.append(this->
mcfname);
599 thecommand.append(
" ");
600 thecommand.append(fileloc.string());
601 std::cout << thecommand << std::endl;
602 system(thecommand.c_str());
613 boost::filesystem::path filetoopen = dir;
614 filetoopen /=
"paramotopy_input_file";
617 fin.open(filetoopen.c_str());
618 if (!fin.is_open()) {
619 std::cerr <<
"failed to open paramotopy input file " << filetoopen << std::endl;
642 if (!fin.is_open()) {
643 std::cerr <<
"failed to open paramotopy input file " <<
inputfilename << std::endl;
668 std::stringstream ss;
673 std::string paramfilename;
675 getline(fin, paramfilename);
682 std::stringstream blabla;
684 blabla <<
"/" << paramfilename;
710 while (getline(fin, tmpstr)) {
727 std::stringstream ss;
740 for (
int ii = 0; ii <
numparam; ++ii){
752 MTRand drand(time(0));
753 for (
int ii = 0; ii <
numparam;++ii){
754 double creal = double(drand());
755 double cimaginary = double(drand());
756 RandomValues.push_back(std::pair<double,double>(creal,cimaginary));
765 std::pair< double, double > > > RandomRanges){
769 MTRand drand(time(0));
770 for (
int ii = 0; ii < int(RandomRanges.size()); ++ii){
771 double crandreal = drand();
772 double crandimaginary = drand();
773 crandreal*=(RandomRanges[ii].first.second
774 - RandomRanges[ii].first.first);
775 crandreal+=RandomRanges[ii].first.first;
776 crandimaginary*=(RandomRanges[ii].second.second
777 -RandomRanges[ii].second.first);
778 crandimaginary+=RandomRanges[ii].second.first;
779 RandomValues.push_back(std::pair<double,double>(crandreal,
789 std::vector<std::pair<double, double> > NewRandomValues;
791 MTRand drand(seed_value);
798 for (
int ii = 0; ii <
numparam;++ii){
799 NewRandomValues.push_back(std::pair<double,double>(
double(drand()),
double(drand()) ));
803 return NewRandomValues;
814 std::stringstream myss;
816 boost::filesystem::path randfilename = this->
location;
817 randfilename /=
"randstart";
818 fin.open(randfilename.c_str());
820 if (!fin.is_open()) {
821 std::cout <<
"failed to open randfilename: " << randfilename <<
"\n";
827 while(getline(fin,mytemp)){
828 std::stringstream myss;
831 double crandimaginary;
833 myss >> crandimaginary;
838 std::cout << std::endl;
849 for (
int ii = 0; ii <
numfunct; ++ii){
902 while ( comma_found != std::string::npos ) {
904 comma_found =
VarGroups[ii].find(
",",comma_found+1,1);
914 inputfilestream <<
"\n";
915 for (
int ii = 0; ii <
numfunct;++ii){
916 inputfilestream <<
"f" << ii+1
929 if (paramotopy_settings.
settings[
"step1bertini"][
"USERHOMOTOPY"].value() ==
"1"){
934 fout << (ii != numvargroup - 1 ?
", " :
"");
942 fout <<
"variable_group ";
969 inputfilestream <<
"function ";
970 for (
int ii = 1; ii <=
numfunct;++ii){
971 inputfilestream <<
"f" << ii;
973 inputfilestream <<
", ";
976 inputfilestream <<
";\n";
985 for (
int ii = 0; ii < int(this->
RandomValues.size());++ii){
1014 inputfilestream <<
"rand"
1022 inputfilestream <<
"here"
1025 << CurrentValues[ii].first <<
" + " << CurrentValues[ii].second
1041 for (
int ii = 0; ii < int(this->
ConstantNames.size());++ii){
1055 for (
int ii = 0; ii < int(this->
ConstantNames.size());++ii){
1077 while(getline(fin,temp)){
1078 std::vector< std::pair<double, double> > CValue;
1079 std::stringstream ss;
1081 for (
int ii = 0; ii <
numparam;++ii){
1086 CValue.push_back(std::pair<double, double>(creal,cimaginary));
1090 Values.push_back(CValue);
1092 std::cout <<
"line count = " << lcount <<
"\n\n";
1103 std::cout <<
"attempting to set bounds in a non-computer-generated" << std::endl;
1110 for (
int ii = 0; ii < int(
Parameters.size());++ii){
1112 std::stringstream ss;
1126 this->
BoundsLeft.push_back(std::pair< double, double> (lepr, lepi));
1127 this->
BoundsRight.push_back(std::pair< double, double> (repr, repi));
1142 for (
int ii = 0; ii < int(
Parameters.size());++ii){
1146 std::stringstream ss;
1157 std::vector< std::pair<double,double> > currentmesh;
1165 double stepr = (repr - lepr)/(meshpoints-1);
1166 double stepi = (repi - lepi)/(meshpoints+1);
1167 double currentr = lepr;
1168 double currenti = lepi;
1169 for (
int jj = 0; jj < meshpoints;++jj){
1170 currentmesh.push_back(std::pair<double,double>(currentr,currenti));
1174 this->
Values.push_back(currentmesh);
1188 for (
int ii = 0; ii <
numparam;++ii){
1189 std::stringstream ss;
1191 std::string paramname;
1203 std::cout <<
"nfunc " <<
numfunct << std::endl;
1204 for (
int ii=0; ii<
numfunct; ++ii) {
1205 std::cout <<
Functions[ii] << std::endl;
1208 std::cout <<
"nvargrp " <<
numvargroup << std::endl;
1210 std::cout <<
VarGroups[ii] << std::endl;
1213 std::cout <<
"nparam " <<
numparam << std::endl;
1214 for (
int ii=0; ii<
numparam; ++ii) {
1217 for (
int ii=0; ii<
numparam; ++ii) {
1222 std::cout <<
"nconst " <<
numconsts << std::endl;
1232 std::cout <<
"base_dir " <<
base_dir <<
" "
1235 std::cout <<
"base_dir " <<
base_dir <<
" "
1236 <<
"inputfilename " << inputfilename << std::endl;
1240 std::cout <<
"userdefined, with mcfname: " <<
mcfname << std::endl;
1243 std::cout <<
"computer-generated mesh." << std::endl;
1247 std::cout <<
"custom lines: " << this->
CustomLines << std::endl;
1288 bool finished =
false;
1290 boost::filesystem::path finishedfile = this->
base_dir;
1291 finishedfile /=
"step2finished";
1294 if (boost::filesystem::exists(finishedfile) ){
1337 time_t wheninitiated, whenupdated;
1340 std::cout <<
"the following are your options for data folders:\n\n";
1341 std::cout <<
" name date modified\n";
1342 for (
int ii = 0; ii<int(found_runs.size()); ++ii) {
1343 std::string tmpdir = found_runs[ii].string();
1344 tmpdir.append(
"/info.xml");
1346 get_run_xml(tmpdir,tmprun,wheninitiated,whenupdated);
1348 std::cout << ii <<
": " << found_runs[ii].string();
1349 for (
int jj=0; jj<(20 - int(found_runs[ii].
string().length())); ++jj) {
1352 std::cout << ctime(&whenupdated);
1355 std::cout << found_runs.size() <<
": " <<
"make new folder\n" << std::endl;
1357 int choice =
get_int_choice(
"which folder to use?\n\n: ",0,found_runs.size());
1359 std::cout << choice <<
" " << found_runs.size() <<
"\n";
1361 if (choice<
int(found_runs.size())) {
1363 base_dir = found_runs[choice].string();
1364 std::cout <<
"loading old directory " <<
base_dir <<
"\n";
1366 boost::filesystem::path fname =
base_dir;
1367 fname /=
"info.xml";
1372 std::cout <<
"making new directory\n";
1388 int max_run_number = -101;
1390 time_t wheninitiated, whenupdated;
1393 for (
int ii=0; ii<int(found_runs.size()); ++ii) {
1394 std::string tmpdir = found_runs[ii].string();
1395 tmpdir.append(
"/info.xml");
1396 get_run_xml(tmpdir,run,wheninitiated,whenupdated);
1397 if (run > max_run_number){
1398 max_run_number = run;
1408 std::stringstream ss;
1412 boost::filesystem::create_directories(
base_dir);
1424 time_t most_recent = -1;
1425 boost::filesystem::path tmpdir;
1426 time_t wheninitiated, whenupdated;
1430 std::cout <<
"\n name date modified\n\n";
1432 for (
int ii=0; ii<int(found_runs.size()); ++ii) {
1433 tmpdir = found_runs[ii];
1434 tmpdir /=
"info.xml";
1435 get_run_xml(tmpdir,tmprun,wheninitiated,whenupdated);
1437 std::cout << found_runs[ii].string();
1438 for (
int jj=0; jj<(20 - int(found_runs[ii].
string().length())); ++jj) {
1441 std::cout << ctime ( &whenupdated );
1442 if (whenupdated > most_recent){
1443 most_recent = whenupdated;
1449 std::cout << std::endl;
1450 tmpdir = found_runs[runindex];
1454 tmpdir /=
"info.xml";
1462 std::cout <<
"Output directory is now: " <<
base_dir << std::endl;
1466 if (found_runs.size()==0) {
1467 std::cout <<
"found no previous data, starting new folder\n";
1485 if (found_runs.size()==0) {
1486 std::cout <<
"found no previous data, starting new folder\n";
1490 switch (preferred_behaviour) {
1492 std::cout <<
"setting base_dir most_recent\n";
1498 std::cout <<
"Setting base dir new\n";
1504 std::cout <<
"setting basedir manually\n";
1513 std::cout <<
"run folder set to " <<
base_dir << std::endl;
1527 TiXmlDocument* doc =
new TiXmlDocument;
1528 TiXmlDeclaration* decl =
new TiXmlDeclaration(
"1.0",
"",
"" );
1530 doc->LinkEndChild( decl );
1532 TiXmlElement * root =
new TiXmlElement(
"run_info");
1536 std::stringstream ss;
1539 TiXmlElement * value_name1 =
new TiXmlElement(
"run_number" );
1541 txt =
new TiXmlText( ss.str().c_str() );
1544 value_name1->LinkEndChild(txt);
1546 TiXmlElement * value_name2 =
new TiXmlElement(
"initiated" );
1548 txt =
new TiXmlText( ss.str().c_str() );
1551 value_name2->LinkEndChild(txt);
1553 TiXmlElement * value_name3 =
new TiXmlElement(
"updated" );
1554 time_t currtime = time(NULL);
1556 txt =
new TiXmlText( ss.str().c_str() );
1559 value_name3->LinkEndChild(txt);
1561 root->LinkEndChild(value_name1);
1562 root->LinkEndChild(value_name2);
1563 root->LinkEndChild(value_name3);
1566 doc->LinkEndChild( root );
1568 boost::filesystem::create_directories(
base_dir);
1570 boost::filesystem::path filename =
base_dir;
1571 filename /=
"info.xml";
1573 if(doc->SaveFile(filename.c_str())){
1578 std::cout <<
"run info *failed* to save to " << filename.string() <<
"!\n";
1588 time_t tmp_initiated=-2, tmp_updated=-1;
1590 get_run_xml(filename,tmp_run,tmp_initiated,tmp_updated);
1600 void runinfo::get_run_xml(boost::filesystem::path filename,
int & run, time_t & wheninitiated, time_t & whenupdated){
1602 TiXmlDocument* doc =
new TiXmlDocument(filename.string().c_str());
1604 bool doc_loaded = doc->LoadFile();
1609 TiXmlHandle hDoc(doc);
1610 TiXmlElement* pElem;
1611 TiXmlHandle hRoot(0);
1613 pElem=hDoc.FirstChildElement().Element();
1617 std::cerr <<
"bad xml file for this run.\n";
1621 std::stringstream ss;
1623 std::string main_name =pElem->Value();
1624 hRoot=TiXmlHandle(pElem);
1626 TiXmlElement* qElem = hRoot.FirstChild(
"run_number").Element();
1627 const char *numberText=qElem->GetText();
1633 qElem = hRoot.FirstChild(
"initiated").Element();
1634 const char *initiatedText=qElem->GetText();
1635 ss << initiatedText;
1636 ss >> wheninitiated;
1641 qElem = hRoot.FirstChild(
"updated").Element();
1642 const char *updatedText=qElem->GetText();
void MakeDeclareFunctions(std::stringstream &inputstringstream)
void ReadSizes(std::ifstream &fin)
void SetBaseDirManual(std::vector< boost::filesystem::path > found_runs)
void GetOriginalParamotopy()
std::vector< std::pair< double, double > > RandomValues
void ReadConstantStrings(std::ifstream &fin)
std::string getAlphaNumeric_WithSpaces()
std::vector< int > NumMeshPoints
void MakeFunctions(std::stringstream &inputstringstream)
void load(boost::filesystem::path filename)
boost::filesystem::path base_dir
std::string paramotopy_file
void MakeCustomLines(std::stringstream &inputfilestream)
boost::filesystem::path fundamental_dir
void WriteOriginalParamotopy(boost::filesystem::path dir)
void ReadVarGroups(std::ifstream &fin)
void MakeDeclareConstants(std::stringstream &fout)
std::vector< boost::filesystem::path > FindDirectories(boost::filesystem::path, std::string expression)
void ReadParameters(std::ifstream &fin)
std::string WriteInputStepTwo(std::vector< std::pair< double, double > > tmprandomvalues, bool standardstep2)
void ParseDataGuts(std::ifstream &fin)
void make_base_dir_name()
void ReadConstants(std::ifstream &fin)
void ReadCustomLines(std::ifstream &fin)
std::string WriteInputStepOne(ProgSettings paramotopy_settings)
void MakeParameterNames()
int get_int_choice(std::string display_string, int min_value, int max_value)
std::vector< std::string > Parameters
void SetBaseDirNew(std::vector< boost::filesystem::path > found_runs)
void MakeConstants(std::stringstream &fout)
void get_run_xml(boost::filesystem::path filename, int &run, time_t &wheninitiated, time_t &whenupdated)
std::vector< std::string > ParameterNames
std::vector< std::string > VarGroups
boost::filesystem::path inputfilename
boost::filesystem::path prefix
boost::filesystem::path location
void AutoScanData(const int preferred_behaviour)
void SetBaseDirMostRecent(std::vector< boost::filesystem::path > found_runs)
A class that stores the general program settings of Paramotopy.
std::vector< std::string > Functions
void MakeVariableGroups(std::stringstream &fout, ProgSettings paramotopy_settings)
void CopyUserDefinedFile()
std::vector< std::string > ConstantNames
void MakeConstantsStep2(std::vector< std::pair< double, double > > CurrentValues, std::stringstream &inputfilestream, bool standardstep2)
std::vector< std::vector< std::pair< double, double > > > Values
void ReadFunctions(std::ifstream &fin)
std::vector< std::pair< double, double > > BoundsLeft
void WriteModifiedParamotopy(boost::filesystem::path dir, int iteration)
std::vector< std::string > Constants
std::vector< std::pair< double, double > > BoundsRight