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

Function random_matrix

IntegerProgramming/testdata.cc:15–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13
14
15int random_matrix(const short& rows, const short& columns,
16 const Integer& lower_bound, const Integer& upper_bound,
17 ofstream& MATRIX)
18{
19 // check arguments
20
21 if(rows<=0)
22 {
23 cerr<<"ERROR: int random_matrix(const short&, const short&, \n"
24 " const Integer&, const Integer&, ofstream&):\n"
25 "first argument out of range: number of matrix rows must be positive"
26 <<endl;
27 return 0;
28 }
29
30 if(columns<=0)
31 {
32 cerr<<"ERROR: int random_matrix(const short&, const short&, \n"
33 " const Integer&, const Integer&, ofstream&):\n"
34 "second argument out of range: number of matrix columns must be positive"
35 <<endl;
36 return 0;
37 }
38
39 if(upper_bound<0)
40 {
41 cerr<<"ERROR: int random_matrix(const short&, const short&, \n"
42 " const Integer&, const Integer&, ofstream&):\n"
43 "fourth argument (upper bound for random cost vector entries) must be\n"
44 "nonnegative\n"<<endl;
45 return 0;
46 }
47
48 if(upper_bound<lower_bound)
49 {
50 cerr<<"ERROR: int random_matrix(const short&, const short&, \n"
51 " const Integer&, const Integer&, ofstream&):\n"
52 "third argument (lower bound for random entries) must be less\n"
53 "or equal the fourth argument (upper bound)"<<endl;
54 return 0;
55 }
56
57 // create test file
58
59 MATRIX<<"MATRIX"<<endl<<endl;
60
61 MATRIX<<"columns:"<<endl;
62 MATRIX<<columns<<endl<<endl;
63
64 // random cost vector
65 MATRIX<<"cost vector:"<<endl;
66 for(short j=0;j<columns;j++)
67 MATRIX<<setw(4)<<rand()%(upper_bound+1);
68 // random entries between 0 and upper_bound
69 MATRIX<<endl;
70
71 MATRIX<<"rows:"<<endl;
72 MATRIX<<rows<<endl<<endl;

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected