00001
00002
00003
00004
00005
00006
00007 bool getUserHomeDir(std::string & userHomeDir)
00008 {
00009 userHomeDir=std::string("");
00010
00011
00012 struct passwd * res= getpwuid( getuid() );
00013
00014 if (res)
00015 {
00016 userHomeDir=std::string(res->pw_dir);
00017 std::cerr << "userHomeDir = " << userHomeDir;
00018 return true;
00019
00020 }
00021 return false;
00022 }
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 using namespace nCenterFocus;
00039 using nCenterFocus::CenterfocusParams;
00040
00041
00042
00043 template <class tParams>
00044 string composeOutputFileName(string prefix,tParams* params)
00045 {
00046
00047 stringstream outputFile_stream;
00048 outputFile_stream << prefix;
00049 outputFile_stream << ".tag_" << params->getExperimentTagNoWS();
00050 outputFile_stream << ".fieldchar_" << params->getFieldCharacteristic();
00051 outputFile_stream << ".deg_" << params->getPolynomialDegree();
00052 outputFile_stream << ".eps_" << params->getEpsPrecision();
00053 outputFile_stream << ".minVanish_" << params->requiredVanishedFocalValuesNum();
00054 outputFile_stream << ".jacobianRank_" << params->getRequiredFullJacobianMinRank();
00055 outputFile_stream << ".subJacobianRank_" << params->getRequiredSubJacobianMinRank();
00056 if ( params->hasVariableCoefficients() )
00057 outputFile_stream << ".seed_" << (long)(*(params->getRandomSeedPtr()));
00058 outputFile_stream << ".m2" ;
00059
00060 string outputFileName ,tmpstr;
00061
00062 while (outputFile_stream >> tmpstr )
00063 {
00064 outputFileName=outputFileName+tmpstr;
00065 }
00066
00067 return outputFileName;
00068 }
00069
00070
00071
00072 template <class TPolynomXY, class TRing >
00073 const string CenterfocusParams< TPolynomXY, TRing >::characteristic_ConstString_m("characteristic");
00074
00075 template <class TPolynomXY, class TRing >
00076 const string CenterfocusParams< TPolynomXY, TRing >::polynomialDegree_ConstString_m("polynomialDegree");
00077
00078 template <class TPolynomXY, class TRing >
00079 const string CenterfocusParams< TPolynomXY, TRing >::reqVanisnedValues_ConstString_m("reqiredVanishedValues");
00080
00081 template <class TPolynomXY, class TRing >
00082 const string CenterfocusParams< TPolynomXY, TRing >::maxFocalValues_ConstString_m("maxFocalValues");
00083
00084 template <class TPolynomXY, class TRing >
00085 const string CenterfocusParams< TPolynomXY, TRing >::randomTrialsNum_ConstString_m("randomTrialsNum");
00086
00087
00088 template <class TPolynomXY, class TRing >
00089 const string CenterfocusParams< TPolynomXY, TRing >::requestedLiftPointNum_ConstString_m("numLiftPoints");
00090
00091 template <class TPolynomXY, class TRing >
00092 const string CenterfocusParams< TPolynomXY, TRing >::maxLift_ConstString_m("maxLift");
00093
00094 template <class TPolynomXY, class TRing >
00095 const string CenterfocusParams< TPolynomXY, TRing >::liftTrials_ConstString_m("liftTrials");
00096
00097
00098 template <class TPolynomXY, class TRing >
00099 const string CenterfocusParams< TPolynomXY, TRing >::exhaustiveMaxLift_ConstString_m("exhaustiveMaxLift");
00100
00101 template <class TPolynomXY, class TRing >
00102 const string CenterfocusParams< TPolynomXY, TRing >::exhaustiveLiftTrials_ConstString_m("exhaustiveLiftTrials");
00103
00104
00105 template <class TPolynomXY, class TRing >
00106 const string CenterfocusParams< TPolynomXY, TRing >::randomSeed_ConstString_m("randomSeed");
00107
00108 template <class TPolynomXY, class TRing >
00109 const string CenterfocusParams< TPolynomXY, TRing >::randomSeedFromSysTime_ConstString_m("randomSeedFromSysTime");
00110
00111 template <class TPolynomXY, class TRing >
00112 const string CenterfocusParams< TPolynomXY, TRing >::epsPrecision_ConstString_m("epsPrecision");
00113
00114 template <class TPolynomXY, class TRing >
00115 const string CenterfocusParams< TPolynomXY, TRing >::minJacobianRank_ConstString_m("minJacobianRank");
00116 template <class TPolynomXY, class TRing >
00117 const string CenterfocusParams< TPolynomXY, TRing >::minJacobianSubMatrixRank_ConstString_m("minJacobianSubMatrixRank");
00118
00119 template <class TPolynomXY, class TRing >
00120 const string CenterfocusParams< TPolynomXY, TRing >::randomCounterStartValue_ConstString_m("randomCounterStartValue");
00121
00122
00123 template <class TPolynomXY, class TRing >
00124 const string CenterfocusParams< TPolynomXY, TRing >::useFormula1_ConstString_m("useFormula1");
00125 template <class TPolynomXY, class TRing >
00126 const string CenterfocusParams< TPolynomXY, TRing >::useFormula2_ConstString_m("useFormula2");
00127
00128 template <class TPolynomXY, class TRing >
00129 const string CenterfocusParams< TPolynomXY, TRing >::useFormula23_ConstString_m("useFormula23");
00130
00131 template <class TPolynomXY, class TRing >
00132 const string CenterfocusParams< TPolynomXY, TRing >::appendResults_ConstString_m("appendResults");
00133
00134
00135 template <class TPolynomXY, class TRing >
00136 const string CenterfocusParams< TPolynomXY, TRing >::experimentTag_ConstString_m("experimentTag");
00137
00138
00139 template <class TPolynomXY, class TRing >
00140 const string CenterfocusParams< TPolynomXY, TRing >::HamiltonianComponentSwitch_ConstString_m("HamiltonianComponentSwitch");
00141
00142 template <class TPolynomXY, class TRing >
00143 const string CenterfocusParams< TPolynomXY, TRing >::nonSmoothPointPassFilter_ConstString_m("nonSmoothPointPassFilter");
00144
00145 template <class TPolynomXY, class TRing >
00146 const string CenterfocusParams< TPolynomXY, TRing >::experimentTagNoWhiteSpaces_ConstString_m("experimentTagNoWhiteSpaces");
00147
00148
00149 template <class TPolynomXY, class TRing >
00150 const string CenterfocusParams< TPolynomXY, TRing >::true_ConstString_m("true");
00151
00152 template <class TPolynomXY, class TRing >
00153 const string CenterfocusParams< TPolynomXY, TRing >::false_ConstString_m("false");
00154
00155 template <class TPolynomXY, class TRing >
00156 const string CenterfocusParams< TPolynomXY, TRing >::showProgress_ConstString_m("showProgress");
00157
00158 template <class TPolynomXY, class TRing >
00159 const string CenterfocusParams< TPolynomXY, TRing >::minComponentCodim_ConstString_m("minComponentCodim");
00160
00161 template <class TPolynomXY, class TRing >
00162 const string CenterfocusParams< TPolynomXY, TRing >::logExtendedLiftStatistic_ConstString_m("logExtendedLiftStatistic");
00163
00164 template <class TPolynomXY, class TRing >
00165 const string CenterfocusParams< TPolynomXY, TRing >::pureSmothnessTest_ConstString_m("pureSmoothnessTest");
00166
00167
00168
00169
00170 template <class TPolynomXY, class TRing >
00171 const string CenterfocusParams< TPolynomXY, TRing >::checkpointInterval_ConstString_m("checkpointInterval");
00172
00173
00174 template <class TPolynomXY, class TRing >
00175 const string CenterfocusParams< TPolynomXY, TRing >::pointFilter_ConstString_m("pointFilter");
00176
00177 template <class TPolynomXY, class TRing >
00178 const string CenterfocusParams< TPolynomXY, TRing >::pointFilterStrategy_ConstString_m("pointFilterStrategy");
00179
00180
00181
00182
00185
00191 template <class TPolynomXY, class TRing >
00192 CenterfocusParams< TPolynomXY, TRing >::CenterfocusParams(const int argc, const char * const argv[])
00193 {
00194
00195 init();
00196
00197
00198 string inputFileName;
00199 if (argc<2)
00200 {
00201 std::cerr << "Please specify an input file or source!"<< endl;
00202
00203 exit(0);
00204 }
00205 else
00206 {
00207 inputFileName = string((char*)(argv)[1]);
00208 }
00209
00210
00211 if (strcmp(argv[1],"+")==0)
00212 {
00213 std::cerr << "+" << std::endl;
00214 assert(argc==4);
00215 loadParamListFromString(argv[3]);
00216 }
00217 else
00218 {
00219 loadParamList(inputFileName);
00220 }
00221
00222
00223
00224
00226
00228 assert( areWellDefined() );
00229
00230
00231
00232 initNonNegativeIntParameter( randomTrialsNum_ConstString_m, azZufallszahlen_m, 104);
00233
00234 setupOutputFile(argc,argv);
00235
00236 };
00237
00245 template <class TPolynomXY, class TRing >
00246 void CenterfocusParams< TPolynomXY, TRing >::setupOutputFile(const int argc, const char * const argv[])
00247 {
00248 bWriteToCout_m=false;
00251 if (argc >= 3 && !strcmp(argv[2], "-"))
00252 {
00254 cerr <<"copyfmt" << endl;
00255 os_m.copyfmt( std::cout);
00256 os_m.clear( std::cout.rdstate() );
00257 os_m.basic_ios<char>::rdbuf( std::cout.rdbuf() );
00258 bWriteToCout_m=true;
00259 }
00260 else
00261 {
00262
00263 ifstream inp;
00264
00265 if (argc < 3)
00266 outputFileName_m = composeOutputFileName("output", this);
00267 else
00268 outputFileName_m = composeOutputFileName((char*)(argv)[2],this);
00269
00270
00271
00272
00273 if (bLocking_m)
00274 {
00275 std::string str_UserHomeDir;
00276 if ( !getUserHomeDir(str_UserHomeDir) )
00277 {
00278 std::cerr << "creating lockfile: it was not possible to determine user home directory" << std::endl;
00279 exit(0);
00280 }
00281 std::string str_LockFileName= str_UserHomeDir+std::string("/.centerfocus.lck");
00282
00283
00284
00285
00286 int fd = open( str_LockFileName.c_str(), O_RDWR | O_CREAT,S_IWUSR );
00287
00288 struct flock lock;
00289
00290 lock.l_type = F_WRLCK;
00291 lock.l_whence = SEEK_SET;
00292 lock.l_start = 0;
00293 lock.l_len=0;
00294
00295
00296 int lfd=-1;
00297 for (int i=0; i<10; i++)
00298 {
00299 lfd=fcntl (fd, F_SETLK, &lock);
00300
00301 if (lfd<0 )
00302 {
00303 assert(errno!=29);
00304
00305
00306 usleep(rand()*1000 % 1000000);
00307 }
00308 else
00309 {
00310 assert(errno!=29);
00311 std::cerr << "lfd= " << lfd << std::endl;
00312 std::cerr << "errno= " << errno << std::endl;
00313 break;
00314 }
00315 }
00316
00317
00318
00319
00320
00321 if (lfd<0 && (errno==EEXIST || errno==EAGAIN) )
00322 {
00323
00324
00325 cout<<"io is currently locked; try again later";
00326 exit(0);
00327 }
00328 else if (lfd < 0)
00329 {
00330
00331
00332 perror("locking failed for the following reason");
00333 exit(0);
00334 }
00335 else
00336 {
00337 inp.open(outputFileName_m.c_str(), ifstream::in);
00338
00339 if (inp && !bMultipleExperimentsInAFile_m)
00340 {
00341 std::cerr << "error: output file '" << outputFileName_m << "' already exists, appending is disabled! " << std::endl;
00342 exit(0);
00343 }
00344 inp.close();
00345 os_m.open(outputFileName_m.c_str(), ios::app);
00346 os_m << " ";
00347 os_m.flush();
00348 assert (!os_m.bad() );
00349 lock.l_type = F_UNLCK;
00350 int lfd2=fcntl (fd, F_SETLK, &lock);
00351 if (lfd2<0)
00352 {
00353 cout<<"unlocking failed " << std::endl;
00354 perror("unlocking failed for the following reason");
00355 }
00356 assert(lfd2>=0);
00357
00358 }
00359 assert(fd>0);
00360 int cfd=close(fd);
00361 assert(cfd==0);
00362
00363 }
00364 else
00365 {
00366 inp.open(outputFileName_m.c_str(), ifstream::in);
00367
00368 if (inp && !bMultipleExperimentsInAFile_m)
00369 {
00370 std::cerr << "error: result file '" << outputFileName_m << "' already exists, appending is disabled! " << std::endl;
00371 exit(0);
00372 }
00373 inp.close();
00374 os_m.open(outputFileName_m.c_str(), ios::app);
00375 }
00376 }
00377 }
00378
00379
00380 template <class TPolynomXY, class TRing >
00381 void CenterfocusParams< TPolynomXY, TRing >::init()
00382 {
00383 bWriteToCout_m=false;
00384
00385 bLocking_m=false;
00386 #ifdef CFLOCKING
00387 bLocking_m=true;
00388 #endif
00389 firstPQ_m = true;
00390 braceLevel_m = 0;
00391
00392 positionInLValue_m = false;
00393 parameterNameExpected_m = true;
00394
00395
00396
00397 checkpointInterval_m=10800;
00398
00399 bPureSmoothnessTest_m = false;
00400 bShowProgress_m = false;
00401 randomCounterStartValue_m = 0;
00402 bMultipleExperimentsInAFile_m = false;
00403
00404 benutzeFormel_1_m = false;
00405 benutzeFormel_2_m = false;
00406 benutzeFormel_23_m = false;
00407
00408 HamiltonianComponentSwitch_m = 0;
00409 bNonSmoothPointPassFilter_m=false;
00410
00411 gradderpolynome_m = 0;
00412 bReqVanishedFocalValues_m=1;
00413 reqSubJacobianMinRank_m=0;
00414 reqFullJacobianMinRank_m=0;
00415
00416 minComponentCodim_m = 0;
00417
00418
00419 maxLift_m=0;
00420 liftTrials_m=0;
00421
00422 exhaustiveMaxLift_m = maxLift_m;
00423 exhaustiveLiftTrials_m = liftTrials_m;
00424
00425 pointFilter=NULL;
00426
00427 requestedLiftPointNum_m=0;
00428
00429 azZufallszahlen_m = 0;
00430 epsPrecision_m =0;
00431 randomSeedFromSysTime_m = false;
00432
00433 randomSeed_m = 548;
00434
00435
00436 infEps_minusP_polynom_m = NULL;
00437 infEps_Q_polynom_m = NULL;
00438
00439 ringEps_m = NULL;
00440 bAllConstCoefficientsAreVariables_m=false;
00441
00442 containsMonomsWithAllCoefficientsCheck_m = 0;
00443 containsMonomsWithRandomCoefficients_m = 0;
00444 inputFromStd_m=false;
00445
00446 experimentTag_m = "";
00447 progressStepWidth_m= 100000;
00448 lockFileName_m="";
00449
00450 bLogExtendedLiftStatistic_m = false;
00451 }
00452
00453
00460 template <class TPolynomXY, class TRing >
00461 bool CenterfocusParams< TPolynomXY, TRing >::isCoefficientVariable(int x_exp, int y_exp, P_or_QPolynom p_or_q ) const
00462 {
00463 CoeffListEntry entry( p_or_q, x_exp, y_exp );
00464
00465 if (monomsWithAllCoefficients_m.containsEntry(p_or_q , x_exp,y_exp ) )
00466 return true;
00467
00468 if (monomsWithRandomCoefficients_m.containsEntry(p_or_q , x_exp,y_exp ) )
00469 return true;
00470
00471 return false;
00472 }
00473
00474
00475 template <class TPolynomXY, class TRing >
00476 bool CenterfocusParams< TPolynomXY, TRing >::isCoefficientVariable(const CoeffListEntry & coeffEntry) const
00477 {
00478 if (monomsWithAllCoefficients_m.containsEntry( coeffEntry ) )
00479 return true;
00480
00481 if (monomsWithRandomCoefficients_m.containsEntry( coeffEntry ) )
00482 return true;
00483 return false;
00484 }
00485
00486 template <class TPolynomXY, class TRing >
00487 bool CenterfocusParams< TPolynomXY, TRing >::isRandomVariable(const CoeffListEntry & coeffEntry) const
00488 {
00489 if (monomsWithRandomCoefficients_m.containsEntry( coeffEntry ) )
00490 return true;
00491 return false;
00492 }
00493
00495 template <class TPolynomXY, class TRing >
00496 void CenterfocusParams< TPolynomXY, TRing >::readMonomGroup(TRing * ring1, TPolynomXY &pol, string &monomGroup, int momomGroupDegree, P_or_QPolynom p_or_q)
00497 {
00498 stringstream ssMonomGroup(monomGroup);
00499 #ifdef DEBUG
00500 cerr << "\t MonomGroup String: \n\n"<< monomGroup << endl;
00501 #endif
00502 extractChar('{',ssMonomGroup);
00503
00504 int y_exp=0;
00505
00506 for ( int x_exp=momomGroupDegree ; x_exp>=0; x_exp--, y_exp++ )
00507 {
00508 #ifdef DEBUG
00509 cerr << "\t readMonomGroup: x_exp: "<< x_exp << endl;
00510 #endif
00511
00512
00513 #ifdef DEBUG
00514 cerr << "\t readMonomGroup: extractNextData \n\n"<< endl;
00515 cerr << "\t ssMonomGroup: ssMonomGroup \n\n"<< ssMonomGroup.str() << endl;
00516 #endif
00517 string nextElement=extractNextData(ssMonomGroup);
00518 #ifdef DEBUG
00519 cerr << "\t readMonomGroup: extractNextData finished! \n\n"<< endl;
00520 #endif
00521
00522 if ( ssMonomGroup.peek()==',' )
00523 extractChar(',',ssMonomGroup);
00524
00525 if ( isAllMarker(nextElement) )
00526 {
00527 #ifdef DEBUG
00528 cerr << "\t readMonomGroup: isAllMarker"<< endl;
00529 #endif
00530 CoeffListEntry * entry= new CoeffListEntry(p_or_q, y_exp, momomGroupDegree);
00531 monomsWithAllCoefficients_m.append(entry);
00532 }
00533 else if ( isRandomMarker(nextElement) )
00534 {
00535 #ifdef DEBUG
00536 cerr << "\t readMonomGroup: isRandomMarker"<< endl;
00537 #endif
00538 CoeffListEntry * entry=new CoeffListEntry(p_or_q, y_exp, momomGroupDegree);
00539 monomsWithRandomCoefficients_m.append(entry);
00540 }
00541
00542 else
00543 {
00544
00545 #ifdef DEBUG
00546 cerr << "\t readMonomGroup: parseNumber"<< endl;
00547 #endif
00548 typename TRing::ElementType coeff = parseNumber( ring1, nextElement.c_str(), this->epsPrecision_m);
00549 if (p_or_q==PCoefficient)
00550 {
00551 pol.setCoeff( x_exp, y_exp, ring1->addInv(coeff));
00552 }
00553 else
00554 pol.setCoeff( x_exp, y_exp, coeff );
00555 }
00556 }
00557 extractChar('}',ssMonomGroup);
00558 return;
00559 }
00560
00561
00562
00563
00564 template <class TPolynomXY, class TRing >
00567 void CenterfocusParams< TPolynomXY, TRing >::updatePolynom(TRing * ring1, TPolynomXY &pol, stringstream &polynomStream, P_or_QPolynom p_or_q)
00568 {
00569 #ifdef DEBUG
00570 std::cerr << "updatePolynom" << std::endl;
00571 #endif
00572
00573 polynomStream >> ws;
00574 extractChar('{',polynomStream);
00575
00576 int lastMonomDegree=-1;
00577 int currMonomDegree=0;
00578
00579
00580 int MaxMonomDegree=getMaxMonomDegree( polynomStream.str() );
00581 pol.setDegree(MaxMonomDegree);
00582
00583
00584 while (!polynomStream.eof() && polynomStream.peek()=='{')
00585 {
00586 #ifdef DEBUG
00587 std::cerr << "while (polynomStream.peek()=='{')"<< std::endl;
00588 #endif
00589 string monomGroup=extractNextBracedData(polynomStream);
00590 #ifdef DEBUG
00591 std::cerr << "monomgroup: '" << monomGroup <<"'" <<std::endl;
00592 #endif
00593 polynomStream>>ws;
00594 if ( polynomStream.peek()!='}' )
00595 extractChar(',',polynomStream);
00596 polynomStream>>ws;
00597
00598 currMonomDegree=getMonomDegree(monomGroup);
00599
00600 if ( ( lastMonomDegree==-1 && currMonomDegree==2 ) || lastMonomDegree+1==currMonomDegree )
00601 lastMonomDegree=currMonomDegree;
00602 else
00603 {
00604 throw " P and Q monom coefficient groups must be ordered ascending by degree and starting with monomDegree=2 ";
00605 }
00606
00607
00608 if (pol.getMaxDegree()>= currMonomDegree)
00609 {
00610
00611 #ifdef DEBUG
00612 cerr << "readMonomGroup()" << endl;
00613 #endif
00614 readMonomGroup(ring1, pol, monomGroup, currMonomDegree, p_or_q);
00615 #ifdef DEBUG
00616 cerr << "readMonomGroup() finished!" << endl;
00617 #endif
00618 }
00619 else
00620 {
00621 throw "Unexpected error: polynom max degree too small " ;
00622 }
00623 }
00624 #ifdef DEBUG
00625 cerr << "updatePolynom: while() finished!" << endl;
00626 #endif
00627 polynomStream>>ws;
00628 extractChar('}',polynomStream);
00629 polynomStream>>ws;
00630 #ifdef DEBUG
00631 std::cerr << "polynomStream! " << polynomStream.str() << std::endl;
00632 #endif
00633 assert(polynomStream.eof());
00634 #ifdef DEBUG
00635 std::cerr << "updatePolynom :finished!" << std::endl;
00636 #endif
00637 }
00638
00639
00640
00648 template <class TPolynomXY, class TRing >
00649 void CenterfocusParams< TPolynomXY, TRing >::updatePolynoms(stringstream & polynomData, TRing* ring1)
00650 {
00651 std::string strPolynomData=polynomData.str();
00652 if (strPolynomData.find("dx")!=std::string::npos || strPolynomData.find("dy")!=std::string::npos)
00653 {
00654 return updatePolynomsFromDifferentialForm(strPolynomData);
00655 }
00656
00657
00658
00659
00660 monomsWithAllCoefficients_m.clear();
00661 monomsWithRandomCoefficients_m.clear();
00662
00663
00664
00665 stringstream pstream;
00666 stringstream qstream;
00667 extractStreamFromPQStream(polynomData, PCoefficient, pstream, qstream);
00668
00669
00670 assert(ring1!=NULL);
00671 assert(infEps_minusP_polynom_m!=NULL);
00672 assert(infEps_Q_polynom_m!=NULL);
00673 infEps_minusP_polynom_m->clear(); infEps_Q_polynom_m->clear();
00674
00675 updatePolynom(ring1, *infEps_minusP_polynom_m, pstream, PCoefficient );
00676 updatePolynom(ring1, *infEps_Q_polynom_m, qstream, QCoefficient );
00677
00678 typename TRing::ElementType w;
00679 infEps_minusP_polynom_m->setCoeff(1,0, ring1->addInv( TRing::ElementType::One) );
00680 infEps_Q_polynom_m->setCoeff(0,1, TRing::ElementType::One);
00681
00682
00683 if (monomsWithAllCoefficients_m.isEmpty())
00684 containsMonomsWithAllCoefficientsCheck_m = false;
00685 else containsMonomsWithAllCoefficientsCheck_m = true;
00686
00687 if (monomsWithRandomCoefficients_m.isEmpty())
00688 containsMonomsWithRandomCoefficients_m = 0;
00689 else containsMonomsWithRandomCoefficients_m = 1;
00690 return;
00691 }
00692
00693 template <class TPolynomXY, class TRing >
00694 void CenterfocusParams< TPolynomXY, TRing >::updatePolynomsFromDifferentialForm(string differentialFormString)
00695 {
00696
00697 differentialFormString=eatWS(differentialFormString);
00698 std::stringstream sstre(differentialFormString);
00699 extractChar('{', sstre);
00700 sstre >> differentialFormString ;
00701 differentialFormString=differentialFormString.substr(0,differentialFormString.find("}"));
00702
00703 #ifdef DEBUG
00704 std::cerr << "differentialFormString=" << differentialFormString;
00705 #endif
00706
00707 typedef fieldScalar< int > localCoeffType ;
00708
00709 typedef polynomXY< localCoeffType, dynamicPolynomdefsNoShift > localPolynomXY_Type;
00710
00711
00712
00713
00714
00715
00716
00717
00718 xyOneForm<localPolynomXY_Type> oneForm = xyOneForm<localPolynomXY_Type>(differentialFormString);
00719
00720 localPolynomXY_Type PPolynom = oneForm.getDxFormPart();
00721 localPolynomXY_Type QPolynom = oneForm.getDyFormPart();
00722
00723 assert(PPolynom.getDegree()<= getPolynomialDegree() );
00724 assert(QPolynom.getDegree()<= getPolynomialDegree() );
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742 PolynomialRing<TPolynomXY,TRing > pr (*ringEps_m);
00743
00744 pr.convertInPlace(PPolynom);
00745 pr.convertInPlace(QPolynom);
00746
00747 #ifdef DEBUG
00748 std::cerr << "PPolynom = " << PPolynom << std::endl;
00749
00750 std::cerr << "QPolynom = " << QPolynom << std::endl;
00751 #endif
00752
00753 TPolynomXY tmpPPolynom( getPolynomialDegree() );
00754
00755 pr.copyPolynomWithGivenEpsPrecision(PPolynom, tmpPPolynom, 0);
00756
00757 *infEps_minusP_polynom_m =pr.addInv(tmpPPolynom);
00758
00759
00760 pr.copyPolynomWithGivenEpsPrecision(QPolynom, *infEps_Q_polynom_m, 0);
00761
00762 #ifdef DEBUG
00763 std::cerr << "infEps_minusP_polynom_m = " << *infEps_minusP_polynom_m << std::endl;
00764
00765 std::cerr << "infEps_Q_polynom_m = " << *infEps_Q_polynom_m << std::endl << std::endl;
00766 #endif
00767
00768 }
00769
00770
00771
00778
00779 template <class TPolynomXY, class TRing >
00780 bool CenterfocusParams< TPolynomXY, TRing >::readNextPolynoms()
00781 {
00782 #ifdef DEBUG
00783 std::cerr << std::endl << std::endl << "readNextPolynoms: " << std::endl;
00784 #endif
00785 if (!positionInLValue_m)
00786 {
00787 try
00788 {
00789 gotoLParamValue(*inputFile_m);
00790 braceLevel_m=0;
00791 }
00792 catch(const char* str) {
00793 std::cerr << "error: " << str << "\n";
00794 return false;
00795 }
00796 positionInLValue_m=true;
00797 #ifdef DEBUG
00798 std::cerr << "positionInLValue_m=true; " << std::endl;
00799 #endif
00800 }
00801 else{
00802 #ifdef DEBUG
00803 std::cerr << " positionInLValue_m=true; " << std::endl;
00804 #endif
00805 }
00806 try
00807 {
00808 stringstream polynomData;
00809 #ifdef DEBUG
00810 std::cerr << "braceLevel_m " << braceLevel_m << std::endl;
00811 #endif
00812 seekToBraceLevel(*inputFile_m,braceLevel_m,1);
00813
00814 char a;
00815 stripComments(*inputFile_m);
00816
00817 a=inputFile_m->peek();
00818 if (a=='}')
00819 {
00820
00821 extractChar('}', *inputFile_m);
00822 stripComments(*inputFile_m);
00823 extractChar(';', *inputFile_m);
00824 return false;
00825 }
00826
00827 if (firstPQ_m)
00828 {
00829 #ifdef DEBUG
00830 std::cerr << "firstPQ_m" << std::endl;
00831 #endif
00832
00833 stripComments(*inputFile_m);
00834 extractChar('{', *inputFile_m);
00835 stripComments(*inputFile_m);
00836 braceLevel_m++;
00837 firstPQ_m=false;
00838
00839 }
00840 else
00841 {
00842 #ifdef DEBUG
00843 std::cerr << "!firstPQ_m" << std::endl;
00844 #endif
00845 stripComments(*inputFile_m);
00846 extractChar(',', *inputFile_m);
00847 stripComments(*inputFile_m);
00848 extractChar('{', *inputFile_m);
00849 stripComments(*inputFile_m);
00850 braceLevel_m++;
00851 }
00852
00853 readNextPQPolynomStream(*inputFile_m,polynomData, braceLevel_m);
00854 #ifdef DEBUG
00855 std::cerr << "readNextPQPolynomStream FINISHED! " << std::endl;
00856 std::cerr << "braceLevel_m : " << braceLevel_m << std::endl;
00857 #endif
00858 updatePolynoms(polynomData, ringEps_m );
00859
00860
00862 pointID_m=-1;
00863
00864 stripComments(*inputFile_m);
00865 a=inputFile_m->peek();
00866
00867
00868 if (a==',')
00869 {
00870 stringstream pointID;
00871 extractChar(',', *inputFile_m);
00872 stripComments(*inputFile_m);
00873
00874 *inputFile_m >> pointID_m;
00875
00876 #ifdef DEBUG
00877 std::cerr << "pointid " << pointid << std::endl;
00878 #endif
00879 }
00880
00881 return true;
00882 }
00883 catch(const char* str) {
00884
00885 std::cerr << "Format error in polynom input data (L={...};): " << str << "\n";
00886 std::cerr << str << "\n";
00887 return false;
00888 }
00889 }
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00903 template <class TPolynomXY, class TRing >
00904 void CenterfocusParams< TPolynomXY, TRing >::initFieldCharacteristic()
00905 {
00906 try
00907 {
00908 fieldCharacteristic_m = 0;
00909
00910 Parameter & p = paramList_m->getParameterRefByName( characteristic_ConstString_m );
00911 assert ( & p != NULL);
00912 p.markUsed();
00913 p.setPrintOrder(10);
00914
00915 fieldCharacteristic_m = atoi( p.getValueAsString().c_str() );
00916 if (fieldCharacteristic_m<2)
00917 {
00918 std::cerr << "characteristic has to be prime and positive!" << std::endl;
00919 throw("characteristic has to be prime and positive!");
00920 }
00921 }
00922 catch(char* str)
00923 {
00924 std::cerr << "Format error in characteristic input data ("<< characteristic_ConstString_m <<" ={...};): " << str << "\n";
00925 exit( 0);
00926 }
00927 }
00928
00929
00930
00931
00932
00933 template <class TPolynomXY, class TRing >
00934 void CenterfocusParams< TPolynomXY, TRing >::initPolynomialDegree()
00935 {
00936 assert( paramList_m->paramExists(polynomialDegree_ConstString_m) );
00937
00938 Parameter & grad = paramList_m->getParameterRefByName(polynomialDegree_ConstString_m);
00939 try
00940 {
00941
00942 assert ( & grad != NULL );
00943 grad.markUsed();
00944 grad.setPrintOrder(40);
00945
00946 gradderpolynome_m = atoi( grad.getValueAsString().c_str() );
00947 if (gradderpolynome_m <2)
00948 {
00949 std::cerr << "polynomial degree must be greater than 1 !" << std::endl;
00950 throw("polynomial degree must be greater than 1 !");
00951 }
00952 }
00953 catch(const char* str)
00954 {
00955 std::cerr << " error: " << str << "\n";
00956 std::cerr << " polynomial degree" << grad.getName() << " interpreted as = " << gradderpolynome_m << "\n";
00957 exit( 0);
00958 }
00959 }
00960
00961
00962
00963
00964
00965
00966
00967
00970 template <class TPolynomXY, class TRing >
00971 template <class TInternParameter>
00972 bool CenterfocusParams< TPolynomXY, TRing >::initNonNegativeIntParameter(string name, TInternParameter & internParameter, int printOrder)
00973 {
00974
00975 if ( paramList_m->paramExists(name) )
00976 {
00977 Parameter & param = paramList_m->getParameterRefByName(name);
00978 {
00979
00980 try{
00981 param.setPrintOrder(printOrder);
00982 stringstream ss ;
00983 ss << param.getValueAsString();
00984 TInternParameter parsedInt=0;
00985 while (ss >>parsedInt);
00986 assert(parsedInt>=0);
00987 internParameter=parsedInt;
00988
00989
00990 }catch(...)
00991 {
00992 std::cerr << name << " initialisation error: parameter"<< name << " has wrong format. Possible values are positive integers " << std::endl;
00993 exit(0);
00994 }
00995 }
00996 }
00997 stringstream rs;
00998 rs<< internParameter;
00999
01000 if (!paramList_m->paramExists( name ))
01001 {
01002 paramList_m->addDefaultParameter( name , rs.str().c_str() );
01003 }
01004 else
01005 paramList_m->setParameterValue( name , rs.str().c_str() );
01006
01007 Parameter & param = paramList_m->getParameterRefByName(name);
01008 param.markUsed();
01009 return true;
01010 }
01011
01013 template <class TPolynomXY, class TRing >
01014 void CenterfocusParams< TPolynomXY, TRing >::initRandomSeed()
01015 {
01016
01017 initBoolParameter( randomSeedFromSysTime_ConstString_m , randomSeedFromSysTime_m, 130);
01018
01019 if ( randomSeedFromSysTime_m)
01020 {
01021 time_t tt;
01022
01023 time(&tt);
01024
01025 randomSeed_m = (tt);
01026
01027 randomSeed_m += getpid();
01028
01029 stringstream gss ;
01030 gss << randomSeed_m;
01031
01032 if (! paramList_m->paramExists( randomSeed_ConstString_m ) )
01033 {
01034 paramList_m->addDefaultParameter(randomSeed_ConstString_m, gss.str().c_str() );
01035 }
01036 Parameter & randomSeed = paramList_m->getParameterRefByName( randomSeed_ConstString_m );
01037
01038 randomSeed.setValue( gss.str().c_str() );
01039 randomSeed.markUsed();
01040 randomSeed.setPrintOrder(120);
01041 }
01042 else
01043 {
01044 try
01045 {
01046 if (! paramList_m->paramExists( randomSeed_ConstString_m ) )
01047 {
01048 stringstream gss ;
01049 gss << randomSeed_m;
01050 paramList_m->addDefaultParameter(randomSeed_ConstString_m, gss.str().c_str() );
01051 }
01052
01053 Parameter & randomSeed = paramList_m->getParameterRefByName( randomSeed_ConstString_m );
01054 stringstream ss ;
01055 ss << randomSeed.getValueAsString();
01056 while (ss >>randomSeed_m);
01057 assert(ss.eof());
01058
01059 randomSeed.markUsed();
01060 randomSeed.setPrintOrder(120);
01061 }
01062 catch(const char* str)
01063 {
01064 std::cerr << "random seed initialisation error: " << str << "\n";
01065 exit(0);
01066 }
01067
01068 }
01069 stringstream rs;
01070 rs<< randomSeed_m;
01071
01072 if (!paramList_m->paramExists( randomSeed_ConstString_m ))
01073 {
01074 paramList_m->addDefaultParameter( randomSeed_ConstString_m , rs.str().c_str() );
01075 }
01076 else
01077 paramList_m->setParameterValue( randomSeed_ConstString_m , rs.str().c_str() );
01078
01079 }
01080
01081
01082 template <class TPolynomXY, class TRing >
01083 void CenterfocusParams< TPolynomXY, TRing >::checkParameters() const
01084 {
01085 assert( (benutzeFormel_23_m && ! benutzeFormel_2_m) ||
01086 (!benutzeFormel_23_m && benutzeFormel_2_m) ||
01087 (!benutzeFormel_23_m && ! benutzeFormel_2_m)
01088 );
01089 }
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130 template <class TPolynomXY, class TRing >
01131 void CenterfocusParams< TPolynomXY, TRing >::initHamiltonianComponentSwitch()
01132 {
01133
01134 if (paramList_m->paramExists(HamiltonianComponentSwitch_ConstString_m) )
01135 {
01136 try
01137 {
01138 Parameter & hamiltonianSwitchParam = paramList_m->getParameterRefByName( HamiltonianComponentSwitch_ConstString_m );
01139 stringstream ss ;
01140 ss << hamiltonianSwitchParam.getValueAsString();
01141 while (ss >>HamiltonianComponentSwitch_m);
01142 assert( ss.eof() );
01143 hamiltonianSwitchParam.markUsed();
01144 hamiltonianSwitchParam.setPrintOrder(122);
01145 assert(HamiltonianComponentSwitch_m == -1 || HamiltonianComponentSwitch_m==0 || HamiltonianComponentSwitch_m==1 );
01146 }
01147 catch(const char* str)
01148 {
01149 std::cerr << "HamiltonianComponentSwitch initialisation error: " << str << "\n";
01150 exit(0);
01151 }
01152 }
01153 stringstream rs;
01154 rs<< HamiltonianComponentSwitch_m;
01155
01156 if (!paramList_m->paramExists( HamiltonianComponentSwitch_ConstString_m ))
01157 {
01158 paramList_m->addDefaultParameter( HamiltonianComponentSwitch_ConstString_m , rs.str().c_str() );
01159 }
01160 else
01161 paramList_m->setParameterValue( HamiltonianComponentSwitch_ConstString_m , rs.str().c_str() );
01162 }
01163
01164 template <class TPolynomXY, class TRing >
01165 void CenterfocusParams< TPolynomXY, TRing >::initPointFilter()
01166 {
01167 CFilterStrategy filterStrategy(CFilterStrategy::CF_FILTER_RANDOM_START);
01168
01169 if (paramList_m->paramExists(pointFilter_ConstString_m) )
01170 {
01171 try
01172 {
01173
01174 Parameter & pointFilterParam = paramList_m->getParameterRefByName( pointFilter_ConstString_m );
01175 if (paramList_m->paramExists(pointFilterStrategy_ConstString_m) )
01176 {
01177 Parameter & pointFilterStrategyParam = paramList_m->getParameterRefByName( pointFilterStrategy_ConstString_m );
01178
01179
01180 filterStrategy= CFilterStrategy(pointFilterStrategyParam.getValueAsString() );
01181 pointFilterStrategyParam.markUsed();
01182 pointFilterStrategyParam.setPrintOrder(122);
01183
01184 }
01185
01186 std::string str1("");
01187 std::string str2("");
01188 stringstream ss( pointFilterParam.getValueAsString() );
01189 stringstream ss2;
01190
01191 while( ss >> std::ws >>str1)
01192 {
01193 str2+=str1;
01194 }
01195
01196
01197 pointFilter = new CFPointFilter( str2, filterStrategy, pointFilter_ConstString_m );
01198
01199 pointFilterParam.markUsed();
01200 pointFilterParam.setPrintOrder(122);
01201
01202 if (!paramList_m->paramExists( pointFilterStrategy_ConstString_m ))
01203 {
01204 paramList_m->addDefaultParameter( pointFilterStrategy_ConstString_m , filterStrategy.getValueAsString().c_str() );
01205 }
01206 }
01207 catch(const char* str)
01208 {
01209 std::cerr << "pointFilter initialisation error: " << str << "\n";
01210 exit(0);
01211 }
01212 }
01213 else
01214 {
01215 pointFilter = new CFPointFilter( filterStrategy, pointFilter_ConstString_m );
01216 }
01217 assert(pointFilter);
01218
01219 }
01220
01221
01224 template <class TPolynomXY, class TRing >
01225 void CenterfocusParams< TPolynomXY, TRing >::initExperimentTag()
01226 {
01227 if (paramList_m->paramExists (experimentTag_ConstString_m))
01228 {
01229 Parameter & pExperimentTag = paramList_m->getParameterRefByName( experimentTag_ConstString_m );
01230 stringstream tagstream;
01231
01232 experimentTag_m="";
01233 tagstream << pExperimentTag.getValueAsString();
01234
01235 extractChar('\"',tagstream);
01236 char ch;
01237 while (!tagstream.eof() && !tagstream.fail() )
01238 {
01239 tagstream >> ch;
01240
01241 if (!tagstream.eof() && !tagstream.fail() && ch>31)
01242 {
01243
01244 experimentTag_m+=ch;
01245 }
01246
01247
01248 }
01249 assert(experimentTag_m[experimentTag_m.size()-1]=='\"');
01250
01251 experimentTag_m=experimentTag_m.substr(0,experimentTag_m.size()-1);
01252 experimentTag_m=trim(experimentTag_m);
01253 experimentTagNoWS_m=experimentTag_m;
01254 paramList_m->addParameter( experimentTagNoWhiteSpaces_ConstString_m, experimentTag_m.c_str() );
01255 experimentTag_m='\"'+experimentTag_m+'\"';
01256 paramList_m->setParameterValue( experimentTag_ConstString_m , experimentTag_m.c_str() );
01257
01258 pExperimentTag.markUsed();
01259 pExperimentTag.setPrintOrder(1);
01260 }
01261 else
01262 {
01263 paramList_m->addDefaultParameter( experimentTag_ConstString_m , string("\"\"") );
01264 }
01265 }
01266
01267
01268 template <class TPolynomXY, class TRing >
01269 void CenterfocusParams< TPolynomXY, TRing >::convertStringParamsToOptions()
01270 {
01271
01272 assert( paramList_m!=NULL );
01273
01274
01275 this->initFieldCharacteristic();
01276
01278 maxFocalValuesToCompute_m = getMaxComputableFocalValues();
01279 initNonNegativeIntParameter( maxFocalValues_ConstString_m, maxFocalValuesToCompute_m, 110);
01280
01281 initNonNegativeIntParameter( reqVanisnedValues_ConstString_m, bReqVanishedFocalValues_m, 110);
01282
01283
01284
01285 this->initPolynomialDegree();
01286
01287 initNonNegativeIntParameter( epsPrecision_ConstString_m, epsPrecision_m, 110);
01288
01289
01290 if (paramList_m->paramExists ( minJacobianRank_ConstString_m ) )
01291 {
01292 try{
01293 Parameter & minJacobianMatrixRank = paramList_m->getParameterRefByName( minJacobianRank_ConstString_m );
01294 minJacobianMatrixRank.markUsed();
01295 minJacobianMatrixRank.setPrintOrder(80);
01296 reqFullJacobianMinRank_m = atoi( minJacobianMatrixRank.getValueAsString().c_str() );
01297 assert(reqFullJacobianMinRank_m>=0);
01298 }
01299 catch(...)
01300 {
01301 cerr << "error: parsing parameter 'minJacobianMatrixRank' failed" ;
01302 exit(0);
01303
01304 }
01305 }
01306 else
01307 {
01308 reqFullJacobianMinRank_m=0;
01309 stringstream ss ;
01310 ss << reqFullJacobianMinRank_m;
01311 paramList_m->addDefaultParameter( minJacobianRank_ConstString_m , ss.str().c_str() );
01312 }
01313 if (paramList_m->paramExists ( minJacobianSubMatrixRank_ConstString_m ) )
01314 {
01315 try{
01316 Parameter & minSubJacobianMatrixRank = paramList_m->getParameterRefByName( minJacobianSubMatrixRank_ConstString_m );
01317
01318 minSubJacobianMatrixRank.markUsed();
01319 minSubJacobianMatrixRank.setPrintOrder(81);
01320 reqSubJacobianMinRank_m = atoi( minSubJacobianMatrixRank.getValueAsString().c_str() );
01321 assert(reqSubJacobianMinRank_m>=0);
01322 }
01323 catch(...)
01324 {
01325 reqSubJacobianMinRank_m = 0;
01326 cerr << "error: parsing parameter 'minJacobianSubMatrixRank' failed" ;
01327 exit(0);
01328
01329 }
01330 }
01331 else
01332 {
01333 reqSubJacobianMinRank_m=0;
01334 stringstream ss ;
01335 ss << reqSubJacobianMinRank_m;
01336 paramList_m->addDefaultParameter( minJacobianSubMatrixRank_ConstString_m , ss.str().c_str() );
01337 }
01338
01339
01340
01341
01342 infEps_minusP_polynom_m = new TPolynomXY(gradderpolynome_m);
01343 infEps_Q_polynom_m = new TPolynomXY(gradderpolynome_m);
01344
01345
01346 ringEps_m = new TRing(fieldCharacteristic_m, epsPrecision_m );
01347 this->initHasVariableCoefficients();
01348
01349 this->initRandomSeed();
01350
01351
01352
01353 initNonNegativeIntParameter( checkpointInterval_ConstString_m, checkpointInterval_m, 104);
01354
01355 initNonNegativeIntParameter( randomCounterStartValue_ConstString_m, randomCounterStartValue_m, 104);
01356
01357 initNonNegativeIntParameter( randomTrialsNum_ConstString_m, azZufallszahlen_m, 104);
01358
01359
01360
01361
01362
01363
01364 initBoolParameter( pureSmothnessTest_ConstString_m , bPureSmoothnessTest_m, 130);
01365
01366 initBoolParameter( useFormula1_ConstString_m , benutzeFormel_1_m, 140);
01367 initBoolParameter( useFormula2_ConstString_m , benutzeFormel_2_m, 150);
01368
01369 initBoolParameter( showProgress_ConstString_m , bShowProgress_m, 171);
01370
01371
01372 initBoolParameter( useFormula23_ConstString_m , benutzeFormel_23_m, 155);
01373
01374
01375
01376 initBoolParameter( appendResults_ConstString_m , bMultipleExperimentsInAFile_m, 170);
01377
01378
01379 initNonNegativeIntParameter( minComponentCodim_ConstString_m, minComponentCodim_m, 110);
01380 initNonNegativeIntParameter( maxLift_ConstString_m, maxLift_m, 111);
01381 initNonNegativeIntParameter( liftTrials_ConstString_m, liftTrials_m, 112);
01382
01383
01384 if ( !paramList_m->paramExists(exhaustiveMaxLift_ConstString_m) )
01385 exhaustiveMaxLift_m=maxLift_m;
01386 initNonNegativeIntParameter( exhaustiveMaxLift_ConstString_m, exhaustiveMaxLift_m, 113 );
01387
01388
01389 if (! paramList_m->paramExists(exhaustiveLiftTrials_ConstString_m) )
01390 exhaustiveLiftTrials_m=liftTrials_m;
01391 initNonNegativeIntParameter( exhaustiveLiftTrials_ConstString_m, exhaustiveLiftTrials_m, 114 );
01392
01393 initNonNegativeIntParameter( requestedLiftPointNum_ConstString_m, requestedLiftPointNum_m,115 );
01394
01395 initExperimentTag();
01396
01397 initPointFilter();
01398
01399 initCoeffVariablesOrder();
01400
01401
01402
01403 initHamiltonianComponentSwitch();
01404
01406 initBoolParameter( nonSmoothPointPassFilter_ConstString_m , bNonSmoothPointPassFilter_m, 170);
01407
01408 initBoolParameter( logExtendedLiftStatistic_ConstString_m , bLogExtendedLiftStatistic_m, 170);
01409 }
01410
01411
01412
01413
01414 template <class TPolynomXY, class TRing >
01415 bool CenterfocusParams< TPolynomXY, TRing >::initBoolParameter(string name, bool & internParameter, int printOrder)
01416 {
01417
01418 if ( paramList_m->paramExists(name) )
01419 {
01420 Parameter & param = paramList_m->getParameterRefByName(name);
01421 {
01422
01423 param.setPrintOrder(printOrder);
01424 if ( param.getValueAsString().compare(true_ConstString_m) == 0)
01425 {
01426 internParameter = true;
01427 param.markUsed();
01428
01429 return true;
01430 }
01431
01432 else if ( param.getValueAsString().compare(false_ConstString_m) == 0)
01433 {
01434 internParameter = false;
01435 param.markUsed();
01436
01437 return true;
01438 }
01439 else
01440 {
01441 std::cerr << name << " initialisation error: wrong format; possible values only 'true' and 'false' " << std::endl;
01442 exit(0);
01443 }
01444 }
01445 }
01446 else
01447 {
01448 if (internParameter)
01449 paramList_m->addDefaultParameter(name,true_ConstString_m);
01450 else
01451 paramList_m->addDefaultParameter(name,false_ConstString_m);
01452 }
01453 return false;
01454 }
01455
01456
01457
01458
01459
01460
01461
01462
01463
01464
01465
01466
01467 template <class TPolynomXY, class TRing >
01468 void CenterfocusParams< TPolynomXY, TRing >::loadParamListFromString(const char * inputParameters)
01469 {
01470 istringstream * ss = new istringstream( string(inputParameters),istringstream::in);
01471 inputFile_m=ss;
01472
01473
01474 loadParamList(*inputFile_m);
01475 checkParameters();
01476 }
01477
01478
01479 template <class TPolynomXY, class TRing >
01480 void CenterfocusParams< TPolynomXY, TRing >::loadParamList(string inputFileName)
01481 {
01482
01483 if (inputFileName.compare("-")==0)
01484 {
01485 inputFromStd_m=true;
01486
01487 string tmpString ;
01488 string inputFileString="";
01489 while ( std::getline(std::cin, tmpString) )
01490 {
01491 inputFileString=inputFileString+"\n"+ tmpString;
01492 }
01493 istringstream * ss = new istringstream( string(inputFileString),istringstream::in);
01494 inputFile_m=ss;
01495 loadParamList(*inputFile_m);
01496 }
01497
01498 else
01499 {
01500 inputFromStd_m=false;
01501 inputFile_m = new ifstream(inputFileName.c_str(), ios::in);
01502 loadParamList(*inputFile_m);
01503 }
01504 checkParameters();
01505 }
01506
01507
01511 template <class TPolynomXY, class TRing >
01512 void CenterfocusParams< TPolynomXY, TRing >::loadParamList(istream &fileInStream_)
01513 {
01514 std::cerr << "loadParams" << std::endl;
01515 paramList_m = new Parameterlist;
01516 string paramname="";
01517 parameterNameExpected_m=true;
01518
01519 fileInStream_.clear();
01520
01521 char a;
01522 stringstream cache;
01523 bool macaulayCode=false;
01524
01525 if (fileInStream_)
01526 {
01527 while ( !fileInStream_.eof() )
01528 {
01529 if ( macaulayCode )
01530 {
01531 fileInStream_ >> std::noskipws >> a;
01532 cache << a;
01533 size_t found=cache.str().find("fi MacaulayDefinitions");
01534 if (found!=string::npos)
01535 macaulayCode=false;
01536 continue;
01537 }
01538
01539 stripComments(fileInStream_);
01540 fileInStream_ >> std::ws;
01541 stripComments(fileInStream_);
01542
01543
01544 paramname=readParamName(fileInStream_);
01545
01546 cerr << "paramname" << "[" << paramname << "]"<<endl;
01547 parameterNameExpected_m=false;
01548 #ifdef DEBUG
01549 cerr <<" loadParamList, paramname = " <<paramname << endl;
01550 #endif
01551
01552
01553 extractChar('=',fileInStream_);
01554
01555 string paramValue=readParamValue(fileInStream_, paramname);
01556 #ifdef DEBUG
01557 cerr <<" loadParamList, paramValue = " <<paramValue << endl;
01558 #endif
01559
01560 extractChar(';',fileInStream_);
01561
01562 string comment=readCurrentComment(fileInStream_);
01563
01564 if ( paramname.compare("LInputString")==0 )
01565 {
01566 continue;
01567 }
01568 if ( paramname.compare("cfEndParams")==0 )
01569 {
01570 break;
01571 }
01572 if ( paramname.compare("cfMacaulayCode")==0 )
01573 {
01574 cache.clear();
01575 macaulayCode=true;
01576 continue;
01577 }
01578
01579 if (paramname.compare("L")==0)
01580 {
01581 paramname = "L_input";
01582
01583 paramname = "LInputString";
01584
01585 paramValue = string("\" L = ") + paramValue + string(";\"");
01586
01587 }
01588
01589
01590
01591 paramList_m->addParameter( paramname, paramValue, comment );
01592
01593
01594 parameterNameExpected_m=true;
01595 }
01596 Parameter & LInputString = paramList_m->getParameterRefByName("LInputString");
01597 LInputString.setPrintOrder(170);
01598 LInputString.markUsed();
01599
01600 }
01601
01602 std::cerr << "convertStringParamsToOptions" << std::endl << std::endl;
01603 convertStringParamsToOptions();
01604 std::cerr << "checkParameters" << std::endl << std::endl;
01605 checkParameters();
01606 std::cerr << "loadParams :finished!" << std::endl << std::endl;
01607 }
01608
01609
01610
01611
01619 template <class TPolynomXY, class TRing >
01620 void CenterfocusParams< TPolynomXY, TRing >::printParameters(ostream &oFile) const
01621 {
01622
01623 oFile << std::endl << "cfMacaulayCode = \"\"; " << std::endl;
01624 oFile << std::endl << " try ( if (not MacaulayDefinitions) then ()) then (MacaulayDefinitions=MacaulayDefinitions) else (MacaulayDefinitions=true);" << std::endl;
01625
01626 oFile << std::endl << "if MacaulayDefinitions then {" << std::endl;
01627 oFile << "-- Macaulay2 defines: " << std::endl;
01628 oFile << "\tp = " << fieldCharacteristic_m << ";"<< std::endl;
01629 oFile << "\t-- define field:" << std::endl;
01630 oFile << "\tFp = ZZ/p;" << std::endl;
01631 oFile << "\t-- define rings :" << std::endl;
01632 oFile << "\t-- for calculation with epsilon" << std::endl;
01633 oFile << "\tScf = Fp[eps]; " << std::endl;
01634
01635
01637 oFile << "\tTcf = Fp[ " ;
01638
01639 bool firstEntry =true;
01640 int ttIndex=1;
01641
01642 list<CoeffListEntry>::const_iterator coeffIt;
01643
01644 for ( coeffIt = coeffVariablesOrder_m.begin(); coeffIt!=coeffVariablesOrder_m.end(); coeffIt++, ttIndex++ )
01645 {
01646 if (!firstEntry)
01647 oFile << ", " ;
01648 else
01649 firstEntry = false;
01650 oFile << "tt_"<< ttIndex ;
01651 }
01652
01653 oFile << " ];" << std::endl;
01654
01656 firstEntry = true;
01657 oFile << "\tPQcf = Fp[ ";
01658
01659 for ( coeffIt = coeffVariablesOrder_m.begin(); coeffIt!=coeffVariablesOrder_m.end(); coeffIt++ )
01660 {
01661 if (!firstEntry)
01662 oFile << ", " ;
01663 else
01664 firstEntry = false;
01665
01666 if ( (*coeffIt).isPMonom() )
01667 oFile << "pp_{"<< (*coeffIt).x_exp << "," << (*coeffIt).y_exp << "}";
01668 else
01669 oFile << "qq_{"<< (*coeffIt).x_exp << "," << (*coeffIt).y_exp << "}";
01670 }
01671
01672 oFile << " ];" << std::endl;
01673 oFile << "} --fi MacaulayDefinitions " << std::endl;
01674 paramList_m->printNotUsedParameters(oFile);
01675
01676 paramList_m->printUsedParameters(oFile);
01677
01678 }
01679
01680
01681 template <class TPolynomXY, class TRing >
01682 void CenterfocusParams< TPolynomXY, TRing >::initHasVariableCoefficients()
01683 {
01684
01685 bHasVariableCoefficients_m = false;
01686
01687 positionInLValue_m=false;
01688
01689
01690 parameterNameExpected_m = true;
01691
01692 inputFile_m->clear();
01693 assert(!inputFile_m->fail() );
01694 inputFile_m->seekg (0, ios::beg);
01695 assert(!inputFile_m->fail() );
01696 positionInLValue_m = false;
01697 firstPQ_m = true;
01698 braceLevel_m = 0;
01699
01700 while( readNextPolynoms() )
01701 {
01702 if (polynomsContainsVariableCoeff() )
01703 {
01704 bHasVariableCoefficients_m = true;
01705 return;
01706 }
01707 }
01708 inputFile_m->clear();
01709 assert(!inputFile_m->fail());
01710 inputFile_m->seekg (0, ios::beg);
01711 assert(!inputFile_m->fail());
01712 positionInLValue_m=false;
01713 firstPQ_m = true;
01714 braceLevel_m = 0;
01715
01716 positionInLValue_m = false;
01717 parameterNameExpected_m = true;
01718
01719 return ;
01720 }
01721
01723 template <class TPolynomXY, class TRing >
01724 bool CenterfocusParams< TPolynomXY, TRing >::areWellDefined()
01725 {
01726
01727 bool wellDefined=true;
01728
01729 positionInLValue_m=false;
01730
01731 int experimentCounter=0;
01732
01733 bHasVariableCoefficients_m = false;
01734
01735 parameterNameExpected_m = true;
01736
01737 inputFile_m->clear();
01738 assert( !inputFile_m->fail() );
01739 inputFile_m->seekg (0, ios::beg);
01740 assert(!inputFile_m->fail());
01741 positionInLValue_m = false;
01742 firstPQ_m = true;
01743 braceLevel_m = 0;
01744
01745
01746
01747 while( readNextPolynoms() )
01748 {
01749 assert(!inputFile_m->fail());
01750 if (polynomsContainsVariableCoeff() )
01751 {
01752 bHasVariableCoefficients_m=true;
01753 }
01754 if (experimentCounter>0 && (polynomsContainsVariableCoeff() || bHasVariableCoefficients_m) )
01755 {
01756 std::cerr << "Error: currently it is not allowed to define multiple random experiments in one input file \
01757 or to mix experiments with varyying coefficients with simple point tests " << std::endl;
01758 wellDefined= false;
01759 }
01760
01761 experimentCounter++;
01762 }
01763 inputFile_m->clear();
01764 assert(!inputFile_m->fail());
01765 inputFile_m->seekg (0, ios::beg);
01766 assert(!inputFile_m->fail());
01767 positionInLValue_m=false;
01768 firstPQ_m = true;
01769 braceLevel_m = 0;
01770
01771 positionInLValue_m = false;
01772 parameterNameExpected_m = true;
01773
01774 assert(maxFocalValuesToCompute_m>0);
01775 assert(maxFocalValuesToCompute_m <= getMaxComputableFocalValues() );
01776
01777 assert(exhaustiveLiftTrials_m>=liftTrials_m);
01778 assert(exhaustiveMaxLift_m>=maxLift_m);
01779
01780 if (getEpsPrecision()<0)
01781 {
01782 std::cerr << "Error: negative epsPrecision" <<std::endl;
01783 wellDefined= false;
01784 }
01785
01786 if (benutzeFormel_2_m && benutzeFormel_23_m)
01787 {
01788 std::cerr << "Error: it is not possible to use together formula2 and formula23)" <<std::endl;
01789 wellDefined= false;
01790 }
01791 if (benutzeFormel_23_m && ! benutzeFormel_1_m)
01792 {
01793 std::cerr << "Error: it is not allowed to use formula23 without formula1."<< std::endl;
01794 wellDefined= false;
01795 }
01796 if (benutzeFormel_2_m && ! benutzeFormel_1_m)
01797 {
01798 std::cerr << "Error: it is not allowed to use formula2 without formula1."<< std::endl;
01799 wellDefined= false;
01800 }
01801
01802 if ( benutzeFormel_23_m && this->polynomsHaveCheckAllCoeff() )
01803 {
01804
01805 std::cerr << "Error: AllCoefficient-search is not implemented for formula23 )" <<std::endl;
01806 wellDefined= false;
01807 }
01808
01809 if (!bHasVariableCoefficients_m && (benutzeFormel_1_m || benutzeFormel_2_m || benutzeFormel_23_m) )
01810 {
01811 std::cerr << "Error: it is not possible to use a formula without random coefficients" <<std::endl;
01812 wellDefined= false;
01813 }
01814
01816 if (!polynomsHaveRandomCoeff() && getRequestedTrialsNum()>0)
01817 {
01818 std::cerr << "Error: it is not possible to perform random trials without random coefficients" <<std::endl;
01819 wellDefined= false;
01820 }
01821
01822
01823 assert(this->getRequestedLiftPointNum()>=0 );
01824 if (this->getRequestedLiftPointNum()>0 )
01825 {
01826
01827 assert( liftTrials_m > 0 );
01828 }
01829
01830 if ( liftTrials_m<0 || maxLift_m<0)
01831 {
01832 std::cerr << "Error:liftTrials_m or maxLift_m<0 !"<< std::endl;
01833
01834 wellDefined= false;
01835
01836 }
01837
01838
01839 if ( getMaxLift()>0 )
01840 assert( liftTrials_m>0 );
01841
01842 if ( liftTrials_m>0 )
01843 {
01844
01845 if (bReqVanishedFocalValues_m <= 0)
01846 {
01847 std::cerr << "Error: for a lift required vanished focal values must be at least 1 !"<< std::endl;
01848 wellDefined= false;
01849 }
01850
01851 if (getMaxLift() < 2)
01852 {
01853 std::cerr << "Error: for a lift test maxLift must be at least =2 !"<< std::endl;
01854 wellDefined= false;
01855 }
01856 #ifdef USESSE
01857
01858 assert(getMaxLift()< ringEps_m->maxEpsPrecision_m - 16);
01859 #endif
01860
01861 if (getEpsPrecision()>0)
01862 {
01863 std::cerr << "epsPrecision is > 0. TODO: what is a lift test for a point with epsPrecision>0?"<< std::endl;
01864 wellDefined= false;
01865 }
01866 }
01867 assert(minComponentCodim_m>=0);
01868
01869 assert(pointFilter);
01870
01872 assert(requiredVanishedFocalValuesNum()>=getParametrizedFocalValuesNum() );
01873
01874 assert( this->gradderpolynome_m>1 );
01875
01876
01877 assert( this->gradderpolynome_m<=3 );
01878
01879
01880
01881
01882 return wellDefined;
01883 }
01884
01885
01886
01887 template <class TPolynomXY, class TRing >
01888 void CenterfocusParams< TPolynomXY, TRing >::initAllCoeffitientsAreVariables()
01889 {
01890 std::list<CoeffListEntry>::const_iterator coeffIt;
01891
01892 bAllConstCoefficientsAreVariables_m=true;
01893
01894 coeffIt =coeffVariablesOrder_m.begin();
01895 while (coeffIt!=coeffVariablesOrder_m.end() )
01896 {
01897 if (! isCoefficientVariable( *coeffIt ) )
01898 {
01899 bAllConstCoefficientsAreVariables_m=false;
01900 return;
01901 }
01902 coeffIt++;
01903 }
01904
01905 }
01909 template <class TPolynomXY, class TRing >
01910 void CenterfocusParams< TPolynomXY, TRing >::initCoeffVariablesOrder( )
01911 {
01912 for (int currentMonomDegree=2; currentMonomDegree <= getPolynomialDegree(); currentMonomDegree++)
01913 {
01914
01915 CoeffListEntry currentEntry;
01916 for (int j=0; j<=currentMonomDegree; j++ )
01917 {
01918 currentEntry=CoeffListEntry( PCoefficient,j,currentMonomDegree );
01919 coeffVariablesOrder_m.push_back( currentEntry );
01920
01921 }
01922 for (int j=0; j<=currentMonomDegree; j++ )
01923 {
01924 currentEntry=CoeffListEntry( QCoefficient,j,currentMonomDegree );
01925 coeffVariablesOrder_m.push_back( currentEntry );
01926 }
01927 }
01928 }
01929
01930
01932 template <class TPolynomXY, class TRing >
01933 long64 CenterfocusParams< TPolynomXY, TRing >::getCoeffTry(const CoeffList & coefflist ) const
01934 {
01935 list<CoeffListEntry>::const_iterator coeffIt = coeffVariablesOrder_m.end();
01936
01937 long64 coeffTry=0;
01938
01939 do
01940 {
01941 coeffIt--;
01942 coeffTry=coeffTry << 1;
01943 if ( coefflist.containsEntry(*coeffIt) )
01944 {
01945 (coeffTry = coeffTry | 1);
01946 }
01947
01948 }
01949 while(coeffIt!=coeffVariablesOrder_m.begin() );
01950
01951 return coeffTry;
01952 }
01953
01954 template <class TPolynomXY, class TRing >
01955 long64 CenterfocusParams< TPolynomXY, TRing >::getCoeffTryAll() const
01956 {
01957 assert( getPolynomialDegree()<7 ) ;
01958 return getCoeffTry(monomsWithAllCoefficients_m);
01959 }
01960
01961
01962 template <class TPolynomXY, class TRing >
01963 long64 CenterfocusParams< TPolynomXY, TRing >::getCoeffTryRandom() const
01964 {
01965 assert( getPolynomialDegree()<7 ) ;
01966 return getCoeffTry(monomsWithRandomCoefficients_m);
01967 }
01968
01969
01970