CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

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

Views: 418346
1
/*
2
* Normaliz
3
* Copyright (C) 2007-2014 Winfried Bruns, Bogdan Ichim, Christof Soeger
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation, either version 3 of the License, or
7
* (at your option) any later version.
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
*
17
* As an exception, when this program is distributed through (i) the App Store
18
* by Apple Inc.; (ii) the Mac App Store by Apple Inc.; or (iii) Google Play
19
* by Google Inc., then that store may impose any digital rights management,
20
* device limits and/or redistribution restrictions that are required by its
21
* terms of service.
22
*/
23
24
#include <stdlib.h>
25
#include <vector>
26
#include <list>
27
#include <string>
28
#include <sstream>
29
#include <algorithm>
30
using namespace std;
31
32
#include "Qnormaliz.h"
33
#include "libQnormaliz/Qinteger.h"
34
#include "libQnormaliz/libQnormaliz.h"
35
#include "libQnormaliz/Qcone.h"
36
#include "libQnormaliz/Qmy_omp.h"
37
//#include "libnormaliz/libnormaliz.cpp"
38
using namespace libQnormaliz;
39
#include "Qinput.cpp"
40
#include "Qoptions.cpp"
41
#include "Qoutput.cpp"
42
43
#ifndef STRINGIFY
44
#define STRINGIFYx(Token) #Token
45
#define STRINGIFY(Token) STRINGIFYx(Token)
46
#endif
47
48
void printHeader() {
49
cout << " \\.....|"<<endl;
50
cout << " QNormaliz " << string( STRINGIFY(QNMZ_VERSION) " " ,11)
51
<< " \\....|"<<endl;
52
cout << " \\...|"<<endl;
53
cout << " (C) The Normaliz Team, University of Osnabrueck \\..|"<<endl;
54
cout << " November 2016 \\.|"<<endl;
55
cout << " \\|"<<endl;
56
}
57
void printHelp(char* command) {
58
cout << "Usage: "<<command<<" [options] PROJECT"<<endl;
59
cout << " runs normaliz on PROJECT.in"<<endl;
60
cout << "Options:"<<endl;
61
cout << " -S\tcompute sublattice"<<endl;
62
cout << " -s\tcompute support hyperplanes"<<endl;
63
cout << " -T\tcompute triangulation (output in file .tri)"<<endl;
64
cout << " -D\tcompute cone decomposition (includes -T)"<<endl;
65
cout << endl;
66
cout << " -k\tcomputation mode: keep order"<<endl;
67
cout << endl;
68
cout << " --<PROP> compute the ConeProperty <PROP>"<<endl;
69
70
cout << endl;
71
cout << " -f, --files write the files .out .gen .inv .cst .msp"<<endl;
72
cout << " -a, --all-files write all output files (except .tri)"<<endl;
73
cout << " --<SUFFIX> write the file .<SUFFIX> where <SUFFIX> can be one of"<<endl;
74
cout << " cst, esp, ext, inv, lat, msp"<<endl;
75
76
cout << endl;
77
cout << " -i, --ignore ignore the compute options set in the input file"<<endl;
78
cout << " -x=<T> limit the number of threads to <T>"<<endl;
79
cout << " --OutputDir=<path> set a path for the output files (relative to current directory)"<< endl;
80
cout << " -?, --help print this help text and exit"<<endl;
81
cout << " -c, --verbose verbose (prints control data)"<<endl;
82
cout << " --version print version info and exit"<<endl;
83
cout << endl;
84
cout << "Please report bugs to <[email protected]> or directly to our issue tracker:" << endl;
85
cout << "https://github.com/Normaliz/Normaliz/issues" << endl;
86
}
87
88
void printCopying() {
89
cout<<"Copyright (C) 2007-2017 The Normaliz Team, University of Osnabrueck."<<endl
90
<<"This program comes with ABSOLUTELY NO WARRANTY; This is free software,"<<endl
91
<<"and you are welcome to redistribute it under certain conditions;"<<endl
92
<<"See COPYING for details."<<endl;
93
}
94
95
void printVersion() {
96
cout << "Normaliz " << string(STRINGIFY(QNMZ_VERSION)) << endl;
97
printCopying();
98
}
99
100
template<typename Number> int process_data(OptionsHandler& options, const string& command_line);
101
102
//---------------------------------------------------------------------------
103
104
int main(int argc, char* argv[])
105
{
106
107
// read command line options
108
109
OptionsHandler options;
110
111
string command_line;
112
for(int i=1; i< argc;++i)
113
command_line=command_line+string(argv[i])+" ";
114
115
bool print_help = options.handle_commandline(argc, argv);
116
117
if (print_help) {
118
//printHeader();
119
printHelp(argv[0]);
120
exit(0);
121
}
122
123
if (verbose) {
124
printHeader();
125
}
126
127
if (!options.isUseLongLong()) {
128
process_data<mpq_class>(options, command_line);
129
}
130
// the previous process_data might return unsuccessfully if the input file specifies to use long long
131
132
}
133
134
//---------------------------------------------------------------------------
135
136
template<typename Number> int process_data(OptionsHandler& options, const string& command_line) {
137
138
#ifndef NCATCH
139
try {
140
#endif
141
142
Output<Number> Out; //all the information relevant for output is collected in this object
143
144
options.applyOutputOptions(Out);
145
146
string name_in=options.getOutputName()+".in";
147
const char* file_in=name_in.c_str();
148
ifstream in;
149
in.open(file_in,ifstream::in);
150
if ( !in.is_open() ) {
151
cerr << "error: Failed to open file "<<name_in<<"."<<endl;
152
exit(1);
153
}
154
155
//read the file
156
map <Type::InputType, vector< vector<Number> > > input = readNormalizInput<Number>(in, options);
157
158
options.activateDefaultMode(); // only if no real cone property is given!
159
160
Out.set_lattice_ideal_input(input.count(Type::lattice_ideal)>0);
161
162
in.close();
163
164
165
if (verbose) {
166
cout << "************************************************************" << endl;
167
cout << "Command line: " << command_line << endl;
168
cout << "Compute: " << options.getToCompute() << endl;
169
}
170
171
Cone<Number> MyCone = Cone<Number>(input);
172
long dim= (long) MyCone.getEmbeddingDim();
173
#ifdef _OPENMP
174
long max_threads=omp_get_max_threads();
175
if(!options.nr_threads_explicitly_set && std::getenv("OMP_NUM_THREADS")==NULL){
176
max_threads=min(max_threads,4*dim); // we limit the implicit number of threads
177
omp_set_num_threads(max_threads);
178
}
179
#endif
180
/* if (options.isUseBigNumber()) {
181
MyCone.deactivateChangeOfPrecision();
182
} */
183
try {
184
MyCone.compute(options.getToCompute());
185
} catch(const NotComputableException& e) {
186
std::cout << "Not all desired properties could be computed." << endl;
187
std::cout << e.what() << endl;
188
std::cout << "Writing only available data." << endl;
189
}
190
Out.setCone(MyCone);
191
Out.write_files();
192
193
#ifndef NCATCH
194
} catch(const BadInputException& e) {
195
cerr << e.what() << endl;
196
cerr << "BadInputException caught... exiting." << endl;
197
exit(1);
198
} catch(const FatalException& e) {
199
cerr << e.what() << endl;
200
cerr << "FatalException caught... exiting." << endl;
201
exit(2);
202
} catch(const NormalizException& e) {
203
cerr << e.what() << endl;
204
cerr << "NormalizException caught... exiting." << endl;
205
exit(3);
206
} catch(const std::exception& e) {
207
cerr << "std::exception caught... \""<< e.what()<<"\" ... exiting." << endl;
208
exit(4);
209
}
210
#endif
211
212
return 0;
213
}
214
215