Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

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