File: libnormaliz.cpp

package info (click to toggle)
normaliz 3.6.3%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 25,880 kB
  • sloc: cpp: 37,346; makefile: 1,611; python: 596
file content (219 lines) | stat: -rw-r--r-- 6,359 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*
 * Normaliz
 * Copyright (C) 2007-2014  Winfried Bruns, Bogdan Ichim, Christof Soeger
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * As an exception, when this program is distributed through (i) the App Store
 * by Apple Inc.; (ii) the Mac App Store by Apple Inc.; or (iii) Google Play
 * by Google Inc., then that store may impose any digital rights management,
 * device limits and/or redistribution restrictions that are required by its
 * terms of service.
 */

#include <cstdlib>
#include <signal.h>

#include "libnormaliz/libnormaliz.h"
#include "libnormaliz/general.h"
#include "libnormaliz/my_omp.h"

namespace libnormaliz {

bool verbose = false;

bool nmz_scip=false;

volatile sig_atomic_t nmz_interrupted = 0;
long default_thread_limit=8;
long thread_limit=default_thread_limit;
bool parallelization_set=false;

// bool test_arithmetic_overflow = false;
// long overflow_test_modulus = 15401;

size_t GMP_mat=0;
size_t GMP_hyp=0;
size_t GMP_scal_prod=0;
size_t TotDet=0;

void interrupt_signal_handler( int signal ){
    nmz_interrupted = 1;
}

namespace {
    std::ostream* verbose_ostream_ptr = &std::cout;
    std::ostream* error_ostream_ptr = &std::cerr;
} // end anonymous namespace, only accessible in this file (and when it is included)

bool setVerboseDefault(bool v) {
    //we want to return the old value
    bool old = verbose;
    verbose = v;
    return old;
}

long set_thread_limit(long t){
    long old=thread_limit;
    parallelization_set=true;
    thread_limit=t;
    return old;
}

void setVerboseOutput(std::ostream& v_out) {
    verbose_ostream_ptr = &v_out;
}

void setErrorOutput(std::ostream& e_out) {
    error_ostream_ptr = &e_out;
}

std::ostream& verboseOutput() {
    return *verbose_ostream_ptr;
}

std::ostream& errorOutput() {
    return *error_ostream_ptr;
}

InputType to_type(const std::string& type_string) {

    if ( type_string=="0" || type_string=="1" || type_string=="2" || type_string=="3"
      || type_string=="4" || type_string=="5" || type_string=="6"
      || type_string=="hyperplanes"
      || type_string=="10") {
        throw BadInputException("Error: deprecated type \"" + type_string
                + "\", please use new type string!");
    }

    if (type_string=="0"||type_string=="integral_closure") {
        return Type::integral_closure;
    }
    if (type_string=="polyhedron") {
        return Type::polyhedron;
    }
    if (type_string=="1"||type_string=="normalization") {
        return Type::normalization;
    }
    if (type_string=="2"||type_string=="polytope") {
        return Type::polytope;
    }
    if (type_string=="3"||type_string=="rees_algebra") {
        return Type::rees_algebra;
    }
    if (type_string=="4"||type_string=="hyperplanes" ||type_string=="inequalities") {
        return Type::inequalities;
    }
    if (type_string=="strict_inequalities") {
         return Type::strict_inequalities;
    }
    if (type_string=="strict_signs") {
        return Type::strict_signs;
    }
    if (type_string=="inhom_inequalities") {
        return Type::inhom_inequalities;
    }
    if (type_string=="dehomogenization") {
         return Type::dehomogenization;
    }
    if (type_string=="5"||type_string=="equations") {
        return Type::equations;
    }
    if (type_string=="inhom_equations") {
        return Type::inhom_equations;
    }
    if (type_string=="6"||type_string=="congruences") {
        return Type::congruences;
    }
    if (type_string=="inhom_congruences") {
        return Type::inhom_congruences;
    }
    if (type_string=="signs") {
        return Type::signs;
    }
    if (type_string=="10"||type_string=="lattice_ideal") {
        return Type::lattice_ideal;
    }
    if (type_string=="grading") {
        return Type::grading;
    }
    if (type_string=="excluded_faces") {
        return Type::excluded_faces;
    }
    if (type_string=="lattice") {
        return Type::lattice;
    }
    if (type_string=="saturation") {
        return Type::saturation;
    }
    if (type_string=="cone") {
        return Type::cone;
    }
    if (type_string=="offset") {
        return Type::offset;
    }
    if (type_string=="vertices") {
        return Type::vertices;
    }
    if (type_string=="support_hyperplanes") {
        return Type::support_hyperplanes;
    }
    if (type_string=="cone_and_lattice") {
        return Type::cone_and_lattice;
    }
    if (type_string=="subspace") {
        return Type::subspace;
    }
    
    if (type_string=="open_facets") {
        return Type::open_facets;
    }
    
    if (type_string=="projection_coordinates") {
        return Type::projection_coordinates;
    }
    
    if (type_string=="hilbert_basis_rec_cone") {
        return Type::hilbert_basis_rec_cone;
    }
    
    if (type_string=="extreme_rays") {
        return Type::extreme_rays;
    }

    throw BadInputException("Unknown type \"" + type_string + "\"!");
    return Type::integral_closure;
}

long type_nr_columns_correction(InputType t) {
    if (t == Type::polytope || t == Type::rees_algebra)
        return -1;
    if (t == Type::congruences || t == Type::vertices || t == Type::polyhedron
     || t == Type::inhom_inequalities || t == Type::inhom_equations || t == Type::hilbert_basis_rec_cone)
        return 1;
    if (t == Type::inhom_congruences)
        return 2;
    return 0;
}

/* returns true if the input of this type is a vector */
bool type_is_vector(InputType type){
    if (type == Type::grading || type == Type::signs || type == Type::strict_signs
            || type == Type::dehomogenization || type == Type::offset || type==Type::open_facets  
            || type==Type::projection_coordinates) {
        return true;
    }
    return false;
}

} /* end namespace libnormaliz */