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