1 // $Id$
2 // Copyright (C) 2000, International Business Machines
3 // Corporation and others.  All Rights Reserved.
4 // This code is licensed under the terms of the Eclipse Public License (EPL).
5 
6 // Test individual classes or groups of classes
7 
8 #include "CoinPragma.hpp"
9 
10 #include "CglConfig.h"
11 
12 #include <string>
13 #include <cstring>
14 #include <cassert>
15 #include <iostream>
16 #include <cstdlib>
17 
18 #ifdef COIN_HAS_OSICPX
19 #include <OsiCpxSolverInterface.hpp>
20 #endif
21 #ifdef COIN_HAS_OSIXPR
22 #include <OsiXprSolverInterface.hpp>
23 #endif
24 #ifdef COIN_HAS_OSICLP
25 #include <OsiClpSolverInterface.hpp>
26 #endif
27 #ifdef COIN_HAS_OSIDYLP
28 #include <OsiDylpSolverInterface.hpp>
29 #endif
30 #ifdef COIN_HAS_OSIGLPK
31 #include <OsiGlpkSolverInterface.hpp>
32 #endif
33 #ifdef COIN_HAS_OSIVOL
34 #include <OsiVolSolverInterface.hpp>
35 #endif
36 
37 #include "CglSimpleRounding.hpp"
38 #include "CglKnapsackCover.hpp"
39 #include "CglOddHole.hpp"
40 #include "CglProbing.hpp"
41 #include "CglGomory.hpp"
42 #include "CglLandP.hpp"
43 #include "CglMixedIntegerRounding.hpp"
44 #include "CglMixedIntegerRounding2.hpp"
45 #include "CglResidualCapacity.hpp"
46 #include "CglRedSplit.hpp"
47 #include "CglRedSplit2.hpp"
48 #include "CglTwomir.hpp"
49 #include "CglClique.hpp"
50 #include "CglFlowCover.hpp"
51 #include "CglZeroHalf.hpp"
52 
53 // Function Prototypes. Function definitions is in this file.
54 void testingMessage( const char * const msg );
55 
56 // Command line parameters are directories containing data files.
57 // You must specify both mpsDir and testDir, in order.
58 // If not specified, then "../../Data/Sample/" and
59 // "CglTestData/" are used
60 
main(int argc,const char * argv[])61 int main (int argc, const char *argv[])
62 {
63   // Initialize directories containing data files.
64   std::string mpsDir;
65   std::string testDir;
66 
67   const char dirsep =  CoinFindDirSeparator();
68   if (dirsep == '/') {
69 #ifdef SAMPLEDIR
70     mpsDir = SAMPLEDIR "/" ;
71 #else
72     mpsDir = "../../Data/Sample/";
73 #endif
74 #ifdef TESTDIR
75     testDir = TESTDIR "/" ;
76 #else
77     testDir = "CglTestData/";
78 #endif
79   } else {
80 #ifdef SAMPLEDIR
81     mpsDir = SAMPLEDIR "\\" ;
82 #else
83     mpsDir = "..\\..\\Data\\Sample\\";
84 #endif
85 #ifdef TESTDIR
86     testDir = TESTDIR "\\";
87 #else
88     testDir = "CglTestData\\";
89 #endif
90   }
91   // Check for command line override
92   if (argc >= 2) {
93     mpsDir = argv[1];
94     mpsDir += dirsep;
95     if (argc >= 3) {
96       testDir = argv[2];
97       testDir += dirsep;
98     }
99   }
100 
101 #ifdef COIN_HAS_OSICPX
102   {
103     OsiCpxSolverInterface cpxSi;
104     testingMessage( "Testing CglGomory with OsiCpxSolverInterface\n" );
105     CglGomoryUnitTest(&cpxSi,mpsDir);
106   }
107   {
108     OsiCpxSolverInterface cpxSi;
109     testingMessage( "Testing CglSimpleRounding with OsiCpxSolverInterface\n" );
110     CglSimpleRoundingUnitTest(&cpxSi,mpsDir);
111   }
112   if(0) // Test does not work with Cplex
113   {
114     OsiCpxSolverInterface cpxSi;
115     testingMessage( "Testing CglKnapsackCover with OsiCpxSolverInterface\n" );
116     CglKnapsackCoverUnitTest(&cpxSi,mpsDir);
117   }
118   {
119     OsiCpxSolverInterface cpxSi;
120     testingMessage( "Testing CglOddHole with OsiCpxSolverInterface\n" );
121     CglOddHoleUnitTest(&cpxSi,mpsDir);
122   }
123   {
124     OsiCpxSolverInterface cpxSi;
125     testingMessage( "Testing CglProbing with OsiCpxSolverInterface\n" );
126     CglProbingUnitTest(&cpxSi,mpsDir);
127   }
128   {
129     OsiCpxSolverInterface cpxSi;
130     testingMessage( "Testing CglMixedIntegerRounding with OsiCpxSolverInterface\n" );
131     CglMixedIntegerRoundingUnitTest(&cpxSi, testDir);
132   }
133   {
134     OsiCpxSolverInterface cpxSi;
135     testingMessage( "Testing CglMixedIntegerRounding2 with OsiCpxSolverInterface\n" );
136     CglMixedIntegerRounding2UnitTest(&cpxSi, testDir);
137   }
138   {
139     OsiCpxSolverInterface cpxSi;
140     testingMessage( "Testing CglResidualCapacity with OsiCpxSolverInterface\n" );
141     CglResidualCapacityUnitTest(&cpxSi, testDir);
142   }
143   {
144     OsiCpxSolverInterface cpxSi;
145     testingMessage( "Testing CglRedSplit with OsiCpxSolverInterface\n" );
146     CglRedSplitUnitTest(&cpxSi, mpsDir);
147   }
148   {
149     OsiCpxSolverInterface cpxSi;
150     testingMessage( "Testing CglTwomir with OsiCpxSolverInterface\n" );
151     CglTwomirUnitTest(&cpxSi, testDir);
152   }
153   {
154     OsiCpxSolverInterface cpxSi;
155     testingMessage( "Testing CglClique with OsiCpxSolverInterface\n" );
156     CglCliqueUnitTest(&cpxSi, testDir);
157   }
158   {
159     OsiCpxSolverInterface cpxSi;
160     testingMessage( "Testing CglFlowCover with OsiCpxSolverInterface\n" );
161     CglFlowCoverUnitTest(&cpxSi, testDir);
162   }
163 
164 #endif
165 
166 #ifdef COIN_HAS_OSIXPR
167   {
168     OsiXprSolverInterface xprSi;
169     testingMessage( "Testing CglGomory with OsiXprSolverInterface\n" );
170     CglGomoryUnitTest(&xprSi,mpsDir);
171   }
172   {
173     OsiXprSolverInterface xprSi;
174     testingMessage( "Testing CglSimpleRounding with OsiXprSolverInterface\n" );
175     CglSimpleRoundingUnitTest(&xprSi,mpsDir);
176   }
177   if(0)
178   {
179     OsiXprSolverInterface xprSi;
180     testingMessage( "Testing CglKnapsackCover with OsiXprSolverInterface\n" );
181     CglKnapsackCoverUnitTest(&xprSi,mpsDir);
182   }
183   {
184     OsiXprSolverInterface xprSi;
185     testingMessage( "Testing CglOddHole with OsiXprSolverInterface\n" );
186     CglOddHoleUnitTest(&xprSi,mpsDir);
187   }
188   if(0)     // Does not work with Xpress
189   {
190     OsiXprSolverInterface xprSi;
191     testingMessage( "Testing CglProbing with OsiXprSolverInterface\n" );
192     CglProbingUnitTest(&xprSi,mpsDir);
193   }
194   {
195     OsiXprSolverInterface xprSi;
196     testingMessage( "Testing CglMixedIntegerRounding with OsiXprSolverInterface\n" );
197     CglMixedIntegerRoundingUnitTest(&xprSi, testDir);
198   }
199   {
200     OsiXprSolverInterface xprSi;
201     testingMessage( "Testing CglMixedIntegerRounding2 with OsiXprSolverInterface\n" );
202     CglMixedIntegerRounding2UnitTest(&xprSi, testDir);
203   }
204   {
205     OsiXprSolverInterface xprSi;
206     testingMessage( "Testing CglResidualCapacity with OsiXprSolverInterface\n" );
207     CglResidualCapacityUnitTest(&xprSi, testDir);
208   }
209   {
210     OsiXprSolverInterface xprSi;
211     testingMessage( "Testing CglTwomir with OsiXprSolverInterface\n" );
212     CglTwomirUnitTest(&xprSi, testDir);
213   }
214   {
215     OsiXprSolverInterface xprSi;
216     testingMessage( "Testing CglClique with OsiXprSolverInterface\n" );
217     CglCliqueUnitTest(&xprSi, testDir);
218   }
219   {
220     OsiXprSolverInterface xprSi;
221     testingMessage( "Testing CglFlowCover with OsiXprSolverInterface\n" );
222     CglFlowCoverUnitTest(&xprSi, testDir);
223   }
224   {
225     OsiXprSolverInterface xprSi;
226     testingMessage( "Testing CglZeroHalf with OsiXprSolverInterface\n" );
227     CglZeroHalfUnitTest(&xprSi, testDir);
228   }
229 
230 #endif
231 #ifdef COIN_HAS_OSICLP
232   {
233     OsiClpSolverInterface clpSi;
234     testingMessage( "Testing CglGomory with OsiClpSolverInterface\n" );
235     CglGomoryUnitTest(&clpSi,mpsDir);
236   }
237   {
238     OsiClpSolverInterface clpSi;
239     testingMessage( "Testing CglLandp with OsiClpSolverInterface\n" );
240     CglLandPUnitTest(&clpSi,mpsDir);
241   }
242   {
243     OsiClpSolverInterface clpSi;
244     testingMessage( "Testing CglSimpleRounding with OsiClpSolverInterface\n" );
245     CglSimpleRoundingUnitTest(&clpSi,mpsDir);
246   }
247   if (0) {
248     OsiClpSolverInterface clpSi;
249     testingMessage( "Testing CglKnapsackCover with OsiClpSolverInterface\n" );
250     CglKnapsackCoverUnitTest(&clpSi,mpsDir);
251   }
252   {
253     OsiClpSolverInterface clpSi;
254     testingMessage( "Testing CglOddHole with OsiClpSolverInterface\n" );
255     CglOddHoleUnitTest(&clpSi,mpsDir);
256   }
257   {
258     OsiClpSolverInterface clpSi;
259     testingMessage( "Testing CglProbing with OsiClpSolverInterface\n" );
260     CglProbingUnitTest(&clpSi,mpsDir);
261   }
262   {
263     OsiClpSolverInterface clpSi;
264     testingMessage( "Testing CglMixedIntegerRounding with OsiClpSolverInterface\n" );
265     CglMixedIntegerRoundingUnitTest(&clpSi, testDir);
266   }
267   {
268     OsiClpSolverInterface clpSi;
269     testingMessage( "Testing CglMixedIntegerRounding2 with OsiClpSolverInterface\n" );
270     CglMixedIntegerRounding2UnitTest(&clpSi, testDir);
271   }
272   {
273     OsiClpSolverInterface clpSi;
274     testingMessage( "Testing CglResidualCapacity with OsiClpSolverInterface\n" );
275     CglResidualCapacityUnitTest(&clpSi, testDir);
276   }
277   {
278     OsiClpSolverInterface clpSi;
279     testingMessage( "Testing CglRedSplit with OsiClpSolverInterface\n" );
280     CglRedSplitUnitTest(&clpSi, mpsDir);
281   }
282   {
283     OsiClpSolverInterface clpSi;
284     testingMessage( "Testing CglRedSplit2 with OsiClpSolverInterface\n" );
285     CglRedSplit2UnitTest(&clpSi, mpsDir);
286   }
287   {
288     OsiClpSolverInterface clpSi;
289     testingMessage( "Testing CglTwomir with OsiClpSolverInterface\n" );
290     CglTwomirUnitTest(&clpSi, testDir);
291   }
292   {
293     OsiClpSolverInterface clpSi;
294     testingMessage( "Testing CglClique with OsiClpSolverInterface\n" );
295     CglCliqueUnitTest(&clpSi, testDir);
296   }
297   {
298     OsiClpSolverInterface clpSi;
299     testingMessage( "Testing CglFlowCover with OsiClpSolverInterface\n" );
300     CglFlowCoverUnitTest(&clpSi, testDir);
301   }
302   {
303     OsiClpSolverInterface clpSi;
304     testingMessage( "Testing CglZeroHalf with OsiClpSolverInterface\n" );
305     CglZeroHalfUnitTest(&clpSi, testDir);
306   }
307 
308 #endif
309 #ifdef COIN_HAS_OSIDYLP
310   {
311     OsiDylpSolverInterface dylpSi;
312     testingMessage( "Testing CglGomory with OsiDylpSolverInterface\n" );
313     CglGomoryUnitTest(&dylpSi,mpsDir);
314   }
315   {
316     OsiDylpSolverInterface dylpSi;
317     testingMessage( "Testing CglSimpleRounding with OsiDylpSolverInterface\n" );
318     CglSimpleRoundingUnitTest(&dylpSi,mpsDir);
319   }
320   if (0) {
321     OsiDylpSolverInterface dylpSi;
322     testingMessage( "Testing CglKnapsackCover with OsiDylpSolverInterface\n" );
323     CglKnapsackCoverUnitTest(&dylpSi,mpsDir);
324   }
325   {
326     OsiDylpSolverInterface dylpSi;
327     testingMessage( "Testing CglOddHole with OsiDylpSolverInterface\n" );
328     CglOddHoleUnitTest(&dylpSi,mpsDir);
329   }
330   {
331     OsiDylpSolverInterface dylpSi;
332     testingMessage( "Testing CglProbing with OsiDylpSolverInterface\n" );
333     CglProbingUnitTest(&dylpSi,mpsDir);
334   }
335   {
336     OsiDylpSolverInterface dylpSi;
337     testingMessage( "Testing CglMixedIntegerRounding with OsiDylpSolverInterface\n" );
338     CglMixedIntegerRoundingUnitTest(&dylpSi, testDir);
339   }
340   {
341     OsiDylpSolverInterface dylpSi;
342     testingMessage( "Testing CglMixedIntegerRounding2 with OsiDylpSolverInterface\n" );
343     CglMixedIntegerRounding2UnitTest(&dylpSi, testDir);
344   }
345   {
346     OsiDylpSolverInterface dylpSi;
347     testingMessage( "Testing CglResidualCapacity with OsiDylpSolverInterface\n" );
348     CglResidualCapacityUnitTest(&dylpSi, testDir);
349   }
350   if (0)  // needs partial OsiSimplex
351   {
352     OsiDylpSolverInterface dylpSi;
353     testingMessage( "Testing CglRedSplit with OsiDylpSolverInterface\n" );
354     CglRedSplitUnitTest(&dylpSi, mpsDir);
355   }
356   {
357     OsiDylpSolverInterface dylpSi;
358     testingMessage( "Testing CglTwomir with OsiDylpSolverInterface\n" );
359     CglTwomirUnitTest(&dylpSi, testDir);
360   }
361   {
362     OsiDylpSolverInterface dylpSi;
363     testingMessage( "Testing CglClique with OsiDylpSolverInterface\n" );
364     CglCliqueUnitTest(&dylpSi, testDir);
365   }
366   {
367     OsiDylpSolverInterface dylpSi;
368     testingMessage( "Testing CglFlowCover with OsiDylpSolverInterface\n" );
369     CglFlowCoverUnitTest(&dylpSi, testDir);
370   }
371   if (0) {
372     OsiDylpSolverInterface dylpSi;
373     testingMessage( "Testing CglZeroHalf with OsiDylpSolverInterface\n" );
374     CglZeroHalfUnitTest(&dylpSi, testDir);
375   }
376 
377 #endif
378 #ifdef COIN_HAS_OSIGLPK
379   {
380     OsiGlpkSolverInterface glpkSi;
381     testingMessage( "Testing CglGomory with OsiGlpkSolverInterface\n" );
382     CglGomoryUnitTest(&glpkSi,mpsDir);
383   }
384   {
385     OsiGlpkSolverInterface glpkSi;
386     testingMessage( "Testing CglSimpleRounding with OsiGlpkSolverInterface\n" );
387     CglSimpleRoundingUnitTest(&glpkSi,mpsDir);
388   }
389   if (0) {
390     OsiGlpkSolverInterface glpkSi;
391     testingMessage( "Testing CglKnapsackCover with OsiGlpkSolverInterface\n" );
392     CglKnapsackCoverUnitTest(&glpkSi,mpsDir);
393   }
394   {
395     OsiGlpkSolverInterface glpkSi;
396     testingMessage( "Testing CglOddHole with OsiGlpkSolverInterface\n" );
397     CglOddHoleUnitTest(&glpkSi,mpsDir);
398   }
399   {
400     OsiGlpkSolverInterface glpkSi;
401     testingMessage( "Testing CglProbing with OsiGlpkSolverInterface\n" );
402     CglProbingUnitTest(&glpkSi,mpsDir);
403   }
404   {
405     OsiGlpkSolverInterface glpkSi;
406     testingMessage( "Testing CglMixedIntegerRounding with OsiGlpkSolverInterface\n" );
407     CglMixedIntegerRoundingUnitTest(&glpkSi, testDir);
408   }
409   {
410     OsiGlpkSolverInterface glpkSi;
411     testingMessage( "Testing CglMixedIntegerRounding2 with OsiGlpkSolverInterface\n" );
412     CglMixedIntegerRounding2UnitTest(&glpkSi, testDir);
413   }
414   {
415     OsiGlpkSolverInterface glpkSi;
416     testingMessage( "Testing CglResidualCapacity with OsiGlpkSolverInterface\n" );
417     CglResidualCapacityUnitTest(&glpkSi, testDir);
418   }
419   if (0)  // needs partial OsiSimplex
420   {
421     OsiGlpkSolverInterface glpkSi;
422     testingMessage( "Testing CglRedSplit with OsiGlpkSolverInterface\n" );
423     CglRedSplitUnitTest(&glpkSi, mpsDir);
424   }
425   {
426     OsiGlpkSolverInterface glpkSi;
427     testingMessage( "Testing CglTwomir with OsiGlpkSolverInterface\n" );
428     CglTwomirUnitTest(&glpkSi, testDir);
429   }
430   {
431     OsiGlpkSolverInterface glpkSi;
432     testingMessage( "Testing CglClique with OsiGlpkSolverInterface\n" );
433     CglCliqueUnitTest(&glpkSi, testDir);
434   }
435   {
436     OsiGlpkSolverInterface glpkSi;
437     testingMessage( "Testing CglFlowCover with OsiGlpkSolverInterface\n" );
438     CglFlowCoverUnitTest(&glpkSi, testDir);
439   }
440   {
441     OsiGlpkSolverInterface glpkSi;
442     testingMessage( "Testing CglZeroHalf with OsiGlpkSolverInterface\n" );
443     CglZeroHalfUnitTest(&glpkSi, testDir);
444   }
445 
446 #endif
447 
448 #ifdef COIN_HAS_OSIVOL
449   if(0) // p0033: LP not solved to optimality: Finds 2142 versus 2520
450   {
451     OsiVolSolverInterface volSi;
452     testingMessage( "Testing CglGomory with OsiVolSolverInterface\n" );
453     CglGomoryUnitTest(&volSi,mpsDir);
454   }
455   if(0) // Not expected number of cuts; might come from different solution?
456   {
457     OsiVolSolverInterface volSi;
458     testingMessage( "Testing CglSimpleRounding with OsiVolSolverInterface\n" );
459     CglSimpleRoundingUnitTest(&volSi,mpsDir);
460   }
461   if(0) // tp3: LP not solved to optimality: Finds 97.1842 versus 97.185
462   {
463     OsiVolSolverInterface volSi;
464     testingMessage( "Testing CglKnapsackCover with OsiVolSolverInterface\n" );
465     CglKnapsackCoverUnitTest(&volSi,mpsDir);
466   }
467   {
468     OsiVolSolverInterface volSi;
469     testingMessage( "Testing CglOddHole with OsiVolSolverInterface\n" );
470     CglOddHoleUnitTest(&volSi,mpsDir);
471   }
472   if(0) // Not expected number of elements in cut; might come from different solution?
473   {
474     OsiVolSolverInterface volSi;
475     testingMessage( "Testing CglProbing with OsiVolSolverInterface\n" );
476     CglProbingUnitTest(&volSi,mpsDir);
477   }
478   if(0) // Throw CoinError since solver can not handle infinite bounds
479   {
480     OsiVolSolverInterface volSi;
481     testingMessage( "Testing CglMixedIntegerRounding with OsiVolSolverInterface\n" );
482     CglMixedIntegerRoundingUnitTest(&volSi, testDir);
483   }
484   if(0) // Throw CoinError since solver can not handle infinite bounds
485   {
486     OsiVolSolverInterface volSi;
487     testingMessage( "Testing CglMixedIntegerRounding2 with OsiVolSolverInterface\n" );
488     CglMixedIntegerRounding2UnitTest(&volSi, testDir);
489   }
490   if(0) // Throw CoinError since solver can not handle infinite bounds
491   {
492     OsiVolSolverInterface volSi;
493     testingMessage( "Testing CglResidualCapacity with OsiVolSolverInterface\n" );
494     CglResidualCapacityUnitTest(&volSi, testDir);
495   }
496   if(0) // Throw CoinError since solver can not handle infinite bounds
497   {
498     OsiVolSolverInterface volSi;
499     testingMessage( "Testing CglTwomir with OsiVolSolverInterface\n" );
500     CglTwomirUnitTest(&volSi, testDir);
501   }
502   if(0) // No cuts found
503   {
504     OsiVolSolverInterface volSi;
505     testingMessage( "Testing CglClique with OsiVolSolverInterface\n" );
506     CglCliqueUnitTest(&volSi, testDir);
507   }
508   if(0) // Throw CoinError since solver can not handle infinite bounds
509   {
510     OsiVolSolverInterface volSi;
511     testingMessage( "Testing CglFlowCover with OsiVolSolverInterface\n" );
512     CglFlowCoverUnitTest(&volSi, testDir);
513   }
514 
515 #endif
516 
517   testingMessage( "All tests completed successfully\n" );
518   return 0;
519 }
520 
521 
522 // Display message on stdout and stderr
testingMessage(const char * const msg)523 void testingMessage( const char * const msg )
524 {
525   std::cout <<std::endl <<"*****************************************"
526             <<std::endl <<msg <<std::endl;
527   //std::cerr <<msg;
528 }
529 
530