ReadCenterFocusParams.h
Go to the documentation of this file.00001 #ifndef READ_CENTERFOCUS_PARAMS
00002 #define READ_CENTERFOCUS_PARAMS
00003
00004 #include "CoeffList.h"
00005 #include "Parameterlist.h"
00006 #include <time.h>
00007
00008
00009 #include "RangStatistik.h"
00010 #include "Statistik.h"
00011
00012
00013 #include "random.h"
00014
00015 #include "parseTools.h"
00016 #include "xyMonom.h"
00017 #include <fcntl.h>
00018 #include <cerrno>
00019 #include <cstdio>
00020
00021
00022
00023 #include <pwd.h>
00024 #include <sys/types.h>
00025 #include <cstdio>
00026 #include <iostream>
00027 #include <time.h>
00028
00029 #include "pointFilter.h"
00030
00031
00045
00046
00047
00048
00073 namespace nCenterFocus
00074 {
00075
00076
00077
00078
00079
00080
00081 bool isMonomChar(char a);
00082
00083
00084
00085
00086
00087
00088
00090 bool isMonomChar(char a)
00091 {
00092 if (isdigit(a)||(a == 'A')||(a == '?')||(a == '^')||
00093 (a == '-')||(a == '*')||(a == 'e')||(a == '+')||isspace(a))
00094 {
00095 return true;
00096 }
00097 return false;
00098 }
00099
00101 bool isAllMarker(string mo)
00102 {
00103 string m=eatWS(mo);
00104 return (m.length()==1 && m.compare("A")==0);
00105 }
00106
00108 bool isRandomMarker(string morig)
00109 {
00110 string mc=eatWS(morig);
00111 return (mc.length()==1 && (mc[0]=='?'||mc[0]=='*'));
00112 }
00113
00114
00115
00116
00117
00118
00119
00120
00121
00124 template <class _istream>
00125 void gotoLParamValue(_istream &inputStream, bool parameterNameExpected=true)
00126 {
00127 bool positionInLValue=false;
00128
00129
00130 #ifdef DEBUG
00131 std::cerr << "gotoLParamValue " << std::endl;
00132 #endif
00133
00134 inputStream.clear();
00135 assert( !inputStream.fail() );
00136 inputStream.seekg (0, ios::beg);
00137
00138 char a;
00139 stringstream cache;
00140 bool macaulayCode=false;
00141
00142 while (!positionInLValue)
00143 {
00144 assert( !inputStream.eof() );
00145 assert( !inputStream.fail() );
00146 if (parameterNameExpected)
00147 {
00148 if ( macaulayCode )
00149 {
00150 inputStream >> std::noskipws >> a;
00151 cache << a;
00152 size_t found=cache.str().find("fi MacaulayDefinitions");
00153 if (found!=string::npos)
00154 macaulayCode=false;
00155 continue;
00156 }
00157 stripComments(inputStream);
00158 string paramname=readParamName(inputStream);
00159 #ifdef DEBUG
00160 std::cerr << std::endl; std::cerr << std::endl;
00161 std::cerr << "paramname = " << paramname << std::endl;
00162 #endif
00163 parameterNameExpected=false;
00164 if ( paramname.compare("L") == 0)
00165 {
00166 extractChar('=',inputStream);
00167 positionInLValue=true;
00168 return;
00169 }
00170 else
00171 {
00172 extractChar('=',inputStream);
00173 string paramValue=readParamValue(inputStream, paramname);
00174 #ifdef DEBUG
00175 std::cerr << "paramValue =" << paramValue << std::endl;
00176 std::cerr << std::endl;
00177 std::cerr << std::endl; std::cerr << std::endl;
00178 #endif
00179 extractChar(';',inputStream);
00180 readCurrentComment(inputStream);
00181 parameterNameExpected=true;
00182
00183 if ( paramname.compare("cfMacaulayCode")==0 )
00184 {
00185 cache.clear();
00186 macaulayCode=true;
00187 continue;
00188 }
00189 }
00190 }
00191 else
00192 {
00193 throw "gotoLParamValue: not possible!";
00194
00195 }
00196 }
00197 throw "gotoLParamValue: file ends unexpectly";
00198 }
00199
00200
00201
00207 template <class _istream>
00208 void readNextPQPolynomStream(_istream &inp, stringstream &polynomData, int &braceLevel)
00209 {
00210 assert(braceLevel==2);
00211
00213
00214 extractChar('{',inp);
00215 polynomData << '{';
00216 braceLevel++;
00217
00218 char a='\0';
00219
00220 while (!inp.eof())
00221 {
00222 inp >> a;
00223
00224 if (a=='{') braceLevel++;
00225
00226 else if (a=='}') braceLevel--;
00227
00228 else if (a==';') throw "readNextPQPolynomStream: unexpected end of Data";
00229 else if (a=='=') throw "readNextPQPolynomStream: unexpected assignment in Data";
00230
00231 if (a=='-' && inp.peek()=='-')
00232 {
00233 inp.putback('-');
00234
00235 stripComments(inp);
00236 }
00237 else
00238 {
00239 polynomData << a;
00240 }
00241 if (braceLevel>4) throw "readNextPQPolynomStream: too many opened braces! ";
00242
00243 if (braceLevel==2)
00244 {
00245 #ifdef DEBUG
00246 std::cerr << "polynomData" << polynomData.str() << std::endl;
00247 std::cerr << " readNextPQPolynomStream: finished!" << std::endl;
00248 #endif
00249 return;
00250 }
00251 }
00252 if (inp.fail())
00253 throw "readNextPQPolynomStream: unexpected error";
00254 std::cerr << " readNextPQPolynomStream: finished!" << std::endl;
00255 }
00256
00257
00258
00259
00260 void extractStreamFromPQStream(stringstream &polynomData, P_or_QPolynom p_or_q, stringstream &PStream,stringstream &QStream )
00261 {
00262 #ifdef DEBUG
00263 std::cerr << "extractStreamFromPQStream" << std::endl;
00264 #endif
00265
00266 extractChar('{',polynomData);
00267
00268 PStream <<'{'; QStream<< '{';
00269
00270 polynomData>>ws;
00271 while (!polynomData.eof() && polynomData.peek()=='{')
00272 {
00273 PStream << extractNextBracedData(polynomData);
00274 extractChar(',',polynomData);
00275 QStream << extractNextBracedData(polynomData);
00276 polynomData>>ws;
00277 if ( polynomData.peek()!='}')
00278 {
00279 extractChar(',',polynomData);
00280 PStream<< ',';
00281 QStream<< ',';
00282 }
00283 polynomData>>ws;
00284 }
00285
00286 extractChar('}',polynomData);
00287
00288 PStream << '}'; QStream << '}';
00289 #ifdef DEBUG
00290 std::cerr << "P" << PStream.str() << std::endl;
00291 std::cerr << "Q" << QStream.str() << std::endl;
00292 std::cerr << "extractStreamFromPQStream : finished!" << std::endl;
00293 #endif
00294 return ;
00295 }
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00326
00338 template <class TPolynomXY, class TRing>
00339 class CenterfocusParams
00340 {
00341
00342 public:
00343 typedef TPolynomXY PolynomXY_Type;
00344 typedef TRing RingType;
00345
00346 static const string nonSmoothPointPassFilter_ConstString_m;
00347 static const string maxFocalValues_ConstString_m;
00348 static const string reqVanisnedValues_ConstString_m;
00349 static const string characteristic_ConstString_m;
00350 static const string polynomialDegree_ConstString_m;
00351 static const string randomTrialsNum_ConstString_m;
00352 static const string randomSeed_ConstString_m;
00353 static const string randomSeedFromSysTime_ConstString_m;
00354 static const string maxLift_ConstString_m;
00355 static const string liftTrials_ConstString_m;
00356 static const string exhaustiveMaxLift_ConstString_m;
00357 static const string exhaustiveLiftTrials_ConstString_m;
00358 static const string requestedLiftPointNum_ConstString_m;
00359
00360 static const string epsPrecision_ConstString_m;
00361 static const string minJacobianRank_ConstString_m;
00362 static const string minJacobianSubMatrixRank_ConstString_m;
00363 static const string useFormula1_ConstString_m;
00364 static const string useFormula2_ConstString_m;
00365 static const string useFormula23_ConstString_m;
00366 static const string appendResults_ConstString_m;
00367
00368 static const string experimentTag_ConstString_m;
00369 static const string experimentTagNoWhiteSpaces_ConstString_m;
00370
00371 static const string showProgress_ConstString_m;
00372
00373 static const string true_ConstString_m;
00374 static const string false_ConstString_m;
00375
00376 static const string minComponentCodim_ConstString_m;
00377
00378 static const string randomCounterStartValue_ConstString_m;
00379
00380 static const string HamiltonianComponentSwitch_ConstString_m;
00381
00382 static const string logExtendedLiftStatistic_ConstString_m;
00383
00384 static const string pureSmothnessTest_ConstString_m;
00385
00386
00387 static const string checkpointInterval_ConstString_m;
00388
00389 static const string pointFilter_ConstString_m;
00390 static const string pointFilterStrategy_ConstString_m;
00391
00392
00393 private:
00394
00395 bool bWriteToCout_m;
00396
00400 long64 randomCounterStartValue_m;
00401
00402 bool bShowProgress_m;
00403 string inputFileString_m;
00404 bool bLocking_m;
00405 bool positionInLValue_m;
00406
00407 bool bNonSmoothPointPassFilter_m;
00408 bool firstPQ_m;
00409
00410 int braceLevel_m;
00411
00412 int checkpointInterval_m;
00413
00414 bool parameterNameExpected_m;
00415
00416 mutable ofstream os_m;
00417
00418 TRing * ringEps_m ;
00419
00420 string outputFileName_m;
00421
00422 long64 pointID_m;
00423
00424 list<CoeffListEntry> coeffVariablesOrder_m;
00425
00429 Parameterlist* paramList_m;
00430
00431
00432 int epsPrecision_m;
00433 int fieldCharacteristic_m;
00434
00435 int maxDegree;
00436 int maxFocalValuesToCompute_m;
00437
00438 int gradderpolynome_m;
00439
00440
00441
00442 istream* inputFile_m;
00443
00444 bool inputFromStd_m;
00445 int progressStepWidth_m;
00446
00447 bool bMultipleExperimentsInAFile_m;
00448
00449 string experimentTag_m;
00450 string experimentTagNoWS_m;
00451
00452 bool bPureSmoothnessTest_m;
00453
00454
00458 int maxLift_m;
00459
00460 int liftTrials_m;
00461
00462 int exhaustiveMaxLift_m;
00463
00464 int exhaustiveLiftTrials_m;
00465
00466
00467 int requestedLiftPointNum_m;
00468
00474 long64 azZufallszahlen_m;
00475 bool randomSeedFromSysTime_m ;
00476 mutable long randomSeed_m;
00477
00478 bool benutzeFormel_1_m;
00479 bool benutzeFormel_2_m;
00480 bool benutzeFormel_23_m;
00481 int HamiltonianComponentSwitch_m;
00482
00483 int minComponentCodim_m;
00484
00490 int reqFullJacobianMinRank_m;
00491 int reqSubJacobianMinRank_m;
00492
00493 int bReqVanishedFocalValues_m;
00494
00495 CFPointFilter* pointFilter;
00496
00499 bool bLogExtendedLiftStatistic_m;
00500
00501 string lockFileName_m;
00502 bool bHasVariableCoefficients_m;
00503 bool bAllConstCoefficientsAreVariables_m;
00504
00508
00509 bool containsMonomsWithAllCoefficientsCheck_m;
00510 bool containsMonomsWithRandomCoefficients_m;
00511
00513
00514
00515 TPolynomXY* infEps_minusP_polynom_m;
00516 TPolynomXY* infEps_Q_polynom_m;
00517
00518
00519 CoeffList monomsWithAllCoefficients_m;
00520 CoeffList monomsWithRandomCoefficients_m;
00521
00522
00523
00524
00525
00529 public:
00530
00532 int getCheckpointInterval() const{ return checkpointInterval_m; }
00537 int getMaxLift() const { return maxLift_m; }
00538
00539 int getLiftTrials() const { return liftTrials_m; }
00540 int getExhaustiveMaxLift() const { return exhaustiveMaxLift_m; }
00541
00542 int getExhaustiveLiftTrials() const { return exhaustiveLiftTrials_m; }
00543
00544
00545 int getRequestedLiftPointNum() const { return requestedLiftPointNum_m; }
00546
00552 inline long64 getRequestedTrialsNum() const { return azZufallszahlen_m; }
00553
00554 inline long & getRandomSeedRef() const { return randomSeed_m; }
00555
00556 inline long * getRandomSeedPtr() const { return & randomSeed_m; }
00557
00559 inline bool bInitRandomFromTime() const { return randomSeedFromSysTime_m; }
00560
00561 inline bool useFormula1() const { return benutzeFormel_1_m; }
00562
00563 inline bool useFormula2() const { return benutzeFormel_2_m; }
00564 inline bool useFormula23() const { return benutzeFormel_23_m; }
00565
00566 long64 getRandomCounterStartValue() const { return randomCounterStartValue_m; }
00567
00568 inline int getParametrizedFocalValuesNum() const
00569 {
00570 if (useFormula23() && useFormula1() && !useFormula2() )
00571 return 3;
00572 else if (useFormula2() && useFormula1() && !useFormula23() )
00573 return 2;
00574 else if (useFormula1() && !useFormula23() && !useFormula2() )
00575 return 1;
00576 else if (!useFormula1() && !useFormula23() && !useFormula2() )
00577 return 0;
00578 else
00579 {
00580 std::cerr << "Error: formula combination { formula1=" << useFormula1()<< " and formula2=" << useFormula2() << " and formula23=" << useFormula23() << "} not allowed!" << std::endl;
00581 exit(0);
00582 }
00583 }
00584
00590 inline int getHamiltonianComponentSwitch() const { return HamiltonianComponentSwitch_m; }
00591
00593 inline unsigned int getRequiredFullJacobianMinRank() const { return reqFullJacobianMinRank_m; }
00594
00596 inline unsigned int getRequiredSubJacobianMinRank() const { return reqSubJacobianMinRank_m; }
00597
00598 inline int requiredVanishedFocalValuesNum() const { return bReqVanishedFocalValues_m; }
00599
00600 unsigned int getMinComponentCodim() const { return minComponentCodim_m; }
00601
00602
00603
00604
00605
00606 bool nonSmoothPointPassFilter() const { return bNonSmoothPointPassFilter_m; }
00607
00612 inline int getEpsPrecision() const { return epsPrecision_m; }
00613
00614 inline int getFieldCharacteristic() const { return fieldCharacteristic_m; }
00615
00616 inline int getMaxFocalValuesToCompute() const { return maxFocalValuesToCompute_m; }
00617
00618 inline int getPolynomialDegree() const { return gradderpolynome_m; }
00619
00620 inline string getExperimentTag() const { return experimentTag_m; }
00621 inline string getExperimentTagNoWS() const { return experimentTagNoWS_m; }
00622
00624 inline bool inputFromStd() const { return inputFromStd_m; }
00625
00626
00627
00628 inline string getOutputFileName() const { return outputFileName_m; }
00629
00631 inline bool showProgress() const { return bShowProgress_m; }
00632
00633 int getProgressStepWidth() const { return progressStepWidth_m ; };
00634
00635 long64 getPointID() const { return pointID_m; };
00636
00637
00638 bool pureSmoothnessTest() const { return bPureSmoothnessTest_m; }
00639
00642 bool writeResultToCout() const {return bWriteToCout_m; };
00643
00647 int getMaxComputableFocalValues() const
00648 {
00649 assert(fieldCharacteristic_m>2);
00650 return (fieldCharacteristic_m-3)/2;
00651 }
00652
00653 long64 getCoeffTryRandom() const;
00654
00655 long64 getCoeffTryAll() const ;
00656
00657 inline Parameterlist const * getParameterList() { return paramList_m; }
00658
00659 bool isCoefficientVariable (int x_exp, int y_exp, P_or_QPolynom p_or_q ) const;
00660 bool isCoefficientVariable (const CoeffListEntry & coeffEntry) const;
00661 bool isRandomVariable (const CoeffListEntry & coeffEntry) const;
00662
00663 bool allConstCoefficientsAreVariables() const { return bAllConstCoefficientsAreVariables_m; }
00664
00665 bool hasVariableCoefficients() const { return bHasVariableCoefficients_m; }
00666
00667 inline const CoeffList & getMonomsWithRandomCoefficients() const { return monomsWithRandomCoefficients_m; }
00668
00669 inline const CoeffList & getMonomsWithAllCoefficients() const { return monomsWithAllCoefficients_m; }
00670
00671 inline bool polynomsHaveRandomCoeff() const { return containsMonomsWithRandomCoefficients_m; }
00672
00673 inline bool polynomsHaveCheckAllCoeff() const { return containsMonomsWithAllCoefficientsCheck_m; }
00674
00675 inline bool logExtendedLiftStatistic() const { return bLogExtendedLiftStatistic_m; }
00676
00677 inline bool polynomsContainsVariableCoeff() const
00678 {
00679 return containsMonomsWithRandomCoefficients_m || containsMonomsWithAllCoefficientsCheck_m ;
00680 };
00681
00682 bool pointPassedFilter( uint16_t exactVanishedFocalValues,
00683 uint16_t jacobianRank,
00684 bool smooth,
00685 uint16_t quadricsRank) const
00686 {
00687
00688 return pointFilter->pointPassedFilter(exactVanishedFocalValues,jacobianRank, smooth,quadricsRank);
00689
00690 }
00691
00693 inline int getPDFCoefficientNum() const
00694 {
00695
00696
00697 return (getPolynomialDegree() + 1 )*( getPolynomialDegree() + 2 ) - 6 ;
00698
00699 }
00700
00708 const list<CoeffListEntry> getCoeffVariablesOrder() const
00709 {
00710 return coeffVariablesOrder_m;
00711 }
00712
00713
00714 void printParameters(ostream &oFile) const;
00715
00716
00717
00718
00719
00720
00723 CenterfocusParams( const int argc, const char * const argv[] );
00724
00728 ofstream& getOsRef() const { return os_m; }
00729
00730
00731 const TRing * getRing() const { return ringEps_m ; }
00732
00733 const TRing & getRingRef() const { return *ringEps_m ; }
00734
00735
00736 TPolynomXY const * getMinusPPolynom() const { return infEps_minusP_polynom_m; }
00737 TPolynomXY const * getQPolynom() const { return infEps_Q_polynom_m; }
00738
00739 TPolynomXY const & getMinusPPolynomRef() const { return *infEps_minusP_polynom_m; }
00740 TPolynomXY const & getQPolynomRef() const { return *infEps_Q_polynom_m; }
00741
00742
00743 bool areWellDefined();
00744
00745
00746 private:
00749 void init();
00750
00751 void setupOutputFile(const int argc, const char * const argv[]);
00752
00753 void initExperimentTag() ;
00754
00755 void initPolynomialDegree();
00756 void initFieldCharacteristic();
00757
00758
00759 void initHamiltonianComponentSwitch();
00760 void initHasVariableCoefficients();
00761
00762 void initRandomSeed();
00763
00764 void initCoeffVariablesOrder();
00765
00766 void initPointFilter();
00767
00768
00771 long64 getCoeffTry(const CoeffList & coefflist) const;
00772
00775 void checkParameters() const;
00781 void loadParamList( istream &fileInStream);
00782 void loadParamList( string inputFile_);
00783 void loadParamListFromString(const char * inputParameters);
00784
00785 bool initBoolParameter(string name, bool & internParameter, int printOrder);
00786
00787 template <class TInternParameter>
00788 bool initNonNegativeIntParameter(string name, TInternParameter & internParameter, int printOrder);
00794 void convertStringParamsToOptions();
00799
00802
00803
00804
00805
00806
00807
00808
00809
00810 public:
00811 bool readNextPolynoms();
00812 string readLParameter();
00813
00814 private:
00815
00816 void readMonomGroup( TRing * ring1,
00817 TPolynomXY &pol,
00818 string &monomGroup,
00819 int momomGroupDegree,
00820 P_or_QPolynom p_or_q );
00821
00822
00823 void updatePolynom( TRing* ring1,
00824 TPolynomXY &pol,
00825 stringstream &polynomStream,
00826 P_or_QPolynom p_or_q );
00827
00828
00829 void updatePolynoms( stringstream & polynomData, TRing* ring1 );
00830
00831 void updatePolynomsFromDifferentialForm(string differentialFormString);
00832
00835 public:
00836
00837
00838 void initAllCoeffitientsAreVariables();
00839
00840 ~CenterfocusParams()
00841 {
00842 delete infEps_minusP_polynom_m; infEps_minusP_polynom_m=NULL;
00843 delete infEps_Q_polynom_m; infEps_Q_polynom_m=NULL;
00844
00845 delete paramList_m; paramList_m=NULL;
00846 delete inputFile_m; inputFile_m=NULL;
00847 delete ringEps_m; ringEps_m=NULL;
00848
00849 }
00850
00851
00852
00853
00854 };
00855
00856 #include "ReadCenterFocusParams.cpp"
00857
00858 }
00859
00860
00861
00862
00863 #endif