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

Last change on this file since 22 was 20, checked in by forrest, 17 years ago

Synchronizing

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 32.4 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 "CoinWarmStartBasis.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    int i;
346    CoinWarmStartBasis warm;
347    warm.setSize(5,3);
348    for (i=0;i<3;i++) {
349      if (rowBasis1[i]<0) {
350        warm.setArtifStatus(i,CoinWarmStartBasis::atLowerBound);
351      } else {
352        warm.setArtifStatus(i,CoinWarmStartBasis::basic);
353      }
354    }
355    for (i=0;i<5;i++) {
356      if (colBasis1[i]<0) {
357        warm.setStructStatus(i,CoinWarmStartBasis::atLowerBound);
358      } else {
359        warm.setStructStatus(i,CoinWarmStartBasis::basic);
360      }
361    }
362    solution.loadProblem(matrix,colLower,colUpper,objective,
363                         rowLower,rowUpper);
364    solution.setLogLevel(3+4+8+16+32);
365    solution.primal();
366    // intricate stuff does not work with scaling
367    solution.scaling(0);
368    solution.setBasis(warm);
369    assert(!solution.factorize ( ));
370    const double * colsol = solution.primalColumnSolution();
371    const double * rowsol = solution.primalRowSolution();
372    solution.getSolution(rowsol,colsol);
373    double colsol1[5]={20.0/7.0,3.0,0.0,0.0,23.0/7.0};
374    for (i=0;i<5;i++) {
375      assert(eq(colsol[i],colsol1[i]));
376    }
377    // now feed in again without actually doing factorization
378    ClpFactorization factorization2 = *solution.factorization();
379    ClpSimplex solution2 = solution;
380    solution2.setFactorization(factorization2);
381    solution2.setBasis(warm);
382    // intricate stuff does not work with scaling
383    solution2.scaling(0);
384    solution2.getSolution(rowsol,colsol);
385    colsol = solution2.primalColumnSolution();
386    rowsol = solution2.primalRowSolution();
387    for (i=0;i<5;i++) {
388      assert(eq(colsol[i],colsol1[i]));
389    }
390    solution2.setDualBound(0.1);
391    solution2.dual();
392    objective[2]=-1.0;
393    objective[3]=-0.5;
394    objective[4]=10.0;
395    solution.dual();
396    for (i=0;i<3;i++) {
397      rowLower[i]=-1.0e50;
398      colUpper[i+2]=0.0;
399    }
400    solution.setLogLevel(3);
401    solution.dual();
402    double rowObjective[]={1.0,0.5,-10.0};
403    solution.loadProblem(matrix,colLower,colUpper,objective,
404                         rowLower,rowUpper,rowObjective);
405    solution.dual();
406  }
407  {   
408    CoinMpsIO m;
409    std::string fn = mpsDir+"exmip1";
410    m.readMps(fn.c_str(),"mps");
411    ClpSimplex solution;
412    solution.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(),
413                         m.getObjCoefficients(),
414                         m.getRowLower(),m.getRowUpper());
415    solution.dual();
416  }
417  // test steepest edge
418  {   
419    CoinMpsIO m;
420    std::string fn = netlibDir+"finnis";
421    m.readMps(fn.c_str(),"mps");
422    ClpModel model;
423    model.loadProblem(*m.getMatrixByCol(),m.getColLower(),
424                    m.getColUpper(),
425                    m.getObjCoefficients(),
426                    m.getRowLower(),m.getRowUpper());
427    ClpSimplex solution(model);
428
429    solution.scaling(1); 
430    solution.setDualBound(1.0e8);
431    //solution.factorization()->maximumPivots(1);
432    //solution.setLogLevel(3);
433    solution.setDualTolerance(1.0e-7);
434    // set objective sense,
435    ClpDualRowSteepest steep;
436    solution.setDualRowPivotAlgorithm(steep);
437    solution.setDblParam(ClpObjOffset,m.objectiveOffset());
438    solution.dual();
439  }
440  // test normal solution
441  {   
442    CoinMpsIO m;
443    std::string fn = netlibDir+"afiro";
444    m.readMps(fn.c_str(),"mps");
445    ClpSimplex solution;
446    ClpModel model;
447    // do twice - without and with scaling
448    int iPass;
449    for (iPass=0;iPass<2;iPass++) {
450      // explicit row objective for testing
451      int nr = m.getNumRows();
452      double * rowObj = new double[nr];
453      CoinFillN(rowObj,nr,0.0);
454      model.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(),
455                      m.getObjCoefficients(),
456                      m.getRowLower(),m.getRowUpper(),rowObj);
457      delete [] rowObj;
458      solution = ClpSimplex(model);
459      if (iPass) {
460        solution.scaling();
461      }
462      solution.dual();
463      solution.dual();
464      // test optimal
465      assert (solution.status()==0);
466      int numberColumns = solution.numberColumns();
467      int numberRows = solution.numberRows();
468      CoinPackedVector colsol(numberColumns,solution.primalColumnSolution());
469      double * objective = solution.objective();
470      double objValue = colsol.dotProduct(objective);
471      CoinRelFltEq eq(1.0e-8);
472      assert(eq(objValue,-4.6475314286e+02));
473      double * lower = solution.columnLower();
474      double * upper = solution.columnUpper();
475      double * sol = solution.primalColumnSolution();
476      double * result = new double[numberColumns];
477      CoinFillN ( result, numberColumns,0.0);
478      solution.matrix()->transposeTimes(solution.dualRowSolution(), result);
479      int iRow , iColumn;
480      // see if feasible and dual feasible
481      for (iColumn=0;iColumn<numberColumns;iColumn++) {
482        double value = sol[iColumn];
483        assert(value<upper[iColumn]+1.0e-8);
484        assert(value>lower[iColumn]-1.0e-8);
485        value = objective[iColumn]-result[iColumn];
486        assert (value>-1.0e-5);
487        if (sol[iColumn]>1.0e-5)
488          assert (value<1.0e-5);
489      }
490      delete [] result;
491      result = new double[numberRows];
492      CoinFillN ( result, numberRows,0.0);
493      solution.matrix()->times(colsol, result);
494      lower = solution.rowLower();
495      upper = solution.rowUpper();
496      sol = solution.primalRowSolution();
497      for (iRow=0;iRow<numberRows;iRow++) {
498        double value = result[iRow];
499        assert(eq(value,sol[iRow]));
500        assert(value<upper[iRow]+1.0e-8);
501        assert(value>lower[iRow]-1.0e-8);
502      }
503      delete [] result;
504      // test row objective
505      double * rowObjective = solution.rowObjective();
506      CoinDisjointCopyN(solution.dualRowSolution(),numberRows,rowObjective);
507      CoinDisjointCopyN(solution.dualColumnSolution(),numberColumns,objective);
508      CoinWarmStartBasis basis;
509      solution.setBasis(basis);
510      solution.dual();
511      CoinFillN(rowObjective,numberRows,0.0);
512      CoinDisjointCopyN(m.getObjCoefficients(),numberColumns,objective);
513      solution.dual();
514    }
515  }
516  // test unbounded
517  {   
518    CoinMpsIO m;
519    std::string fn = netlibDir+"brandy";
520    m.readMps(fn.c_str(),"mps");
521    ClpSimplex solution;
522    // do twice - without and with scaling
523    int iPass;
524    for (iPass=0;iPass<2;iPass++) {
525      solution.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(),
526                      m.getObjCoefficients(),
527                      m.getRowLower(),m.getRowUpper());
528      if (iPass)
529        solution.scaling();
530      solution.setOptimizationDirection(-1);
531      // test unbounded and ray
532#ifdef DUAL
533      solution.setDualBound(100.0);
534      solution.dual();
535#else
536      solution.primal();
537#endif
538      assert (solution.status()==2);
539      int numberColumns = solution.numberColumns();
540      int numberRows = solution.numberRows();
541      double * lower = solution.columnLower();
542      double * upper = solution.columnUpper();
543      double * sol = solution.primalColumnSolution();
544      double * ray = solution.unboundedRay();
545      double * objective = solution.objective();
546      double objChange=0.0;
547      int iRow , iColumn;
548      // make sure feasible and columns form ray
549      for (iColumn=0;iColumn<numberColumns;iColumn++) {
550        double value = sol[iColumn];
551        assert(value<upper[iColumn]+1.0e-8);
552        assert(value>lower[iColumn]-1.0e-8);
553        value = ray[iColumn];
554        if (value>0.0)
555          assert(upper[iColumn]>1.0e30);
556        else if (value<0.0)
557          assert(lower[iColumn]<-1.0e30);
558        objChange += value*objective[iColumn];
559      }
560      // make sure increasing objective
561      assert(objChange>0.0);
562      double * result = new double[numberRows];
563      CoinFillN ( result, numberRows,0.0);
564      solution.matrix()->times(sol, result);
565      lower = solution.rowLower();
566      upper = solution.rowUpper();
567      sol = solution.primalRowSolution();
568      for (iRow=0;iRow<numberRows;iRow++) {
569        double value = result[iRow];
570        assert(eq(value,sol[iRow]));
571        assert(value<upper[iRow]+1.0e-8);
572        assert(value>lower[iRow]-1.0e-8);
573      }
574      CoinFillN ( result, numberRows,0.0);
575      solution.matrix()->times(ray, result);
576      // there may be small differences (especially if scaled)
577      for (iRow=0;iRow<numberRows;iRow++) {
578        double value = result[iRow];
579        if (value>1.0e-8)
580          assert(upper[iRow]>1.0e30);
581        else if (value<-1.0e-8)
582          assert(lower[iRow]<-1.0e30);
583      }
584      delete [] result;
585      delete [] ray;
586    }
587  }
588  // test infeasible
589  {   
590    CoinMpsIO m;
591    std::string fn = netlibDir+"brandy";
592    m.readMps(fn.c_str(),"mps");
593    ClpSimplex solution;
594    // do twice - without and with scaling
595    int iPass;
596    for (iPass=0;iPass<2;iPass++) {
597      solution.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(),
598                      m.getObjCoefficients(),
599                      m.getRowLower(),m.getRowUpper());
600      if (iPass)
601        solution.scaling();
602      // test infeasible and ray
603      solution.columnUpper()[0]=0.0;
604#ifdef DUAL
605      solution.setDualBound(100.0);
606      solution.dual();
607#else
608      solution.primal();
609#endif
610      assert (solution.status()==1);
611      int numberColumns = solution.numberColumns();
612      int numberRows = solution.numberRows();
613      double * lower = solution.rowLower();
614      double * upper = solution.rowUpper();
615      double * ray = solution.infeasibilityRay();
616      assert(ray);
617      // construct proof of infeasibility
618      int iRow , iColumn;
619      double lo=0.0,up=0.0;
620      int nl=0,nu=0;
621      for (iRow=0;iRow<numberRows;iRow++) {
622        if (lower[iRow]>-1.0e20) {
623          lo += ray[iRow]*lower[iRow];
624        } else {
625          if (ray[iRow]>1.0e-8) 
626            nl++;
627        }
628        if (upper[iRow]<1.0e20) {
629          up += ray[iRow]*upper[iRow];
630        } else {
631          if (ray[iRow]>1.0e-8) 
632            nu++;
633        }
634      }
635      if (nl)
636        lo=-1.0e100;
637      if (nu)
638        up=1.0e100;
639      double * result = new double[numberColumns];
640      double lo2=0.0,up2=0.0;
641      CoinFillN ( result, numberColumns,0.0);
642      solution.matrix()->transposeTimes(ray, result);
643      lower = solution.columnLower();
644      upper = solution.columnUpper();
645      nl=nu=0;
646      for (iColumn=0;iColumn<numberColumns;iColumn++) {
647        if (result[iColumn]>1.0e-8) {
648          if (lower[iColumn]>-1.0e20)
649            lo2 += result[iColumn]*lower[iColumn];
650          else
651            nl++;
652          if (upper[iColumn]<1.0e20)
653            up2 += result[iColumn]*upper[iColumn];
654          else
655            nu++;
656        } else if (result[iColumn]<-1.0e-8) {
657          if (lower[iColumn]>-1.0e20)
658            up2 += result[iColumn]*lower[iColumn];
659          else
660            nu++;
661          if (upper[iColumn]<1.0e20)
662            lo2 += result[iColumn]*upper[iColumn];
663          else
664            nl++;
665        }
666      }
667      if (nl)
668        lo2=-1.0e100;
669      if (nu)
670        up2=1.0e100;
671      // make sure inconsistency
672      assert(lo2>up||up2<lo);
673      delete [] result;
674      delete [] ray;
675    }
676  }
677 
678}
Note: See TracBrowser for help on using the repository browser.