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