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

Function transportation_problem

IntegerProgramming/testdata.cc:94–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92
93
94int transportation_problem(const short& sources, const short& targets,
95 const Integer& upper_bound, ofstream& MATRIX)
96{
97 // check arguments
98
99 if(sources<=0)
100 {
101 cerr<<"ERROR: int transportation_problem(const short&, const short&, \n"
102 " const Integer&, ofstream&):\n"
103 "first argument out of range: number of sources must be positive"
104 <<endl;
105 return 0;
106 }
107
108 if(targets<=0)
109 {
110 cerr<<"ERROR: int transportation_problem(const short&, const short&, \n"
111 " const Integer&, ofstream&):\n"
112 "second argument out of range: number of targets must be positive"
113 <<endl;
114 return 0;
115 }
116
117 if(upper_bound<0)
118 {
119 cerr<<"ERROR: int transportation_problem(const short&, const short&, \n"
120 " const Integer&, const Integer&, ofstream&):\n"
121 "third argument (upper bound for random cost vector entries) must be\n"
122 "nonnegative\n"<<endl;
123 return 0;
124 }
125
126 // create test file
127
128 MATRIX<<"MATRIX"<<endl<<endl;
129
130 MATRIX<<"columns:"<<endl;
131 MATRIX<<sources*targets<<endl<<endl;
132
133 // random cost vector
134 MATRIX<<"cost vector:"<<endl;
135 for(short j=0;j<sources*targets;j++)
136 MATRIX<<setw(4)<<rand()%(upper_bound+1);
137 // random entries between 0 and upper_bound
138 MATRIX<<endl;
139
140 MATRIX<<"rows:"<<endl;
141 MATRIX<<sources+targets<<endl<<endl;
142
143 // constraint matrix in the usual formulation of the transportation problem
144 // as an IP problem
145 MATRIX<<"matrix:"<<endl;
146
147 for(int i=0;i<targets;i++)
148 // generate matrix
149 {
150 for(int k=0;k<targets;k++)
151 for(int j=0;j<sources;j++)

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected