[mathicgb] 113/393: Made two separate actions gb and siggb for classic and signature grobner basis computation respectively.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Fri Apr 3 15:58:43 UTC 2015


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to branch upstream
in repository mathicgb.

commit 399c07b89e6b52f8a420d74cbac7bdf4de5a312a
Author: Bjarke Hammersholt Roune <bjarkehr.code at gmail.com>
Date:   Fri Nov 16 14:08:51 2012 +0100

    Made two separate actions gb and siggb for classic and signature grobner basis computation respectively.
---
 build/vs12/mathicgb-exe/mathicgb-exe.vcxproj       |   8 +
 .../vs12/mathicgb-exe/mathicgb-exe.vcxproj.filters |  20 ++
 build/vs12/mathicgb.sln                            |   3 -
 src/cli/GBMain.cpp                                 | 364 ++-------------------
 src/mathicgb/BjarkeGeobucket2.cpp                  |  10 +-
 src/mathicgb/BuchbergerAlg.hpp                     |   4 +-
 src/mathicgb/PolyRing.cpp                          |   6 +-
 7 files changed, 61 insertions(+), 354 deletions(-)

diff --git a/build/vs12/mathicgb-exe/mathicgb-exe.vcxproj b/build/vs12/mathicgb-exe/mathicgb-exe.vcxproj
index 97f294c..dc8095d 100755
--- a/build/vs12/mathicgb-exe/mathicgb-exe.vcxproj
+++ b/build/vs12/mathicgb-exe/mathicgb-exe.vcxproj
@@ -43,7 +43,10 @@
     </ProjectConfiguration>
   </ItemGroup>
   <ItemGroup>
+    <ClCompile Include="..\..\..\src\cli\GBAction.cpp" />
+    <ClCompile Include="..\..\..\src\cli\GBCommonParams.cpp" />
     <ClCompile Include="..\..\..\src\cli\GBMain.cpp" />
+    <ClCompile Include="..\..\..\src\cli\SigGBAction.cpp" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\..\..\..\mathic\build\vs12\mathic-lib\mathic-lib.vcxproj">
@@ -56,6 +59,11 @@
       <Project>{0928155f-aee7-4b28-ad10-ff7d6488d232}</Project>
     </ProjectReference>
   </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="..\..\..\src\cli\GBAction.hpp" />
+    <ClInclude Include="..\..\..\src\cli\GBCommonParams.hpp" />
+    <ClInclude Include="..\..\..\src\cli\SigGBAction.hpp" />
+  </ItemGroup>
   <PropertyGroup Label="Globals">
     <ProjectGuid>{1CCEB690-2F15-4D60-AF28-2F0AC260E685}</ProjectGuid>
     <Keyword>Win32Proj</Keyword>
diff --git a/build/vs12/mathicgb-exe/mathicgb-exe.vcxproj.filters b/build/vs12/mathicgb-exe/mathicgb-exe.vcxproj.filters
index f89b070..c8ac080 100755
--- a/build/vs12/mathicgb-exe/mathicgb-exe.vcxproj.filters
+++ b/build/vs12/mathicgb-exe/mathicgb-exe.vcxproj.filters
@@ -18,5 +18,25 @@
     <ClCompile Include="..\..\..\src\cli\GBMain.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\..\src\cli\GBCommonParams.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\src\cli\GBAction.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\src\cli\SigGBAction.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="..\..\..\src\cli\GBCommonParams.hpp">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\..\src\cli\GBAction.hpp">
+      <Filter>Source Files</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\..\src\cli\SigGBAction.hpp">
+      <Filter>Source Files</Filter>
+    </ClInclude>
   </ItemGroup>
 </Project>
\ No newline at end of file
diff --git a/build/vs12/mathicgb.sln b/build/vs12/mathicgb.sln
index ad9225a..8a6a242 100755
--- a/build/vs12/mathicgb.sln
+++ b/build/vs12/mathicgb.sln
@@ -139,7 +139,4 @@ Global
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
 	EndGlobalSection
-	GlobalSection(Performance) = preSolution
-		HasPerformanceSessions = true
-	EndGlobalSection
 EndGlobal
diff --git a/src/cli/GBMain.cpp b/src/cli/GBMain.cpp
index 6a07d83..6725956 100755
--- a/src/cli/GBMain.cpp
+++ b/src/cli/GBMain.cpp
@@ -1,354 +1,34 @@
 #include "mathicgb/stdinc.h"
 
-#include "mathicgb/Ideal.hpp"
-#include "mathicgb/SignatureGB.hpp"
-#include "mathicgb/BuchbergerAlg.hpp"
-#include "mathicgb/io-util.hpp"
-#include "mathicgb/MTArray.hpp"
-
+#include "GBAction.hpp"
+#include "SigGBAction.hpp"
 #include <mathic.h>
-#include <tbb/tbb.h>
-#include <cstdlib>
-#include <fstream>
-#include <iostream>
-#include <istream>
 #include <cctype>
-
-class CliActionSignature : public mic::Action {
-public:
-  CliActionSignature():
-    mUseSingularCriterionEarly("earlySingularCriterion",
-      "Apply the singular S-pair elimination criterion before queueing "
-      "that S-pair. Otherwise, the criterion is only checked just before "
-      "the S-pair would otherwise cause a polynomial reduction to occur. "
-      "This criterion is only relevant to the signature Buchberger "
-      "algorithm.",
-      false),
-
-    mPreferSparseReducers("preferSparseReducers",
-      "If true, always use the sparsest reducer in polynomial reduction. "
-      "This option impacts both classic and signature constrained "
-      "polynomial reduction. Ties are broken by taking the oldest reducer. "
-      "If this option is false, the oldest reducer is always used.",
-      true),
-
-    mAutoTailReduce("autoTailReduce",
-      "Reduce the non-leading terms of all polynomials whenever an element "
-      "is inserted into the basis. Only relevant to the "
-      "classic Buchberger algorithm.",
-      false),
-
-    mAutoTopReduce("autoTopReduce",
-      "Reduce any basis element whose lead term becomes reducible "
-      "by a different basis element. Only relevant to the "
-      "classic Buchberger algorithm.",
-      true),
-
-    mClassicBuchbergerAlgorithm("classicBuchbergerAlgorithm",
-      "Use the classic buchberger algorithm. If true, ignore "
-      "any options having to do with signatures or the signature "
-      "algorithm.",
-      false),
-
-    mPostponeKoszul("postponeKoszul",
-      "Postpone the construction of Koszul syzygy signatures.",
-      true),
-
-    mUseBaseDivisors("useBaseDivisors",
-      "Use high ratio and low ratio base divisors to eliminate "
-      "S-spairs quickly based on signature.",
-      true),
-
-    mSPairQueue("spairQueue",
-      "The priority queue used to order S-pairs.\n"
-      "  0   tournament tree in front of triangle\n"
-      "  1   heap in front of triangle\n"
-      "  2   tournament tree\n"
-      "  3   heap\n",
-      0),
-
-    mTracingLevel("tracingLevel",
-      "How much information to print out about actions taken. Nothing "
-      "extra is printed if the value is zero. Higher values "
-      "result in more information.",
-      0),
-
-    mBreakAfter("breakAfter",
-      "Stop the computation after this many elements have been added to "
-      "the basis. The computation runs uninterrupted if the value is zero.",
-      0),
-
-    mPrintInterval("printInterval",
-      "Print information about the computation every time this many S-pair "
-      "reductions have been performed. Do not print information like this "
-      "during the computation if the value is zero.",
-      0),
-
-    mMonomialTable("monomialTable",
-      "The kind of monomial table data structure to use.\n",
-      2),
-
-    mDivisorLookup("divisorLookup",
-      "The divisor lookup data structure to use.\n",
-      2),
-
-    mReducer("reducer",
-      "The data structure to use for polynomial reduction.\n",
-      4),
-
-    mModuleOrder("moduleOrder",
-      "The free module term order.\n",
-      4),
-
-    mProjectName("projectName",
-      "For a value X, read the input ideal from X.ideal, "
-      "write statistics to X.stats and write the output to X.gb",
-      ""),
-
-    mStrategy("strategy",
-      "The integer representing the strategy to use for the computation:\n"
-      "  0   signature+gbstop\n"
-      "  1   buchberger\n"
-      "  2   late koszul\n"
-      "  4   not used (used to be MES reduction)\n"
-      "  8   signature\n",
-     2),
-
-    mSPairGroupSize("sPairGroupSize",
-      "Specifies how many S-pair to reduce at one time. A value of 0 "
-      "indicates not to group S-pairs together. Only currently relevant "
-      "for the classic Buchberger algorithm.",
-     0),
-
-    mThreadCount("threadCount",
-      "Specifies how many threads to use to run the program in parallel.",
-     1),
-
-    mMemoryQuantum("memoryQuantumForReducer",
-      "Specifies how many items to allocate memory for at a time for the reducer.",
-      1024 * 1024)
-
-  {
-    {
-      std::ostringstream orderOut;
-      FreeModuleOrder::displayOrderTypes(orderOut);
-      mModuleOrder.appendToDescription(orderOut.str());
-    }
-    {
-      std::ostringstream reducerOut;
-      Reducer::displayReducerTypes(reducerOut);
-      mReducer.appendToDescription(reducerOut.str());
-    }
-    {
-      std::ostringstream divisorLookupOut;
-      DivisorLookup::displayDivisorLookupTypes(divisorLookupOut);
-      mDivisorLookup.appendToDescription(divisorLookupOut.str());
-    }
-    {
-      std::ostringstream monomialTableOut;
-      MonomialTableArray::displayMTTypes(monomialTableOut);
-      mMonomialTable.appendToDescription(monomialTableOut.str());
-    }
-  }
-
-  virtual ~CliActionSignature() {}
-
-  virtual void directOptions(
-    std::vector<std::string> tokens,
-    mic::CliParser& parser
-  ) {
-    switch (tokens.size()) {
-    case 8: mStrategy.processArgument(tokens[6]);
-      mClassicBuchbergerAlgorithm.setValue((mStrategy.value() &  1) == 1);
-      mPostponeKoszul.setValue((mStrategy.value() &  2) != 0);
-      mUseBaseDivisors.setValue((mStrategy.value() & 16) != 0);
-    case 7: mTracingLevel.processArgument(tokens[5]);
-    case 6: // ignore this value
-    case 5: mMonomialTable.processArgument(tokens[3]);
-    case 4: mDivisorLookup.processArgument(tokens[2]);
-    case 3: mReducer.processArgument(tokens[1]);
-    case 2: mModuleOrder.processArgument(tokens[0]);
-    case 1: mProjectName.processArgument(tokens.back());
-    case 0: break;
-    default: mic::reportError
-      (std::string("Too many direct options for action ") + staticName());
-    }
-  }
-
-  virtual void performAction() {
-    tracingLevel = mTracingLevel.value();
-
-    // read input file
-    std::unique_ptr<Ideal> ideal;
-    {
-      std::string const inputIdealFile = mProjectName.value() + ".ideal";
-      std::ifstream inputFile(inputIdealFile.c_str());
-      if (inputFile.fail())
-        mic::reportError("Could not read input file \"" + inputIdealFile + '\n');
-      ideal = Ideal::parse(inputFile);
-    }
-    std::unique_ptr<PolyRing const> ring(&(ideal->ring()));
-
-    const auto threadCount = mThreadCount.value() == 0 ?
-      tbb::task_scheduler_init::automatic :
-      mThreadCount.value();
-    tbb::task_scheduler_init scheduler(threadCount);
-
-    if (mClassicBuchbergerAlgorithm.value()) {
-      BuchbergerAlg alg(
-        *ideal,
-        mModuleOrder.value(),
-        Reducer::ReducerType(mReducer.value()),
-        mDivisorLookup.value(),
-        mPreferSparseReducers.value(),
-        mSPairQueue.value());
-      alg.setBreakAfter(mBreakAfter.value());
-      alg.setThreadCount(mThreadCount.value());
-      alg.setPrintInterval(mPrintInterval.value());
-      alg.setSPairGroupSize(mSPairGroupSize.value());
-      alg.setReducerMemoryQuantum(mMemoryQuantum.value());
-      alg.setUseAutoTopReduction(mAutoTopReduce.value());
-      alg.setUseAutoTailReduction(mAutoTailReduce.value());
-
-      alg.computeGrobnerBasis();
-      alg.printStats(std::cerr);
-
-      /*
-      std::ofstream statsOut((mProjectName.value() + ".stats").c_str());
-      alg.printStats(statsOut);
-      {
-        std::string basisFileName = mProjectName.value() + ".gb";
-        FILE* basisOut = std::fopen(basisFileName.c_str(), "w");
-        output(basisOut, alg.basis());
-      }
-      */
-    } else {
-      SignatureGB alg(
-        *ideal,
-        mModuleOrder.value(),
-        Reducer::reducerType(mReducer.value()),
-        mDivisorLookup.value(),
-        mMonomialTable.value(),
-        mPostponeKoszul.value(),
-        mUseBaseDivisors.value(),
-        mPreferSparseReducers.value(),
-        mUseSingularCriterionEarly.value(),
-        mSPairQueue.value());
-      alg.setBreakAfter(mBreakAfter.value());
-      alg.setPrintInterval(mPrintInterval.value());
-      alg.computeGrobnerBasis();
-
-      // print statistics
-      alg.displayStats(std::cout);
-      alg.displayPaperStats(std::cout);
-
-      {
-        std::ofstream statsOut((mProjectName.value() + ".stats").c_str());
-        alg.displayStats(statsOut);
-        alg.displayPaperStats(statsOut);
-      }
-
-      // print basis
-      {
-        std::ofstream ogb((mProjectName.value() + ".gb").c_str());
-        ogb << "-- gb: ----\n";
-        alg.getGB()->display(ogb);
-      }
-
-      // print syzygy basis
-      {
-        std::ofstream syzygyOut((mProjectName.value() + ".syz").c_str());
-        syzygyOut << "-- syz: ----\n";
-        alg.getSyzTable()->display(syzygyOut, 1);
-        syzygyOut << std::endl;
-      }
-    }
-  }
-
-  static const char* staticName() {return "gb";}
-
-  virtual const char* name() const {return staticName();}
-  virtual const char* description() const {
-    return
-      "Compute a Grobner basis. Takes optional direct parameters in this order:\n"
-      "  <module order> <reducer> <divisor lookup> <monomial table>\n"
-      "  <ignore this value> <trace level> <strategy> <project name>\n"
-      "If fewer than 8 direct parameters, only so many options are read. They "
-      "are read in the order given, except that the the last direct "
-      "parameter, if any, is always assumed to be the project name. "
-      "Parameters given with a dash take priority over direct parameters.";
-  }
-  virtual const char* shortDescription() const {return "Compute a Grobner basis";}
-  
-  virtual void pushBackParameters(std::vector<mic::CliParameter*>& parameters) {
-    parameters.push_back(&mUseSingularCriterionEarly);
-    parameters.push_back(&mPreferSparseReducers);
-    parameters.push_back(&mAutoTailReduce);
-    parameters.push_back(&mAutoTopReduce);
-    parameters.push_back(&mClassicBuchbergerAlgorithm);
-    parameters.push_back(&mPostponeKoszul);
-    parameters.push_back(&mUseBaseDivisors);
-    parameters.push_back(&mSPairQueue);
-    parameters.push_back(&mTracingLevel);
-    parameters.push_back(&mBreakAfter);
-    parameters.push_back(&mPrintInterval);
-    parameters.push_back(&mMonomialTable);
-    parameters.push_back(&mDivisorLookup);
-    parameters.push_back(&mReducer);
-    parameters.push_back(&mModuleOrder);
-    parameters.push_back(&mProjectName);
-    parameters.push_back(&mSPairGroupSize);
-    parameters.push_back(&mThreadCount);
-    parameters.push_back(&mMemoryQuantum);
-
-    // we do not expose the strategy parameter - it is only here to
-    // support the old format of using direct numeric parameters to
-    // the action.
-    // parameters.push_back(&mStrategy);
-  }
-
-private:
-  mic::BoolParameter mUseSingularCriterionEarly;
-  mic::BoolParameter mPreferSparseReducers;
-  mic::BoolParameter mAutoTailReduce;
-  mic::BoolParameter mAutoTopReduce;
-  mic::BoolParameter mClassicBuchbergerAlgorithm;
-  mic::BoolParameter mPostponeKoszul;
-  mic::BoolParameter mUseBaseDivisors;
-  mic::IntegerParameter mSPairQueue;
-  mic::IntegerParameter mTracingLevel;
-  mic::IntegerParameter mBreakAfter;
-  mic::IntegerParameter mPrintInterval;
-  mic::IntegerParameter mMonomialTable;
-  mic::IntegerParameter mDivisorLookup;
-  mic::IntegerParameter mReducer;
-  mic::IntegerParameter mModuleOrder;
-  mic::StringParameter mProjectName;
-  mic::IntegerParameter mStrategy;
-  mic::IntegerParameter mSPairGroupSize;
-  mic::IntegerParameter mThreadCount;
-  mic::IntegerParameter mMemoryQuantum;
-};
+#include <iostream>
+#include <exception>
 
 int main(int argc, char **argv) {
   try {
-    mic::CliParser parser;
-    parser.registerAction<CliActionSignature>();
-    parser.registerAction<mic::HelpAction>();
+    mathic::CliParser parser;
+    parser.registerAction<SigGBAction>();
+    parser.registerAction<GBAction>();
+    parser.registerAction<mathic::HelpAction>();
+
     std::vector<std::string> commandLine(argv, argv + argc);
-    if (commandLine.size() >= 2 &&
-      !commandLine[1].empty() &&
-      std::isdigit(commandLine[1][0])) {
-      commandLine[0] = "gb";
-    } else
-      commandLine.erase(commandLine.begin());
-    // todo: remove the .release once parser returns unique_ptr
-    // instead of auto_ptr.
-    std::unique_ptr<mic::Action> action(parser.parse(commandLine).release());
-    action->performAction();
-  } catch (const mic::MathicException& e) {
-    mic::display(e.what());
+    commandLine.erase(commandLine.begin());
+
+    parser.parse(commandLine)->performAction();
+  } catch (const mathic::MathicException& e) {
+    mathic::display(e.what());
     return -1;
+  } catch (std::exception& e) {
+    mathic::display(e.what());
+    return -1;  
+  } catch (...) {
+    std::cout << "UNKNOWN ERROR" << std::endl;
+    // maybe there is some outer exception handler that might say something
+    // reasonable about this exception, so rethrow the exception.
+    throw;
   }
   return 0;
 };
diff --git a/src/mathicgb/BjarkeGeobucket2.cpp b/src/mathicgb/BjarkeGeobucket2.cpp
index abdc866..5468f74 100755
--- a/src/mathicgb/BjarkeGeobucket2.cpp
+++ b/src/mathicgb/BjarkeGeobucket2.cpp
@@ -38,15 +38,17 @@ void BjarkeGeobucket2::insert(Poly::const_iterator first,
 ///////////////////////////////////////
 void BjarkeGeobucket2::insertTail(const_term multiplier, const Poly *g1)
 {
-  if (g1->nTerms() <= 1) return;
+  MATHICGB_ASSERT(g1 != 0);
+  MATHICGB_ASSERT(g1->termsAreInDescendingOrder());
+
+  if (g1->nTerms() <= 1)
+    return;
 
   HashPoly M;
   mHashTableOLD.insert(multiplier, ++(g1->begin()), g1->end(), M);
 
   if (!M.empty())
-    {
-      mHeap.push(M.begin(),M.end());
-    }
+    mHeap.push(M.begin(),M.end());
 
   stats_n_inserts++;
   stats_n_compares += mHeap.getConfiguration().getComparisons();
diff --git a/src/mathicgb/BuchbergerAlg.hpp b/src/mathicgb/BuchbergerAlg.hpp
index 6500545..583c67d 100755
--- a/src/mathicgb/BuchbergerAlg.hpp
+++ b/src/mathicgb/BuchbergerAlg.hpp
@@ -1,5 +1,5 @@
-#ifndef _buchberger_alg_
-#define _bucbberger_alg_
+#ifndef MATHICGB_BUCHBERGER_ALG_GUARD
+#define MATHICGB_BUCHBERGER_ALG_GUARD
 
 #include "Reducer.hpp"
 #include "FreeModuleOrder.hpp"
diff --git a/src/mathicgb/PolyRing.cpp b/src/mathicgb/PolyRing.cpp
index 2602c02..3b42544 100755
--- a/src/mathicgb/PolyRing.cpp
+++ b/src/mathicgb/PolyRing.cpp
@@ -244,7 +244,7 @@ void PolyRing::monomialParse(std::istream &i,
           e = 1;
           if (isdigit(next))
             i >> e;
-          result[v+1] = e;
+          result[v+1] = static_cast<exponent>(e);
         }
       else if (next == '<')
         {
@@ -658,7 +658,7 @@ PolyRing *PolyRing::read(std::istream &i)
   int mNumVars, mNumWeights;
 
   i >> characInt;
-  charac = characInt;
+  charac = static_cast<exponent>(characInt);
   i >> mNumVars;
   i >> mNumWeights;
   PolyRing* R = new PolyRing(charac, mNumVars, mNumWeights);
@@ -669,7 +669,7 @@ PolyRing *PolyRing::read(std::istream &i)
     exponent a;
     int64 aInt;
     i >> aInt;
-    a = aInt;
+    a = static_cast<exponent>(aInt);
     R->mWeights[j] = -a;
     if (R->mWeights[j] != -1)
       R->mTotalDegreeGradedOnly = false;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mathicgb.git



More information about the debian-science-commits mailing list