1 | // toric_ideal.cc |
---|
2 | |
---|
3 | // This file provides an interface to compute toric ideals from a matrix |
---|
4 | // without solving IP-problems. |
---|
5 | |
---|
6 | |
---|
7 | |
---|
8 | #ifndef TORIC_IDEAL_CC |
---|
9 | #define TORIC_IDEAL_CC |
---|
10 | |
---|
11 | |
---|
12 | |
---|
13 | #include "IP_algorithms.h" |
---|
14 | |
---|
15 | |
---|
16 | |
---|
17 | int main(int argc, char *argv[]) |
---|
18 | { |
---|
19 | |
---|
20 | // initialize arguments for the Buchberger algorithm |
---|
21 | // with default settings |
---|
22 | BOOLEAN verbose=FALSE; |
---|
23 | short version=1; |
---|
24 | short S_pair_criteria=11; |
---|
25 | double interreduction_percentage=12.0; |
---|
26 | |
---|
27 | |
---|
28 | ///////////////////////// parse options ///////////////////////////////////// |
---|
29 | |
---|
30 | short alg_option=0; |
---|
31 | // no algorithm specified yet |
---|
32 | |
---|
33 | if(argc>=2 && strcmp(argv[1],"--help")) |
---|
34 | // argc has to be at least 2 |
---|
35 | // program name, MATRIX file |
---|
36 | { |
---|
37 | |
---|
38 | for(short i=1;i<argc-1;i++) |
---|
39 | // these are the input options |
---|
40 | { |
---|
41 | |
---|
42 | if(!strcmp(argv[i],"-v") || !strcmp(argv[i],"--verbose")) |
---|
43 | { |
---|
44 | verbose=TRUE; |
---|
45 | continue; |
---|
46 | // read next argument |
---|
47 | } |
---|
48 | |
---|
49 | if(!strcmp(argv[i],"-V") || !strcmp(argv[i],"-version")) |
---|
50 | { |
---|
51 | // check if next argument is a valid version number |
---|
52 | i++; |
---|
53 | |
---|
54 | if(!strcmp(argv[i],"1")) |
---|
55 | { |
---|
56 | version=1; |
---|
57 | continue; |
---|
58 | } |
---|
59 | if(!strcmp(argv[i],"1a")) |
---|
60 | { |
---|
61 | version=0; |
---|
62 | continue; |
---|
63 | } |
---|
64 | if(!strcmp(argv[i],"2")) |
---|
65 | { |
---|
66 | version=2; |
---|
67 | continue; |
---|
68 | } |
---|
69 | if(!strcmp(argv[i],"3")) |
---|
70 | { |
---|
71 | version=3; |
---|
72 | continue; |
---|
73 | } |
---|
74 | |
---|
75 | // When reaching this line, the version argument was invalid. |
---|
76 | cerr<<"ERROR: invalid version argument"<<endl |
---|
77 | <<"Type `toric_ideal --help' for help on options."<<endl; |
---|
78 | return 1; |
---|
79 | } |
---|
80 | |
---|
81 | if(!strcmp(argv[i],"-S")) |
---|
82 | { |
---|
83 | // initialize argument to the use of no criteria |
---|
84 | S_pair_criteria=0; |
---|
85 | |
---|
86 | do |
---|
87 | { |
---|
88 | // Check what S-pair criterion the next argument indicates. |
---|
89 | // If none: The algorithm is called without S-pair criteria. |
---|
90 | i++; |
---|
91 | |
---|
92 | if(i>=argc-2) |
---|
93 | // file arguments reached |
---|
94 | break; |
---|
95 | |
---|
96 | if(!strcmp(argv[i],"RP")) |
---|
97 | { |
---|
98 | S_pair_criteria|=1; |
---|
99 | continue; |
---|
100 | } |
---|
101 | if(!strcmp(argv[i],"M")) |
---|
102 | { |
---|
103 | S_pair_criteria|=2; |
---|
104 | continue; |
---|
105 | } |
---|
106 | if(!strcmp(argv[i],"F")) |
---|
107 | { |
---|
108 | S_pair_criteria|=4; |
---|
109 | continue; |
---|
110 | } |
---|
111 | if(!strcmp(argv[i],"B")) |
---|
112 | { |
---|
113 | S_pair_criteria|=8; |
---|
114 | continue; |
---|
115 | } |
---|
116 | if(!strcmp(argv[i],"2")) |
---|
117 | { |
---|
118 | S_pair_criteria|=16; |
---|
119 | continue; |
---|
120 | } |
---|
121 | |
---|
122 | // option does not belong to an S-pair criterion |
---|
123 | break; |
---|
124 | |
---|
125 | } |
---|
126 | while(1); |
---|
127 | |
---|
128 | i--; // reset counter so that the outer loop |
---|
129 | continue; // continues with the just considered argument |
---|
130 | } |
---|
131 | |
---|
132 | if(!strcmp(argv[i],"-p")) |
---|
133 | { |
---|
134 | // read interreduction percentage |
---|
135 | i++; |
---|
136 | |
---|
137 | char** rest; |
---|
138 | interreduction_percentage=strtod(argv[i],rest); |
---|
139 | // The function strtod converts a string into a double. As the |
---|
140 | // specification is not correct, it may cause trouble... |
---|
141 | // For example, if the argument can be read as a float, the value |
---|
142 | // of rest should be NULL. This is not the case. Therefore, we can |
---|
143 | // only check by the following string comparison if a float has been |
---|
144 | // built. An argument as 15xy is thereby considered as valid |
---|
145 | // (with interreduction_percentage==15.0). |
---|
146 | |
---|
147 | if(!(strcmp(argv[i],*rest))) |
---|
148 | // argument was no float |
---|
149 | { |
---|
150 | cerr<<"ERROR: invalid argument for interreduction percentage"<<endl |
---|
151 | <<"Type `toric_ideal --help' for help on options."<<endl; |
---|
152 | return 1; |
---|
153 | } |
---|
154 | |
---|
155 | continue; |
---|
156 | } |
---|
157 | |
---|
158 | if(!strcmp(argv[i],"-alg") || !strcmp(argv[i],"--algorithm")) |
---|
159 | { |
---|
160 | // check if next argument is a valid algorithm specification |
---|
161 | i++; |
---|
162 | |
---|
163 | if(!strcmp(argv[i],"ct") || !strcmp(argv[i],"pct") || |
---|
164 | !strcmp(argv[i],"ect") || !strcmp(argv[i],"pt") || |
---|
165 | !strcmp(argv[i],"hs") || !strcmp(argv[i],"du") || |
---|
166 | !strcmp(argv[i],"blr")) |
---|
167 | { |
---|
168 | alg_option=i; |
---|
169 | continue; |
---|
170 | } |
---|
171 | |
---|
172 | // When reaching this line, the algorithm argument was invalid. |
---|
173 | cerr<<"ERROR: unkwon algorithm"<<endl |
---|
174 | <<"Type `toric_ideal --help' for help on options."<<endl; |
---|
175 | return 1; |
---|
176 | } |
---|
177 | |
---|
178 | // When reaching this line, the argument is no legal option. |
---|
179 | cerr<<"ERROR: invalid option "<<argv[i]<<endl |
---|
180 | <<"Type `toric_ideal --help' for help on options."<<endl; |
---|
181 | return 1; |
---|
182 | } |
---|
183 | |
---|
184 | |
---|
185 | ////////////// call algorithms for computing toric ideals ///////////////////// |
---|
186 | |
---|
187 | // open input stream (MATRIX file) |
---|
188 | ifstream input(argv[argc-1]); |
---|
189 | |
---|
190 | if(!input) |
---|
191 | { |
---|
192 | cerr<<"ERROR: cannot open input file, possibly not found"<<endl; |
---|
193 | return 1; |
---|
194 | } |
---|
195 | |
---|
196 | if(alg_option==0) |
---|
197 | { |
---|
198 | cerr<<"ERROR: no valid algorithm specified"<<endl; |
---|
199 | return 1; |
---|
200 | } |
---|
201 | |
---|
202 | // perform specified algorithm to compute a Groebner basis of the |
---|
203 | // toric ideal defined by the input matrix |
---|
204 | |
---|
205 | int success; |
---|
206 | if(!strcmp(argv[alg_option],"ct")) |
---|
207 | success=Conti_Traverso(argv[argc-1], version, S_pair_criteria, |
---|
208 | interreduction_percentage, verbose); |
---|
209 | if(!strcmp(argv[alg_option],"pct")) |
---|
210 | success=Positive_Conti_Traverso(argv[argc-1], version, |
---|
211 | S_pair_criteria, |
---|
212 | interreduction_percentage, verbose); |
---|
213 | if(!strcmp(argv[alg_option],"ect")) |
---|
214 | success=Elim_Conti_Traverso(argv[argc-1], version, S_pair_criteria, |
---|
215 | interreduction_percentage, verbose); |
---|
216 | if(!strcmp(argv[alg_option],"pt")) |
---|
217 | success=Pottier(argv[argc-1], version, S_pair_criteria, |
---|
218 | interreduction_percentage, verbose); |
---|
219 | if(!strcmp(argv[alg_option],"hs")) |
---|
220 | success=Hosten_Sturmfels(argv[argc-1], version, S_pair_criteria, |
---|
221 | interreduction_percentage, verbose); |
---|
222 | if(!strcmp(argv[alg_option],"du")) |
---|
223 | success=DiBiase_Urbanke(argv[argc-1], version, S_pair_criteria, |
---|
224 | interreduction_percentage, verbose); |
---|
225 | if(!strcmp(argv[alg_option],"blr")) |
---|
226 | success=Bigatti_LaScala_Robbiano(argv[argc-1], version, |
---|
227 | S_pair_criteria, |
---|
228 | interreduction_percentage, verbose); |
---|
229 | if(!success) |
---|
230 | { |
---|
231 | cerr<<"ERROR: could not perform required IP-algorithm,\n" |
---|
232 | "no GROEBNER file created"<<endl; |
---|
233 | return 1; |
---|
234 | } |
---|
235 | |
---|
236 | // Groebner basis successfully computed |
---|
237 | return 0; |
---|
238 | } |
---|
239 | |
---|
240 | |
---|
241 | /////////////////////// provide help text /////////////////////////////////// |
---|
242 | |
---|
243 | // handle the case of "missing" arguments |
---|
244 | |
---|
245 | if((argc==2) && !strcmp(argv[1],"--help")) |
---|
246 | // help required |
---|
247 | { |
---|
248 | system("less toric_ideal.hlp"); |
---|
249 | return 0; |
---|
250 | } |
---|
251 | |
---|
252 | else |
---|
253 | // invalid arguments |
---|
254 | cerr<<"USAGE: toric_ideal [options] matrix_file"<<endl |
---|
255 | <<"Type `toric_ideal --help' for help on options."<<endl; |
---|
256 | |
---|
257 | return 1; |
---|
258 | |
---|
259 | } |
---|
260 | #endif // TORIC_IDEAL_CC |
---|