MCPcopy Create free account
hub / github.com/Singular/Singular / random_problems

Function random_problems

IntegerProgramming/testdata.cc:176–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

174
175
176int random_problems(const short& vector_dimension,
177 const long& number_of_instances,
178 const Integer& lower_bound, const Integer& upper_bound,
179 ofstream& PROBLEM)
180{
181 // check arguments
182
183 if(vector_dimension<=0)
184 {
185 cerr<<"ERROR: int random_problems(const short&, const long&, \n"
186 " const Integer&, const Integer&, ofstream&):\n"
187 "first argument out of range: vector dimension must be positive"
188 <<endl;
189 return 0;
190 }
191
192 if(number_of_instances<0)
193 {
194 cerr<<"ERROR: int random_problems(const short&, const long&, \n"
195 " const Integer&, const Integer&, ofstream&):\n"
196 "second argument out of range: number of instances must be nonnegative"
197 <<endl;
198 return 0;
199 }
200
201 if(upper_bound<lower_bound)
202 {
203 cerr<<"ERROR: int random_problems(const short&, const long&, \n"
204 " const Integer&, const Integer&, ofstream&):\n"
205 "third argument (lower bound for random entries) must be less\n"
206 "or equal the fourth argument (upper bound)"<<endl;
207 return 0;
208 }
209
210 // create random problems
211
212 PROBLEM<<"PROBLEM"<<endl<<endl;
213
214 PROBLEM<<"vector size:"<<endl;
215 PROBLEM<<vector_dimension<<endl<<endl;
216
217 PROBLEM<<"number of instances:"<<endl;
218 PROBLEM<<number_of_instances<<endl<<endl;
219
220 PROBLEM<<"right hand or initial solution vectors:"<<endl;
221 for(short i=0;i<number_of_instances;i++)
222 {
223 for(short j=0;j<vector_dimension;j++)
224 PROBLEM<<setw(4)<<rand()%(upper_bound+1);
225 // random entries between 0 and upper_bound
226 PROBLEM<<endl;
227 }
228 PROBLEM<<endl;
229
230 return 1;
231}
232#endif // TESTDATA_CC

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected