source: branches/devel-1/Test/unitTest.cpp @ 26

Last change on this file since 26 was 26, checked in by forrest, 18 years ago

Taking out dependence on CoinWarmStartBasis?

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 33.1 KB
Line 
1// Copyright (C) 2002, International Business Machines
2// Corporation and others.  All Rights Reserved.
3#if defined(_MSC_VER)
4// Turn off compiler warning about long names
5#  pragma warning(disable:4786)
6#endif
7
8#include <cassert>
9#include <cstdio>
10#include <cmath>
11#include <cfloat>
12#include <string>
13#include <iostream>
14
15#include <time.h>
16#include <sys/times.h>
17#include <sys/resource.h>
18#include <unistd.h>
19
20#include "CoinMpsIO.hpp"
21#include "CoinPackedMatrix.hpp"
22#include "CoinPackedVector.hpp"
23#include "CoinHelperFunctions.hpp"
24
25#include "ClpFactorization.hpp"
26#include "ClpSimplex.hpp"
27#include "ClpDualRowSteepest.hpp"
28#include "ClpDualRowDantzig.hpp"
29#include "ClpPrimalColumnSteepest.hpp"
30#include "ClpPrimalColumnDantzig.hpp"
31#include "ClpParameters.hpp"
32
33//#############################################################################
34
35#ifdef NDEBUG
36#undef NDEBUG
37#endif
38
39// Function Prototypes. Function definitions is in this file.
40void testingMessage( const char * const msg );
41
42//----------------------------------------------------------------
43// unitTest [-mpsDir=V1] [-netlibDir=V2] [-netlib]
44//
45// where:
46//   -mpsDir: directory containing mps test files
47//       Default value V1="../Mps/Sample"   
48//   -netlibDir: directory containing netlib files
49//       Default value V2="../Mps/Netlib"
50//   -netlib
51//       If specified, then netlib test set run
52//
53// All parameters are optional.
54//----------------------------------------------------------------
55
56int mainTest (int argc, const char *argv[],bool doDual,
57              ClpSimplex empty)
58{
59  int i;
60
61  // define valid parameter keywords
62  std::set<std::string> definedKeyWords;
63  definedKeyWords.insert("-mpsDir");
64  definedKeyWords.insert("-netlibDir");
65  definedKeyWords.insert("-netlib");
66
67  // Create a map of parameter keys and associated data
68  std::map<std::string,std::string> parms;
69  for ( i=1; i<argc; i++ ) {
70    std::string parm(argv[i]);
71    std::string key,value;
72    unsigned int  eqPos = parm.find('=');
73
74    // Does parm contain and '='
75    if ( eqPos==std::string::npos ) {
76      //Parm does not contain '='
77      key = parm;
78    }
79    else {
80      key=parm.substr(0,eqPos);
81      value=parm.substr(eqPos+1);
82    }
83
84    // Is specifed key valid?
85    if ( definedKeyWords.find(key) == definedKeyWords.end() ) {
86      // invalid key word.
87      // Write help text
88      std::cerr <<"Undefined parameter \"" <<key <<"\".\n";
89      std::cerr <<"Correct usage: \n";
90      std::cerr <<"  unitTest [-mpsDir=V1] [-netlibDir=V2] [-netlib]\n";
91      std::cerr <<"  where:\n";
92      std::cerr <<"    -mpsDir: directory containing mps test files\n";
93      std::cerr <<"        Default value V1=\"../Mps/Sample\"\n";
94      std::cerr <<"    -netlibDir: directory containing netlib files\n";
95      std::cerr <<"        Default value V2=\"../Mps/Netlib\"\n";
96      std::cerr <<"    -netlib\n";
97      std::cerr <<"        If specified, then netlib testset run.\n";
98      return 1;
99    }
100    parms[key]=value;
101  }
102 
103  const char dirsep =  CoinFindDirSeparator();
104  // Set directory containing mps data files.
105  std::string mpsDir;
106  if (parms.find("-mpsDir") != parms.end())
107    mpsDir=parms["-mpsDir"] + dirsep;
108  else 
109    mpsDir = dirsep == '/' ? "../Mps/Sample/" : "..\\Mps\\Sample\\";
110 
111  // Set directory containing netlib data files.
112  std::string netlibDir;
113  if (parms.find("-netlibDir") != parms.end())
114    netlibDir=parms["-netlibDir"] + dirsep;
115  else 
116    netlibDir = dirsep == '/' ? "../Mps/Netlib/" : "..\\Mps\\Netlib\\";
117
118  testingMessage( "Testing ClpSimplex\n" );
119  ClpSimplexUnitTest(mpsDir,netlibDir);
120  if (parms.find("-netlib") != parms.end())
121  {
122    unsigned int m;
123   
124    // Define test problems:
125    //   mps names,
126    //   maximization or minimization,
127    //   Number of rows and columns in problem, and
128    //   objective function value
129    std::vector<std::string> mpsName;
130    std::vector<bool> min;
131    std::vector<int> nRows;
132    std::vector<int> nCols;
133    std::vector<double> objValue;
134    std::vector<double> objValueTol;
135    mpsName.push_back("25fv47");
136    min.push_back(true);
137    nRows.push_back(822);
138    nCols.push_back(1571);
139    objValueTol.push_back(1.E-10);
140    objValue.push_back(5.5018458883E+03);
141
142#if 1
143    mpsName.push_back("blend");min.push_back(true);nRows.push_back(75);nCols.push_back(83);objValueTol.push_back(1.e-10);objValue.push_back(-3.0812149846e+01);
144    mpsName.push_back("pilotnov");min.push_back(true);nRows.push_back(976);nCols.push_back(2172);objValueTol.push_back(1.e-10);objValue.push_back(-4.4972761882e+03);
145    mpsName.push_back("maros-r7");min.push_back(true);nRows.push_back(3137);nCols.push_back(9408);objValueTol.push_back(1.e-10);objValue.push_back(1.4971851665e+06);
146   
147    mpsName.push_back("pilot");min.push_back(true);nRows.push_back(1442);nCols.push_back(3652);objValueTol.push_back(1.e-5);objValue.push_back(/*-5.5740430007e+02*/-557.48972927292);
148    mpsName.push_back("pilot4");min.push_back(true);nRows.push_back(411);nCols.push_back(1000);objValueTol.push_back(1.e-8);objValue.push_back(-2.5811392641e+03);
149    mpsName.push_back("pilot87");min.push_back(true);nRows.push_back(2031);nCols.push_back(4883);objValueTol.push_back(1.e-4);objValue.push_back(3.0171072827e+02);
150    mpsName.push_back("80bau3b");min.push_back(true);nRows.push_back(2263);nCols.push_back(9799);objValueTol.push_back(1.e-10);objValue.push_back(9.8722419241E+05);
151    mpsName.push_back("adlittle");min.push_back(true);nRows.push_back(57);nCols.push_back(97);objValueTol.push_back(1.e-10);objValue.push_back(2.2549496316e+05);
152    mpsName.push_back("afiro");min.push_back(true);nRows.push_back(28);nCols.push_back(32);objValueTol.push_back(1.e-10);objValue.push_back(-4.6475314286e+02);
153    mpsName.push_back("agg");min.push_back(true);nRows.push_back(489);nCols.push_back(163);objValueTol.push_back(1.e-10);objValue.push_back(-3.5991767287e+07);
154    mpsName.push_back("agg2");min.push_back(true);nRows.push_back(517);nCols.push_back(302);objValueTol.push_back(1.e-10);objValue.push_back(-2.0239252356e+07);
155    mpsName.push_back("agg3");min.push_back(true);nRows.push_back(517);nCols.push_back(302);objValueTol.push_back(1.e-10);objValue.push_back(1.0312115935e+07);
156    mpsName.push_back("bandm");min.push_back(true);nRows.push_back(306);nCols.push_back(472);objValueTol.push_back(1.e-10);objValue.push_back(-1.5862801845e+02);
157    mpsName.push_back("beaconfd");min.push_back(true);nRows.push_back(174);nCols.push_back(262);objValueTol.push_back(1.e-10);objValue.push_back(3.3592485807e+04);
158    mpsName.push_back("bnl1");min.push_back(true);nRows.push_back(644);nCols.push_back(1175);objValueTol.push_back(1.e-10);objValue.push_back(1.9776295615E+03);
159    mpsName.push_back("bnl2");min.push_back(true);nRows.push_back(2325);nCols.push_back(3489);objValueTol.push_back(1.e-10);objValue.push_back(1.8112365404e+03);
160    mpsName.push_back("boeing1");min.push_back(true);nRows.push_back(/*351*/352);nCols.push_back(384);objValueTol.push_back(1.e-10);objValue.push_back(-3.3521356751e+02);
161    mpsName.push_back("boeing2");min.push_back(true);nRows.push_back(167);nCols.push_back(143);objValueTol.push_back(1.e-10);objValue.push_back(-3.1501872802e+02);
162    mpsName.push_back("bore3d");min.push_back(true);nRows.push_back(234);nCols.push_back(315);objValueTol.push_back(1.e-10);objValue.push_back(1.3730803942e+03);
163    mpsName.push_back("brandy");min.push_back(true);nRows.push_back(221);nCols.push_back(249);objValueTol.push_back(1.e-10);objValue.push_back(1.5185098965e+03);
164    mpsName.push_back("capri");min.push_back(true);nRows.push_back(272);nCols.push_back(353);objValueTol.push_back(1.e-10);objValue.push_back(2.6900129138e+03);
165    mpsName.push_back("cycle");min.push_back(true);nRows.push_back(1904);nCols.push_back(2857);objValueTol.push_back(1.e-9);objValue.push_back(-5.2263930249e+00);
166    mpsName.push_back("czprob");min.push_back(true);nRows.push_back(930);nCols.push_back(3523);objValueTol.push_back(1.e-10);objValue.push_back(2.1851966989e+06);
167    mpsName.push_back("d2q06c");min.push_back(true);nRows.push_back(2172);nCols.push_back(5167);objValueTol.push_back(1.e-7);objValue.push_back(122784.21557456);
168    mpsName.push_back("d6cube");min.push_back(true);nRows.push_back(416);nCols.push_back(6184);objValueTol.push_back(1.e-7);objValue.push_back(3.1549166667e+02);
169    mpsName.push_back("degen2");min.push_back(true);nRows.push_back(445);nCols.push_back(534);objValueTol.push_back(1.e-10);objValue.push_back(-1.4351780000e+03);
170    mpsName.push_back("degen3");min.push_back(true);nRows.push_back(1504);nCols.push_back(1818);objValueTol.push_back(1.e-10);objValue.push_back(-9.8729400000e+02);
171    mpsName.push_back("dfl001");min.push_back(true);nRows.push_back(6072);nCols.push_back(12230);objValueTol.push_back(1.e-5);objValue.push_back(1.1266396047E+07);
172    mpsName.push_back("e226");min.push_back(true);nRows.push_back(224);nCols.push_back(282);objValueTol.push_back(1.e-10);objValue.push_back(-1.8751929066e+01+7.113); // The correct answer includes -7.113 term. This is a constant in the objective function. See line 1683 of the mps file.
173    mpsName.push_back("etamacro");min.push_back(true);nRows.push_back(401);nCols.push_back(688);objValueTol.push_back(1.e-6);objValue.push_back(-7.5571521774e+02 );
174    mpsName.push_back("fffff800");min.push_back(true);nRows.push_back(525);nCols.push_back(854);objValueTol.push_back(1.e-6);objValue.push_back(5.5567961165e+05);
175    mpsName.push_back("finnis");min.push_back(true);nRows.push_back(498);nCols.push_back(614);objValueTol.push_back(1.e-6);objValue.push_back(1.7279096547e+05);
176    mpsName.push_back("fit1d");min.push_back(true);nRows.push_back(25);nCols.push_back(1026);objValueTol.push_back(1.e-10);objValue.push_back(-9.1463780924e+03);
177    mpsName.push_back("fit1p");min.push_back(true);nRows.push_back(628);nCols.push_back(1677);objValueTol.push_back(1.e-10);objValue.push_back(9.1463780924e+03);
178    mpsName.push_back("fit2d");min.push_back(true);nRows.push_back(26);nCols.push_back(10500);objValueTol.push_back(1.e-10);objValue.push_back(-6.8464293294e+04);
179    mpsName.push_back("fit2p");min.push_back(true);nRows.push_back(3001);nCols.push_back(13525);objValueTol.push_back(1.e-9);objValue.push_back(6.8464293232e+04);
180    mpsName.push_back("forplan");min.push_back(true);nRows.push_back(162);nCols.push_back(421);objValueTol.push_back(1.e-6);objValue.push_back(-6.6421873953e+02);
181    mpsName.push_back("ganges");min.push_back(true);nRows.push_back(1310);nCols.push_back(1681);objValueTol.push_back(1.e-5);objValue.push_back(-1.0958636356e+05);
182    mpsName.push_back("gfrd-pnc");min.push_back(true);nRows.push_back(617);nCols.push_back(1092);objValueTol.push_back(1.e-10);objValue.push_back(6.9022359995e+06);
183#endif
184    mpsName.push_back("greenbea");min.push_back(true);nRows.push_back(2393);nCols.push_back(5405);objValueTol.push_back(1.e-10);objValue.push_back(/*-7.2462405908e+07*/-72555248.129846);
185    mpsName.push_back("greenbeb");min.push_back(true);nRows.push_back(2393);nCols.push_back(5405);objValueTol.push_back(1.e-10);objValue.push_back(/*-4.3021476065e+06*/-4302260.2612066);
186    mpsName.push_back("grow15");min.push_back(true);nRows.push_back(301);nCols.push_back(645);objValueTol.push_back(1.e-10);objValue.push_back(-1.0687094129e+08);
187    mpsName.push_back("grow22");min.push_back(true);nRows.push_back(441);nCols.push_back(946);objValueTol.push_back(1.e-10);objValue.push_back(-1.6083433648e+08);
188    mpsName.push_back("grow7");min.push_back(true);nRows.push_back(141);nCols.push_back(301);objValueTol.push_back(1.e-10);objValue.push_back(-4.7787811815e+07);
189    mpsName.push_back("israel");min.push_back(true);nRows.push_back(175);nCols.push_back(142);objValueTol.push_back(1.e-10);objValue.push_back(-8.9664482186e+05);
190    mpsName.push_back("kb2");min.push_back(true);nRows.push_back(44);nCols.push_back(41);objValueTol.push_back(1.e-10);objValue.push_back(-1.7499001299e+03);
191    mpsName.push_back("lotfi");min.push_back(true);nRows.push_back(154);nCols.push_back(308);objValueTol.push_back(1.e-10);objValue.push_back(-2.5264706062e+01);
192    mpsName.push_back("maros");min.push_back(true);nRows.push_back(847);nCols.push_back(1443);objValueTol.push_back(1.e-10);objValue.push_back(-5.8063743701e+04);
193    mpsName.push_back("modszk1");min.push_back(true);nRows.push_back(688);nCols.push_back(1620);objValueTol.push_back(1.e-10);objValue.push_back(3.2061972906e+02);
194    mpsName.push_back("nesm");min.push_back(true);nRows.push_back(663);nCols.push_back(2923);objValueTol.push_back(1.e-5);objValue.push_back(1.4076073035e+07);
195    mpsName.push_back("perold");min.push_back(true);nRows.push_back(626);nCols.push_back(1376);objValueTol.push_back(1.e-6);objValue.push_back(-9.3807580773e+03);
196    //mpsName.push_back("qap12");min.push_back(true);nRows.push_back(3193);nCols.push_back(8856);objValueTol.push_back(1.e-6);objValue.push_back(5.2289435056e+02);
197    //mpsName.push_back("qap15");min.push_back(true);nRows.push_back(6331);nCols.push_back(22275);objValueTol.push_back(1.e-10);objValue.push_back(1.0409940410e+03);
198    mpsName.push_back("recipe");min.push_back(true);nRows.push_back(92);nCols.push_back(180);objValueTol.push_back(1.e-10);objValue.push_back(-2.6661600000e+02);
199    mpsName.push_back("sc105");min.push_back(true);nRows.push_back(106);nCols.push_back(103);objValueTol.push_back(1.e-10);objValue.push_back(-5.2202061212e+01);
200    mpsName.push_back("sc205");min.push_back(true);nRows.push_back(206);nCols.push_back(203);objValueTol.push_back(1.e-10);objValue.push_back(-5.2202061212e+01);
201    mpsName.push_back("sc50a");min.push_back(true);nRows.push_back(51);nCols.push_back(48);objValueTol.push_back(1.e-10);objValue.push_back(-6.4575077059e+01);
202    mpsName.push_back("sc50b");min.push_back(true);nRows.push_back(51);nCols.push_back(48);objValueTol.push_back(1.e-10);objValue.push_back(-7.0000000000e+01);
203    mpsName.push_back("scagr25");min.push_back(true);nRows.push_back(472);nCols.push_back(500);objValueTol.push_back(1.e-10);objValue.push_back(-1.4753433061e+07);
204    mpsName.push_back("scagr7");min.push_back(true);nRows.push_back(130);nCols.push_back(140);objValueTol.push_back(1.e-6);objValue.push_back(-2.3313892548e+06);
205    mpsName.push_back("scfxm1");min.push_back(true);nRows.push_back(331);nCols.push_back(457);objValueTol.push_back(1.e-10);objValue.push_back(1.8416759028e+04);
206    mpsName.push_back("scfxm2");min.push_back(true);nRows.push_back(661);nCols.push_back(914);objValueTol.push_back(1.e-10);objValue.push_back(3.6660261565e+04);
207    mpsName.push_back("scfxm3");min.push_back(true);nRows.push_back(991);nCols.push_back(1371);objValueTol.push_back(1.e-10);objValue.push_back(5.4901254550e+04);
208    mpsName.push_back("scorpion");min.push_back(true);nRows.push_back(389);nCols.push_back(358);objValueTol.push_back(1.e-10);objValue.push_back(1.8781248227e+03);
209    mpsName.push_back("scrs8");min.push_back(true);nRows.push_back(491);nCols.push_back(1169);objValueTol.push_back(1.e-5);objValue.push_back(9.0429998619e+02);
210    mpsName.push_back("scsd1");min.push_back(true);nRows.push_back(78);nCols.push_back(760);objValueTol.push_back(1.e-10);objValue.push_back(8.6666666743e+00);
211    mpsName.push_back("scsd6");min.push_back(true);nRows.push_back(148);nCols.push_back(1350);objValueTol.push_back(1.e-10);objValue.push_back(5.0500000078e+01);
212    mpsName.push_back("scsd8");min.push_back(true);nRows.push_back(398);nCols.push_back(2750);objValueTol.push_back(1.e-10);objValue.push_back(9.0499999993e+02);
213    mpsName.push_back("sctap1");min.push_back(true);nRows.push_back(301);nCols.push_back(480);objValueTol.push_back(1.e-10);objValue.push_back(1.4122500000e+03);
214    mpsName.push_back("sctap2");min.push_back(true);nRows.push_back(1091);nCols.push_back(1880);objValueTol.push_back(1.e-10);objValue.push_back(1.7248071429e+03);
215    mpsName.push_back("sctap3");min.push_back(true);nRows.push_back(1481);nCols.push_back(2480);objValueTol.push_back(1.e-10);objValue.push_back(1.4240000000e+03);
216    mpsName.push_back("seba");min.push_back(true);nRows.push_back(516);nCols.push_back(1028);objValueTol.push_back(1.e-10);objValue.push_back(1.5711600000e+04);
217    mpsName.push_back("share1b");min.push_back(true);nRows.push_back(118);nCols.push_back(225);objValueTol.push_back(1.e-10);objValue.push_back(-7.6589318579e+04);
218    mpsName.push_back("share2b");min.push_back(true);nRows.push_back(97);nCols.push_back(79);objValueTol.push_back(1.e-10);objValue.push_back(-4.1573224074e+02);
219    mpsName.push_back("shell");min.push_back(true);nRows.push_back(537);nCols.push_back(1775);objValueTol.push_back(1.e-10);objValue.push_back(1.2088253460e+09);
220    mpsName.push_back("ship04l");min.push_back(true);nRows.push_back(403);nCols.push_back(2118);objValueTol.push_back(1.e-10);objValue.push_back(1.7933245380e+06);
221    mpsName.push_back("ship04s");min.push_back(true);nRows.push_back(403);nCols.push_back(1458);objValueTol.push_back(1.e-10);objValue.push_back(1.7987147004e+06);
222    mpsName.push_back("ship08l");min.push_back(true);nRows.push_back(779);nCols.push_back(4283);objValueTol.push_back(1.e-10);objValue.push_back(1.9090552114e+06);
223    mpsName.push_back("ship08s");min.push_back(true);nRows.push_back(779);nCols.push_back(2387);objValueTol.push_back(1.e-10);objValue.push_back(1.9200982105e+06);
224    mpsName.push_back("ship12l");min.push_back(true);nRows.push_back(1152);nCols.push_back(5427);objValueTol.push_back(1.e-10);objValue.push_back(1.4701879193e+06);
225    mpsName.push_back("ship12s");min.push_back(true);nRows.push_back(1152);nCols.push_back(2763);objValueTol.push_back(1.e-10);objValue.push_back(1.4892361344e+06);
226    mpsName.push_back("sierra");min.push_back(true);nRows.push_back(1228);nCols.push_back(2036);objValueTol.push_back(1.e-10);objValue.push_back(1.5394362184e+07);
227    mpsName.push_back("stair");min.push_back(true);nRows.push_back(357);nCols.push_back(467);objValueTol.push_back(1.e-10);objValue.push_back(-2.5126695119e+02);
228    mpsName.push_back("standata");min.push_back(true);nRows.push_back(360);nCols.push_back(1075);objValueTol.push_back(1.e-10);objValue.push_back(1.2576995000e+03);
229    //mpsName.push_back("standgub");min.push_back(true);nRows.push_back(362);nCols.push_back(1184);objValueTol.push_back(1.e-10);objValue.push_back(1257.6995);
230    mpsName.push_back("standmps");min.push_back(true);nRows.push_back(468);nCols.push_back(1075);objValueTol.push_back(1.e-10);objValue.push_back(1.4060175000E+03); 
231    mpsName.push_back("stocfor1");min.push_back(true);nRows.push_back(118);nCols.push_back(111);objValueTol.push_back(1.e-10);objValue.push_back(-4.1131976219E+04);
232    mpsName.push_back("stocfor2");min.push_back(true);nRows.push_back(2158);nCols.push_back(2031);objValueTol.push_back(1.e-10);objValue.push_back(-3.9024408538e+04);
233    //mpsName.push_back("stocfor3");min.push_back(true);nRows.push_back(16676);nCols.push_back(15695);objValueTol.push_back(1.e-10);objValue.push_back(-3.9976661576e+04);
234    //mpsName.push_back("truss");min.push_back(true);nRows.push_back(1001);nCols.push_back(8806);objValueTol.push_back(1.e-10);objValue.push_back(4.5881584719e+05);
235    mpsName.push_back("tuff");min.push_back(true);nRows.push_back(334);nCols.push_back(587);objValueTol.push_back(1.e-10);objValue.push_back(2.9214776509e-01);
236    mpsName.push_back("vtpbase");min.push_back(true);nRows.push_back(199);nCols.push_back(203);objValueTol.push_back(1.e-10);objValue.push_back(1.2983146246e+05);
237    mpsName.push_back("wood1p");min.push_back(true);nRows.push_back(245);nCols.push_back(2594);objValueTol.push_back(1.e-10);objValue.push_back(1.4429024116e+00);
238    mpsName.push_back("woodw");min.push_back(true);nRows.push_back(1099);nCols.push_back(8405);objValueTol.push_back(1.e-10);objValue.push_back(1.3044763331E+00);
239  // Loop once for each Mps File
240    for (m=0; m<mpsName.size(); m++ ) {
241      std::cerr <<"  processing mps file: " <<mpsName[m] 
242                <<" (" <<m+1 <<" out of " <<mpsName.size() <<")" <<std::endl;
243   
244      // Read data mps file,
245      std::string fn = netlibDir+mpsName[m];
246      CoinMpsIO mps;
247      mps.readMps(fn.c_str(),"mps");
248      ClpSimplex solution=empty;
249      solution.loadProblem(*mps.getMatrixByCol(),mps.getColLower(),
250                           mps.getColUpper(),
251                           mps.getObjCoefficients(),
252                           mps.getRowLower(),mps.getRowUpper());
253
254      if (doDual) {
255#if 0
256        solution.scaling(1);
257        solution.setDualBound(1.0e6);
258        solution.setDualTolerance(1.0e-7);
259        // set objective sense,
260        if(min[m])
261          solution.setOptimizationDirection(1);
262        else       
263          solution.setOptimizationDirection(-1);
264        ClpDualRowSteepest steep;
265        solution.setDualRowPivotAlgorithm(steep);
266#endif
267        solution.setDblParam(ClpObjOffset,mps.objectiveOffset());
268        solution.dual();
269      } else {
270#if 0
271        solution.setPrimalTolerance(1.0e-8);
272        solution.scaling(1);
273        ClpPrimalColumnSteepest steep;
274        solution.setPrimalColumnPivotAlgorithm(steep);
275        // set objective sense,
276        if(min[m])
277          solution.setOptimizationDirection(1);
278        else       
279          solution.setOptimizationDirection(-1);
280        solution.setInfeasibilityCost(1.0e6);
281#endif
282        solution.setDblParam(ClpObjOffset,mps.objectiveOffset());
283        solution.primal();
284      }
285      // Test objective solution value
286      {
287        double soln = solution.objectiveValue();
288        CoinRelFltEq eq(objValueTol[m]);
289        std::cerr <<soln <<",  " <<objValue[m] <<" diff "<<
290          soln-objValue[m]<<std::endl;
291        if(!eq(soln,objValue[m]))
292          printf("** difference fails\n");
293      }
294    }
295   
296  }
297  else {
298    testingMessage( "***Skipped Testing on netlib    ***\n" );
299    testingMessage( "***use -netlib to test class***\n" );
300  }
301
302  testingMessage( "All tests completed successfully\n" );
303  return 0;
304}
305
306 
307// Display message on stdout and stderr
308void testingMessage( const char * const msg )
309{
310  std::cerr <<msg;
311  //cout <<endl <<"*****************************************"
312  //     <<endl <<msg <<endl;
313}
314
315//--------------------------------------------------------------------------
316// test factorization methods and simplex method
317void
318ClpSimplexUnitTest(const std::string & mpsDir,
319                   const std::string & netlibDir)
320{
321 
322  CoinRelFltEq eq(0.000001);
323
324  {
325    ClpSimplex solution;
326 
327    // matrix data
328    //deliberate hiccup of 2 between 0 and 1
329    int start[5]={0,4,7,8,9};
330    int length[5]={2,3,1,1,1};
331    int rows[11]={0,2,-1,-1,0,1,2,0,1,2};
332    double elements[11]={7.0,2.0,1.0e10,1.0e10,-2.0,1.0,-2.0,1,1,1};
333    CoinPackedMatrix matrix(true,3,5,8,elements,rows,start,length);
334   
335    // rim data
336    double objective[7]={-4.0,1.0,0.0,0.0,0.0,0.0,0.0};
337    double rowLower[5]={14.0,3.0,3.0,1.0e10,1.0e10};
338    double rowUpper[5]={14.0,3.0,3.0,-1.0e10,-1.0e10};
339    double colLower[7]={0.0,0.0,0.0,0.0,0.0,0.0,0.0};
340    double colUpper[7]={100.0,100.0,100.0,100.0,100.0,100.0,100.0};
341   
342    // basis 1
343    int rowBasis1[3]={-1,-1,-1};
344    int colBasis1[5]={1,1,-1,-1,1};
345    solution.loadProblem(matrix,colLower,colUpper,objective,
346                         rowLower,rowUpper);
347    int i;
348    solution.createStatus();
349    for (i=0;i<3;i++) {
350      if (rowBasis1[i]<0) {
351        solution.setRowStatus(i,ClpSimplex::atLowerBound);
352      } else {
353        solution.setRowStatus(i,ClpSimplex::basic);
354      }
355    }
356    for (i=0;i<5;i++) {
357      if (colBasis1[i]<0) {
358        solution.setColumnStatus(i,ClpSimplex::atLowerBound);
359      } else {
360        solution.setColumnStatus(i,ClpSimplex::basic);
361      }
362    }
363    solution.setLogLevel(3+4+8+16+32);
364    solution.primal();
365    for (i=0;i<3;i++) {
366      if (rowBasis1[i]<0) {
367        solution.setRowStatus(i,ClpSimplex::atLowerBound);
368      } else {
369        solution.setRowStatus(i,ClpSimplex::basic);
370      }
371    }
372    for (i=0;i<5;i++) {
373      if (colBasis1[i]<0) {
374        solution.setColumnStatus(i,ClpSimplex::atLowerBound);
375      } else {
376        solution.setColumnStatus(i,ClpSimplex::basic);
377      }
378    }
379    // intricate stuff does not work with scaling
380    solution.scaling(0);
381    assert(!solution.factorize ( ));
382    const double * colsol = solution.primalColumnSolution();
383    const double * rowsol = solution.primalRowSolution();
384    solution.getSolution(rowsol,colsol);
385    double colsol1[5]={20.0/7.0,3.0,0.0,0.0,23.0/7.0};
386    for (i=0;i<5;i++) {
387      assert(eq(colsol[i],colsol1[i]));
388    }
389    // now feed in again without actually doing factorization
390    ClpFactorization factorization2 = *solution.factorization();
391    ClpSimplex solution2 = solution;
392    solution2.setFactorization(factorization2);
393    solution2.createStatus();
394    for (i=0;i<3;i++) {
395      if (rowBasis1[i]<0) {
396        solution2.setRowStatus(i,ClpSimplex::atLowerBound);
397      } else {
398        solution2.setRowStatus(i,ClpSimplex::basic);
399      }
400    }
401    for (i=0;i<5;i++) {
402      if (colBasis1[i]<0) {
403        solution2.setColumnStatus(i,ClpSimplex::atLowerBound);
404      } else {
405        solution2.setColumnStatus(i,ClpSimplex::basic);
406      }
407    }
408    // intricate stuff does not work with scaling
409    solution2.scaling(0);
410    solution2.getSolution(rowsol,colsol);
411    colsol = solution2.primalColumnSolution();
412    rowsol = solution2.primalRowSolution();
413    for (i=0;i<5;i++) {
414      assert(eq(colsol[i],colsol1[i]));
415    }
416    solution2.setDualBound(0.1);
417    solution2.dual();
418    objective[2]=-1.0;
419    objective[3]=-0.5;
420    objective[4]=10.0;
421    solution.dual();
422    for (i=0;i<3;i++) {
423      rowLower[i]=-1.0e50;
424      colUpper[i+2]=0.0;
425    }
426    solution.setLogLevel(3);
427    solution.dual();
428    double rowObjective[]={1.0,0.5,-10.0};
429    solution.loadProblem(matrix,colLower,colUpper,objective,
430                         rowLower,rowUpper,rowObjective);
431    solution.dual();
432  }
433  {   
434    CoinMpsIO m;
435    std::string fn = mpsDir+"exmip1";
436    m.readMps(fn.c_str(),"mps");
437    ClpSimplex solution;
438    solution.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(),
439                         m.getObjCoefficients(),
440                         m.getRowLower(),m.getRowUpper());
441    solution.dual();
442  }
443  // test steepest edge
444  {   
445    CoinMpsIO m;
446    std::string fn = netlibDir+"finnis";
447    m.readMps(fn.c_str(),"mps");
448    ClpModel model;
449    model.loadProblem(*m.getMatrixByCol(),m.getColLower(),
450                    m.getColUpper(),
451                    m.getObjCoefficients(),
452                    m.getRowLower(),m.getRowUpper());
453    ClpSimplex solution(model);
454
455    solution.scaling(1); 
456    solution.setDualBound(1.0e8);
457    //solution.factorization()->maximumPivots(1);
458    //solution.setLogLevel(3);
459    solution.setDualTolerance(1.0e-7);
460    // set objective sense,
461    ClpDualRowSteepest steep;
462    solution.setDualRowPivotAlgorithm(steep);
463    solution.setDblParam(ClpObjOffset,m.objectiveOffset());
464    solution.dual();
465  }
466  // test normal solution
467  {   
468    CoinMpsIO m;
469    std::string fn = netlibDir+"afiro";
470    m.readMps(fn.c_str(),"mps");
471    ClpSimplex solution;
472    ClpModel model;
473    // do twice - without and with scaling
474    int iPass;
475    for (iPass=0;iPass<2;iPass++) {
476      // explicit row objective for testing
477      int nr = m.getNumRows();
478      double * rowObj = new double[nr];
479      CoinFillN(rowObj,nr,0.0);
480      model.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(),
481                      m.getObjCoefficients(),
482                      m.getRowLower(),m.getRowUpper(),rowObj);
483      delete [] rowObj;
484      solution = ClpSimplex(model);
485      if (iPass) {
486        solution.scaling();
487      }
488      solution.dual();
489      solution.dual();
490      // test optimal
491      assert (solution.status()==0);
492      int numberColumns = solution.numberColumns();
493      int numberRows = solution.numberRows();
494      CoinPackedVector colsol(numberColumns,solution.primalColumnSolution());
495      double * objective = solution.objective();
496      double objValue = colsol.dotProduct(objective);
497      CoinRelFltEq eq(1.0e-8);
498      assert(eq(objValue,-4.6475314286e+02));
499      double * lower = solution.columnLower();
500      double * upper = solution.columnUpper();
501      double * sol = solution.primalColumnSolution();
502      double * result = new double[numberColumns];
503      CoinFillN ( result, numberColumns,0.0);
504      solution.matrix()->transposeTimes(solution.dualRowSolution(), result);
505      int iRow , iColumn;
506      // see if feasible and dual feasible
507      for (iColumn=0;iColumn<numberColumns;iColumn++) {
508        double value = sol[iColumn];
509        assert(value<upper[iColumn]+1.0e-8);
510        assert(value>lower[iColumn]-1.0e-8);
511        value = objective[iColumn]-result[iColumn];
512        assert (value>-1.0e-5);
513        if (sol[iColumn]>1.0e-5)
514          assert (value<1.0e-5);
515      }
516      delete [] result;
517      result = new double[numberRows];
518      CoinFillN ( result, numberRows,0.0);
519      solution.matrix()->times(colsol, result);
520      lower = solution.rowLower();
521      upper = solution.rowUpper();
522      sol = solution.primalRowSolution();
523      for (iRow=0;iRow<numberRows;iRow++) {
524        double value = result[iRow];
525        assert(eq(value,sol[iRow]));
526        assert(value<upper[iRow]+1.0e-8);
527        assert(value>lower[iRow]-1.0e-8);
528      }
529      delete [] result;
530      // test row objective
531      double * rowObjective = solution.rowObjective();
532      CoinDisjointCopyN(solution.dualRowSolution(),numberRows,rowObjective);
533      CoinDisjointCopyN(solution.dualColumnSolution(),numberColumns,objective);
534      // this sets up all slack basis
535      solution.createStatus();
536      solution.dual();
537      CoinFillN(rowObjective,numberRows,0.0);
538      CoinDisjointCopyN(m.getObjCoefficients(),numberColumns,objective);
539      solution.dual();
540    }
541  }
542  // test unbounded
543  {   
544    CoinMpsIO m;
545    std::string fn = netlibDir+"brandy";
546    m.readMps(fn.c_str(),"mps");
547    ClpSimplex solution;
548    // do twice - without and with scaling
549    int iPass;
550    for (iPass=0;iPass<2;iPass++) {
551      solution.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(),
552                      m.getObjCoefficients(),
553                      m.getRowLower(),m.getRowUpper());
554      if (iPass)
555        solution.scaling();
556      solution.setOptimizationDirection(-1);
557      // test unbounded and ray
558#ifdef DUAL
559      solution.setDualBound(100.0);
560      solution.dual();
561#else
562      solution.primal();
563#endif
564      assert (solution.status()==2);
565      int numberColumns = solution.numberColumns();
566      int numberRows = solution.numberRows();
567      double * lower = solution.columnLower();
568      double * upper = solution.columnUpper();
569      double * sol = solution.primalColumnSolution();
570      double * ray = solution.unboundedRay();
571      double * objective = solution.objective();
572      double objChange=0.0;
573      int iRow , iColumn;
574      // make sure feasible and columns form ray
575      for (iColumn=0;iColumn<numberColumns;iColumn++) {
576        double value = sol[iColumn];
577        assert(value<upper[iColumn]+1.0e-8);
578        assert(value>lower[iColumn]-1.0e-8);
579        value = ray[iColumn];
580        if (value>0.0)
581          assert(upper[iColumn]>1.0e30);
582        else if (value<0.0)
583          assert(lower[iColumn]<-1.0e30);
584        objChange += value*objective[iColumn];
585      }
586      // make sure increasing objective
587      assert(objChange>0.0);
588      double * result = new double[numberRows];
589      CoinFillN ( result, numberRows,0.0);
590      solution.matrix()->times(sol, result);
591      lower = solution.rowLower();
592      upper = solution.rowUpper();
593      sol = solution.primalRowSolution();
594      for (iRow=0;iRow<numberRows;iRow++) {
595        double value = result[iRow];
596        assert(eq(value,sol[iRow]));
597        assert(value<upper[iRow]+1.0e-8);
598        assert(value>lower[iRow]-1.0e-8);
599      }
600      CoinFillN ( result, numberRows,0.0);
601      solution.matrix()->times(ray, result);
602      // there may be small differences (especially if scaled)
603      for (iRow=0;iRow<numberRows;iRow++) {
604        double value = result[iRow];
605        if (value>1.0e-8)
606          assert(upper[iRow]>1.0e30);
607        else if (value<-1.0e-8)
608          assert(lower[iRow]<-1.0e30);
609      }
610      delete [] result;
611      delete [] ray;
612    }
613  }
614  // test infeasible
615  {   
616    CoinMpsIO m;
617    std::string fn = netlibDir+"brandy";
618    m.readMps(fn.c_str(),"mps");
619    ClpSimplex solution;
620    // do twice - without and with scaling
621    int iPass;
622    for (iPass=0;iPass<2;iPass++) {
623      solution.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(),
624                      m.getObjCoefficients(),
625                      m.getRowLower(),m.getRowUpper());
626      if (iPass)
627        solution.scaling();
628      // test infeasible and ray
629      solution.columnUpper()[0]=0.0;
630#ifdef DUAL
631      solution.setDualBound(100.0);
632      solution.dual();
633#else
634      solution.primal();
635#endif
636      assert (solution.status()==1);
637      int numberColumns = solution.numberColumns();
638      int numberRows = solution.numberRows();
639      double * lower = solution.rowLower();
640      double * upper = solution.rowUpper();
641      double * ray = solution.infeasibilityRay();
642      assert(ray);
643      // construct proof of infeasibility
644      int iRow , iColumn;
645      double lo=0.0,up=0.0;
646      int nl=0,nu=0;
647      for (iRow=0;iRow<numberRows;iRow++) {
648        if (lower[iRow]>-1.0e20) {
649          lo += ray[iRow]*lower[iRow];
650        } else {
651          if (ray[iRow]>1.0e-8) 
652            nl++;
653        }
654        if (upper[iRow]<1.0e20) {
655          up += ray[iRow]*upper[iRow];
656        } else {
657          if (ray[iRow]>1.0e-8) 
658            nu++;
659        }
660      }
661      if (nl)
662        lo=-1.0e100;
663      if (nu)
664        up=1.0e100;
665      double * result = new double[numberColumns];
666      double lo2=0.0,up2=0.0;
667      CoinFillN ( result, numberColumns,0.0);
668      solution.matrix()->transposeTimes(ray, result);
669      lower = solution.columnLower();
670      upper = solution.columnUpper();
671      nl=nu=0;
672      for (iColumn=0;iColumn<numberColumns;iColumn++) {
673        if (result[iColumn]>1.0e-8) {
674          if (lower[iColumn]>-1.0e20)
675            lo2 += result[iColumn]*lower[iColumn];
676          else
677            nl++;
678          if (upper[iColumn]<1.0e20)
679            up2 += result[iColumn]*upper[iColumn];
680          else
681            nu++;
682        } else if (result[iColumn]<-1.0e-8) {
683          if (lower[iColumn]>-1.0e20)
684            up2 += result[iColumn]*lower[iColumn];
685          else
686            nu++;
687          if (upper[iColumn]<1.0e20)
688            lo2 += result[iColumn]*upper[iColumn];
689          else
690            nl++;
691        }
692      }
693      if (nl)
694        lo2=-1.0e100;
695      if (nu)
696        up2=1.0e100;
697      // make sure inconsistency
698      assert(lo2>up||up2<lo);
699      delete [] result;
700      delete [] ray;
701    }
702  }
703 
704}
Note: See TracBrowser for help on using the repository browser.