GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
/*1* Normaliz2* Copyright (C) 2007-2014 Winfried Bruns, Bogdan Ichim, Christof Soeger3* This program is free software: you can redistribute it and/or modify4* it under the terms of the GNU General Public License as published by5* the Free Software Foundation, either version 3 of the License, or6* (at your option) any later version.7*8* This program is distributed in the hope that it will be useful,9* but WITHOUT ANY WARRANTY; without even the implied warranty of10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11* GNU General Public License for more details.12*13* You should have received a copy of the GNU General Public License14* along with this program. If not, see <http://www.gnu.org/licenses/>.15*16* As an exception, when this program is distributed through (i) the App Store17* by Apple Inc.; (ii) the Mac App Store by Apple Inc.; or (iii) Google Play18* by Google Inc., then that store may impose any digital rights management,19* device limits and/or redistribution restrictions that are required by its20* terms of service.21*/2223#include <stdlib.h>24#include <vector>25#include <list>26#include <string>27#include <sstream>28#include <algorithm>29using namespace std;3031#include "libnormaliz/libnormaliz.h"32#include "libnormaliz/cone.h"33using namespace libnormaliz;3435#include "normaliz.h"36#include "options.h"37#include "output.h"383940OptionsHandler::OptionsHandler() {41project_name_set = false;42output_dir_set=false;43write_extra_files = false, write_all_files = false;44// use_Big_Integer = false;45use_long_long = false;46ignoreInFileOpt = false;47nr_threads = 0;48no_ext_rays_output=false;49}505152bool OptionsHandler::handle_commandline(int argc, char* argv[]) {53vector<string> LongOptions;54string ShortOptions; //all options concatenated (including -)55// read command line options56for (int i = 1; i < argc; i++) {57if (argv[i][0] == '-') {58if (argv[i][1] != '\0') {59if (argv[i][1] != 'x') {60if (argv[i][1] == '-') {61string LO = argv[i];62LO.erase(0, 2);63LongOptions.push_back(LO);64} else65ShortOptions = ShortOptions + argv[i];66} else if (argv[i][2] == '=') {67#ifdef _OPENMP68string Threads = argv[i];69Threads.erase(0,3);70if ( (istringstream(Threads) >> nr_threads) && nr_threads >= 0) {71set_thread_limit(nr_threads);72// omp_set_num_threads(nr_threads); -- now in cone.cpp73} else {74cerr<<"Error: Invalid option string "<<argv[i]<<endl;75exit(1);76}77#else78cerr << "Warning: Compiled without OpenMP support, option "79<< argv[i] << " ignored." << endl;80#endif81} else {82cerr << "Error: Invalid option string " << argv[i] << endl;83exit(1);84}85}86} else {87setProjectName(argv[i]);88}89}90return handle_options(LongOptions, ShortOptions);91}9293void OptionsHandler::setProjectName(const string& s) {94if (project_name_set) {95cerr << "Error: Second project name " << s << " in command line!" << endl;96exit(1);97}98project_name = s;99// check if we can read the .in file100string name_in= project_name+".in";101const char* file_in=name_in.c_str();102ifstream in2;103in2.open(file_in,ifstream::in);104if (in2.is_open()==false) {105//check if user added ".in" and ignore it in this case106string suffix (".in");107size_t found = project_name.rfind(suffix);108if (found!=string::npos) {109project_name.erase(found);110}111} else {112in2.close();113}114project_name_set = true;115}116117void OptionsHandler::setOutputDirName(const string& s) {118output_dir=s;119char slash='/';120#ifdef _WIN32 //for 32 and 64 bit windows121slash='\\';122#endif123if(output_dir[output_dir.size()-1]!=slash)124output_dir+=slash;125output_dir_set=true;126}127128bool OptionsHandler::handle_options(vector<string>& LongOptions, string& ShortOptions) {129//Analyzing short command line options130for (size_t i = 1; i <ShortOptions.size(); i++) {131switch (ShortOptions[i]) {132case '-':133break;134case 'c':135verbose=true;136break;137case 'f':138write_extra_files = true;139break;140case 'a':141write_all_files = true;142break;143case 'T':144to_compute.set(ConeProperty::Triangulation);145// to_compute.set(ConeProperty::Multiplicity);146break;147case 's':148to_compute.set(ConeProperty::SupportHyperplanes);149break;150case 'S':151to_compute.set(ConeProperty::Sublattice);152break;153case 't':154to_compute.set(ConeProperty::TriangulationSize);155break;156case 'v':157to_compute.set(ConeProperty::Multiplicity);158break;159case 'n':160to_compute.set(ConeProperty::HilbertBasis);161to_compute.set(ConeProperty::Multiplicity);162break;163case 'N':164to_compute.set(ConeProperty::HilbertBasis);165break;166case 'w':167to_compute.set(ConeProperty::IsIntegrallyClosed);168break;169case '1':170to_compute.set(ConeProperty::Deg1Elements);171break;172case 'q':173to_compute.set(ConeProperty::HilbertSeries);174break;175case 'p':176to_compute.set(ConeProperty::HilbertSeries);177to_compute.set(ConeProperty::Deg1Elements);178break;179case 'h':180to_compute.set(ConeProperty::HilbertBasis);181to_compute.set(ConeProperty::HilbertSeries);182break;183case 'y':184to_compute.set(ConeProperty::StanleyDec);185break;186case 'd':187to_compute.set(ConeProperty::DualMode);188break;189case 'r':190to_compute.set(ConeProperty::Approximate);191break;192case 'e': //check for arithmetic overflow193// test_arithmetic_overflow=true;194cerr << "WARNING: deprecated option -e is ignored." << endl;195break;196case 'B': //use Big Integer197to_compute.set(ConeProperty::BigInt); // use_Big_Integer=true;198break;199case 'b': //use the bottom decomposition for the triangulation200to_compute.set(ConeProperty::BottomDecomposition);201break;202case 'C': //compute the class group203to_compute.set(ConeProperty::ClassGroup);204break;205case 'k': //keep the order of the generators in Full_Cone206to_compute.set(ConeProperty::KeepOrder);207break;208case 'o': //suppress bottom decomposition in Full_Cone209to_compute.set(ConeProperty::NoBottomDec);210break;211case 'M': // compute minimal system of generators of integral closure212// as a module over original monoid213to_compute.set(ConeProperty::ModuleGeneratorsOverOriginalMonoid);214break;215case '?': //print help text and exit216return true;217break;218case 'x': //should be separated from other options219cerr<<"Error: Option -x=<T> has to be separated from other options"<<endl;220exit(1);221break;222case 'I':223to_compute.set(ConeProperty::Integral);224break;225case 'L':226to_compute.set(ConeProperty::VirtualMultiplicity);227break;228case 'E':229to_compute.set(ConeProperty::WeightedEhrhartSeries);230break;231case 'i':232ignoreInFileOpt=true;233break;234case 'H':235to_compute.set(ConeProperty::IntegerHull);236break;237case 'D':238to_compute.set(ConeProperty::ConeDecomposition);239break;240case 'P':241to_compute.set(ConeProperty::PrimalMode);242break;243case 'Y':244to_compute.set(ConeProperty::Symmetrize);245break;246case 'X':247to_compute.set(ConeProperty::NoSymmetrization);248break;249case 'G':250to_compute.set(ConeProperty::IsGorenstein);251break;252case 'j':253to_compute.set(ConeProperty::Projection);254break;255case 'J':256to_compute.set(ConeProperty::ProjectionFloat);257break;258default:259cerr<<"Error: Unknown option -"<<ShortOptions[i]<<endl;260exit(1);261break;262}263}264265// Remember to update also the --help text and the documentation when changing this!266vector<string> AdmissibleOut;267string AdmissibleOutarray[]={"gen","cst","inv","ext","ht1","esp","egn","typ","lat","msp","mod"}; // "mod" must be last268for(size_t i=0;i<11;++i)269AdmissibleOut.push_back(AdmissibleOutarray[i]);270assert(AdmissibleOut.back()=="mod");271272// analyzing long options273for(size_t i=0; i<LongOptions.size();++i){274size_t j;275for(j=0;j<LongOptions[i].size();++j){276if(LongOptions[i][j]=='=')277break;278}279if(j<LongOptions[i].size()){280string OptName=LongOptions[i].substr(0,j);281string OptValue=LongOptions[i].substr(j+1,LongOptions[i].size()-1);282if(OptName=="OutputDir"){283setOutputDirName(OptValue);284continue;285}286}287if(LongOptions[i]=="help"){288return true; // indicate printing of help text289}290if(LongOptions[i]=="verbose"){291verbose=true;292continue;293}294if(LongOptions[i]=="version"){295printVersion();296exit(0);297}298/* if(LongOptions[i]=="BigInt"){299use_Big_Integer=true;300continue;301}*/302if(LongOptions[i]=="LongLong"){303use_long_long=true;304continue;305}306if(LongOptions[i]=="NoExtRaysOutput"){307no_ext_rays_output=true;308continue;309}310if(LongOptions[i]=="ignore"){311ignoreInFileOpt=true;312continue;313}314if(LongOptions[i]=="files"){315write_extra_files = true;316continue;317}318if(LongOptions[i]=="all-files"){319write_all_files = true;320continue;321}322if(find(AdmissibleOut.begin(),AdmissibleOut.end(),LongOptions[i])!=AdmissibleOut.end()){323OutFiles.push_back(LongOptions[i]);324continue;325}326try {327to_compute.set(toConeProperty(LongOptions[i]));328continue;329} catch (const BadInputException& ) {};330cerr << "Error: Unknown option --" << LongOptions[i] << endl;331exit(1);332}333334if(output_dir_set){335output_file=output_dir+pureName(project_name);336}337else338output_file=project_name;339340341342return false; //no need to print help text343}344345template<typename Integer>346void OptionsHandler::applyOutputOptions(Output<Integer>& Out) {347if(no_ext_rays_output)348Out.set_no_ext_rays_output();349if(write_all_files) {350Out.set_write_all_files();351} else if (write_extra_files) {352Out.set_write_extra_files();353}354if (to_compute.test(ConeProperty::Triangulation) || to_compute.test(ConeProperty::ConeDecomposition)) {355Out.set_write_tri(true);356Out.set_write_tgn(true);357Out.set_write_inv(true);358}359if (to_compute.test(ConeProperty::StanleyDec)) {360Out.set_write_dec(true);361Out.set_write_tgn(true);362Out.set_write_inv(true);363}364for(size_t i=0;i<OutFiles.size();++i){365if(OutFiles[i]=="gen"){366Out.set_write_gen(true);367continue;368}369if(OutFiles[i]=="cst"){370Out.set_write_cst(true);371continue;372}373if(OutFiles[i]=="inv"){374Out.set_write_inv(true);375continue;376}377if(OutFiles[i]=="ht1"){378Out.set_write_ht1(true);379continue;380}381if(OutFiles[i]=="ext"){382Out.set_write_ext(true);383continue;384}385if(OutFiles[i]=="egn"){386Out.set_write_egn(true);387continue;388}389if(OutFiles[i]=="esp"){390Out.set_write_esp(true);391continue;392}393if(OutFiles[i]=="typ"){394Out.set_write_typ(true);395continue;396}397if(OutFiles[i]=="lat"){398Out.set_write_lat(true);399continue;400}401if(OutFiles[i]=="msp"){402Out.set_write_msp(true);403continue;404}405if(OutFiles[i]=="mod"){406Out.set_write_mod(true);407continue;408}409}410411if (!project_name_set) {412cerr << "ERROR: No project name set!" << endl;413exit(1);414}415Out.set_name(output_file);416}417418bool OptionsHandler::activateDefaultMode() {419if (to_compute.goals().none() && !to_compute.test(ConeProperty::DualMode)420&& !to_compute.test(ConeProperty::Approximate)421&& !to_compute.test(ConeProperty::ProjectionFloat)422&& !to_compute.test(ConeProperty::Projection) ) {423to_compute.set(ConeProperty::DefaultMode);424return true;425}426return false;427}428429string pureName(const string& fullName){430// extracts the pure filename431432string slash="/";433#ifdef _WIN32 //for 32 and 64 bit windows434slash="\\";435#endif436size_t found = fullName.rfind(slash);437if(found==std::string::npos)438return(fullName);439found++;440size_t length=fullName.size()-found;441442// cout << "**************************** " << fullName.substr(found,length) << endl;443// exit(1);444return(fullName.substr(found,length));445446}447448449