Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
| Download
GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
Project: cocalc-sagemath-dev-slelievre
Views: 418346/*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 "libQnormaliz/libQnormaliz.h"32#include "libQnormaliz/Qcone.h"33using namespace libQnormaliz;3435#include "Qnormaliz.h"36#include "Qoptions.h"37#include "Qoutput.h"383940OptionsHandler::OptionsHandler() {41project_name_set = false;42output_dir_set=false;43write_extra_files = false, write_all_files = false;44// use_Big_Number = false;45use_long_long = false;46ignoreInFileOpt = false;47nmzInt_E = false, nmzInt_I = false, nmzInt_L = false;48nr_threads = 0;49nr_threads_explicitly_set=false;50}515253bool OptionsHandler::handle_commandline(int argc, char* argv[]) {54vector<string> LongOptions;55string ShortOptions; //all options concatenated (including -)56// read command line options57for (int i = 1; i < argc; i++) {58if (argv[i][0] == '-') {59if (argv[i][1] != '\0') {60if (argv[i][1] != 'x') {61if (argv[i][1] == '-') {62string LO = argv[i];63LO.erase(0, 2);64LongOptions.push_back(LO);65} else66ShortOptions = ShortOptions + argv[i];67} else if (argv[i][2] == '=') {68#ifdef _OPENMP69string Threads = argv[i];70Threads.erase(0,3);71if ( (istringstream(Threads) >> nr_threads) && nr_threads > 0) {72omp_set_num_threads(nr_threads);73nr_threads_explicitly_set=true;74} else {75cerr<<"Error: Invalid option string "<<argv[i]<<endl;76exit(1);77}78#else79cerr << "Warning: Compiled without OpenMP support, option "80<< argv[i] << " ignored." << endl;81#endif82} else {83cerr << "Error: Invalid option string " << argv[i] << endl;84exit(1);85}86}87} else {88setProjectName(argv[i]);89}90}91return handle_options(LongOptions, ShortOptions);92}9394void OptionsHandler::setProjectName(const string& s) {95if (project_name_set) {96cerr << "Error: Second project name " << s << " in command line!" << endl;97exit(1);98}99project_name = s;100// check if we can read the .in file101string name_in= project_name+".in";102const char* file_in=name_in.c_str();103ifstream in2;104in2.open(file_in,ifstream::in);105if (in2.is_open()==false) {106//check if user added ".in" and ignore it in this case107string suffix (".in");108size_t found = project_name.rfind(suffix);109if (found!=string::npos) {110project_name.erase(found);111}112} else {113in2.close();114}115project_name_set = true;116}117118void OptionsHandler::setOutputDirName(const string& s) {119output_dir=s;120char slash='/';121#ifdef _WIN32 //for 32 and 64 bit windows122slash='\\';123#endif124if(output_dir[output_dir.size()-1]!=slash)125output_dir+=slash;126output_dir_set=true;127}128129bool OptionsHandler::handle_options(vector<string>& LongOptions, string& ShortOptions) {130//Analyzing short command line options131for (size_t i = 1; i <ShortOptions.size(); i++) {132switch (ShortOptions[i]) {133case '-':134break;135case 'c':136verbose=true;137break;138case 'f':139write_extra_files = true;140break;141case 'a':142write_all_files = true;143break;144case 'T':145to_compute.set(ConeProperty::Triangulation);146// to_compute.set(ConeProperty::Multiplicity);147break;148case 's':149to_compute.set(ConeProperty::SupportHyperplanes);150break;151case 'S':152to_compute.set(ConeProperty::Sublattice);153break;154case 't':155to_compute.set(ConeProperty::TriangulationSize);156break;157case 'v':158to_compute.set(ConeProperty::Multiplicity);159break;160case 'n':161to_compute.set(ConeProperty::HilbertBasis);162to_compute.set(ConeProperty::Multiplicity);163break;164case 'N':165to_compute.set(ConeProperty::HilbertBasis);166break;167case 'w':168to_compute.set(ConeProperty::IsIntegrallyClosed);169break;170case '1':171to_compute.set(ConeProperty::Deg1Elements);172break;173case 'q':174to_compute.set(ConeProperty::HilbertSeries);175break;176case 'p':177to_compute.set(ConeProperty::HilbertSeries);178to_compute.set(ConeProperty::Deg1Elements);179break;180case 'h':181to_compute.set(ConeProperty::HilbertBasis);182to_compute.set(ConeProperty::HilbertSeries);183break;184case 'y':185to_compute.set(ConeProperty::StanleyDec);186break;187case 'd':188to_compute.set(ConeProperty::DualMode);189break;190case 'r':191to_compute.set(ConeProperty::Approximate);192break;193case 'e': //check for arithmetic overflow194// test_arithmetic_overflow=true;195cerr << "WARNING: deprecated option -e is ignored." << endl;196break;197case 'B': //use Big Number198to_compute.set(ConeProperty::BigInt); // use_Big_Number=true;199break;200case 'b': //use the bottom decomposition for the triangulation201to_compute.set(ConeProperty::BottomDecomposition);202break;203case 'C': //compute the class group204to_compute.set(ConeProperty::ClassGroup);205break;206case 'k': //keep the order of the generators in Full_Cone207to_compute.set(ConeProperty::KeepOrder);208break;209case 'o': //suppress bottom decomposition in Full_Cone210to_compute.set(ConeProperty::NoBottomDec);211break;212case 'M': // compute minimal system of generators of integral closure213// as a module over original monoid214to_compute.set(ConeProperty::ModuleGeneratorsOverOriginalMonoid);215break;216case '?': //print help text and exit217return true;218break;219case 'x': //should be separated from other options220cerr<<"Error: Option -x=<T> has to be separated from other options"<<endl;221exit(1);222break;223case 'I': //nmzIntegrate -I (integrate)224nmzInt_I = true;225to_compute.set(ConeProperty::Triangulation);226to_compute.set(ConeProperty::Multiplicity);227break;228case 'L': //nmzIntegrate -L (leading term)229nmzInt_L = true;230to_compute.set(ConeProperty::Triangulation);231to_compute.set(ConeProperty::Multiplicity);232break;233case 'E': //nmzIntegrate -E (Ehrhart series)234nmzInt_E = true;235to_compute.set(ConeProperty::StanleyDec);236break;237case 'i':238ignoreInFileOpt=true;239break;240case 'H':241to_compute.set(ConeProperty::NumberHull);242break;243case 'D':244to_compute.set(ConeProperty::ConeDecomposition);245break;246case 'P':247to_compute.set(ConeProperty::PrimalMode);248break;249case 'Y':250to_compute.set(ConeProperty::Symmetrize);251break;252case 'X':253to_compute.set(ConeProperty::NoSymmetrization);254break;255default:256cerr<<"Error: Unknown option -"<<ShortOptions[i]<<endl;257exit(1);258break;259}260}261262// Remember to update also the --help text and the documentation when changing this!263vector<string> AdmissibleOut;264string AdmissibleOutarray[]={"gen","cst","inv","ext","ht1","esp","egn","typ","lat","msp","mod"}; // "mod" must be last265for(size_t i=0;i<11;++i)266AdmissibleOut.push_back(AdmissibleOutarray[i]);267assert(AdmissibleOut.back()=="mod");268269// analyzing long options270for(size_t i=0; i<LongOptions.size();++i){271size_t j;272for(j=0;j<LongOptions[i].size();++j){273if(LongOptions[i][j]=='=')274break;275}276if(j<LongOptions[i].size()){277string OptName=LongOptions[i].substr(0,j);278string OptValue=LongOptions[i].substr(j+1,LongOptions[i].size()-1);279if(OptName=="OutputDir"){280setOutputDirName(OptValue);281continue;282}283}284if(LongOptions[i]=="help"){285return true; // indicate printing of help text286}287if(LongOptions[i]=="verbose"){288verbose=true;289continue;290}291if(LongOptions[i]=="version"){292printVersion();293exit(0);294}295/* if(LongOptions[i]=="BigInt"){296use_Big_Number=true;297continue;298}*/299if(LongOptions[i]=="LongLong"){300use_long_long=true;301continue;302}303if(LongOptions[i]=="ignore"){304ignoreInFileOpt=true;305continue;306}307if(LongOptions[i]=="files"){308write_extra_files = true;309continue;310}311if(LongOptions[i]=="all-files"){312write_all_files = true;313continue;314}315if(find(AdmissibleOut.begin(),AdmissibleOut.end(),LongOptions[i])!=AdmissibleOut.end()){316OutFiles.push_back(LongOptions[i]);317continue;318}319try {320to_compute.set(toConeProperty(LongOptions[i]));321continue;322} catch (const BadInputException& ) {};323cerr << "Error: Unknown option --" << LongOptions[i] << endl;324exit(1);325}326327if(output_dir_set){328output_file=output_dir+pureName(project_name);329}330else331output_file=project_name;332333334335return false; //no need to print help text336}337338template<typename Number>339void OptionsHandler::applyOutputOptions(Output<Number>& Out) {340if(write_all_files) {341Out.set_write_all_files();342} else if (write_extra_files) {343Out.set_write_extra_files();344}345if (to_compute.test(ConeProperty::Triangulation) || to_compute.test(ConeProperty::ConeDecomposition)) {346Out.set_write_tri(true);347Out.set_write_tgn(true);348Out.set_write_inv(true);349}350if (to_compute.test(ConeProperty::StanleyDec)) {351Out.set_write_dec(true);352Out.set_write_tgn(true);353Out.set_write_inv(true);354}355for(size_t i=0;i<OutFiles.size();++i){356if(OutFiles[i]=="gen"){357Out.set_write_gen(true);358continue;359}360if(OutFiles[i]=="cst"){361Out.set_write_cst(true);362continue;363}364if(OutFiles[i]=="inv"){365Out.set_write_inv(true);366continue;367}368if(OutFiles[i]=="ht1"){369Out.set_write_ht1(true);370continue;371}372if(OutFiles[i]=="ext"){373Out.set_write_ext(true);374continue;375}376if(OutFiles[i]=="egn"){377Out.set_write_egn(true);378continue;379}380if(OutFiles[i]=="esp"){381Out.set_write_esp(true);382continue;383}384if(OutFiles[i]=="typ"){385Out.set_write_typ(true);386continue;387}388if(OutFiles[i]=="lat"){389Out.set_write_lat(true);390continue;391}392if(OutFiles[i]=="msp"){393Out.set_write_msp(true);394continue;395}396if(OutFiles[i]=="mod"){397Out.set_write_mod(true);398continue;399}400}401402if (!project_name_set) {403cerr << "ERROR: No project name set!" << endl;404exit(1);405}406Out.set_name(output_file);407}408409bool OptionsHandler::anyNmzIntegrateOption() const {410return nmzInt_E || nmzInt_I || nmzInt_L;411}412413string OptionsHandler::getNmzIntegrateOptions() const {414string nmz_options;415if (verbose) {416nmz_options.append(" -c");417}418if (nr_threads > 0) {419nmz_options.append(" -x=");420ostringstream convert;421convert << nr_threads;422nmz_options.append(convert.str());423}424if (nmzInt_E) {425nmz_options.append(" -E");426}427if (nmzInt_L) {428nmz_options.append(" -L");429}430if (nmzInt_I) {431nmz_options.append(" -I");432}433nmz_options.append(" \"");434nmz_options.append(project_name);435nmz_options.append("\"");436if(output_dir_set){437nmz_options.append(" \"");438nmz_options.append("--OutputDir="+output_dir);439nmz_options.append("\"");440}441return nmz_options;442}443444bool OptionsHandler::activateDefaultMode() {445if (to_compute.goals().none() && !to_compute.test(ConeProperty::DualMode)) {446to_compute.set(ConeProperty::DefaultMode);447return true;448}449return false;450}451452string pureName(const string& fullName){453// extracts the pure filename454455string slash="/";456#ifdef _WIN32 //for 32 and 64 bit windows457slash="\\";458#endif459size_t found = fullName.rfind(slash);460if(found==std::string::npos)461return(fullName);462found++;463size_t length=fullName.size()-found;464465// cout << "**************************** " << fullName.substr(found,length) << endl;466// exit(1);467return(fullName.substr(found,length));468469}470471472