source: trunk/Test/unitTest.cpp @ 2

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

Adding Clp to development branch

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 32.3 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
10#include "ClpFactorization.hpp"
11#include "OsiMpsReader.hpp"
12#include "ClpSimplex.hpp"
13#include "ClpDualRowSteepest.hpp"
14#include "ClpDualRowDantzig.hpp"
15#include "ClpPrimalColumnSteepest.hpp"
16#include "ClpPrimalColumnDantzig.hpp"
17#include "OsiPackedMatrix.hpp"
18#include "OsiPackedVector.hpp"
19#include "OsiWarmStartBasis.hpp"
20#include <stdio.h>
21
22#include <cmath>
23#include <cfloat>
24
25#include <string>
26#include <iostream>
27#include  <time.h>
28#include <sys/times.h>
29#include <sys/resource.h>
30#include <unistd.h>
31
32//#############################################################################
33
34#ifdef NDEBUG
35#undef NDEBUG
36#endif
37
38// Function Prototypes. Function definitions is in this file.
39void testingMessage( const char * const msg );
40
41//----------------------------------------------------------------
42// unitTest [-mpsDir=V1] [-netlibDir=V2] [-netlib]
43//
44// where:
45//   -mpsDir: directory containing mps test files
46//       Default value V1="../Mps/Sample"   
47//   -netlibDir: directory containing netlib files
48//       Default value V2="../Mps/Netlib"
49//   -netlib
50//       If specified, then netlib test set run
51//
52// All parameters are optional.
53//----------------------------------------------------------------
54
55int mainTest (int argc, const char *argv[],bool doDual,
56              ClpSimplex empty)
57{
58  int i;
59
60  // define valid parameter keywords
61  std::set<std::string> definedKeyWords;
62  definedKeyWords.insert("-mpsDir");
63  definedKeyWords.insert("-netlibDir");
64  definedKeyWords.insert("-netlib");
65
66  // Create a map of parameter keys and associated data
67  std::map<std::string,std::string> parms;
68  for ( i=1; i<argc; i++ ) {
69    std::string parm(argv[i]);
70    std::string key,value;
71    unsigned int  eqPos = parm.find('=');
72
73    // Does parm contain and '='
74    if ( eqPos==std::string::npos ) {
75      //Parm does not contain '='
76      key = parm;
77    }
78    else {
79      key=parm.substr(0,eqPos);
80      value=parm.substr(eqPos+1);
81    }
82
83    // Is specifed key valid?
84    if ( definedKeyWords.find(key) == definedKeyWords.end() ) {
85      // invalid key word.
86      // Write help text
87      std::cerr <<"Undefined parameter \"" <<key <<"\".\n";
88      std::cerr <<"Correct usage: \n";
89      std::cerr <<"  unitTest [-mpsDir=V1] [-netlibDir=V2] [-netlib]\n";
90      std::cerr <<"  where:\n";
91      std::cerr <<"    -mpsDir: directory containing mps test files\n";
92      std::cerr <<"        Default value V1=\"../Mps/Sample\"\n";
93      std::cerr <<"    -netlibDir: directory containing netlib files\n";
94      std::cerr <<"        Default value V2=\"../Mps/Netlib\"\n";
95      std::cerr <<"    -netlib\n";
96      std::cerr <<"        If specified, then netlib testset run.\n";
97      return 1;
98    }
99    parms[key]=value;
100  }
101 
102  const char dirsep =  CoinFindDirSeparator();
103  // Set directory containing mps data files.
104  std::string mpsDir;
105  if (parms.find("-mpsDir") != parms.end())
106    mpsDir=parms["-mpsDir"] + dirsep;
107  else 
108    mpsDir = dirsep == '/' ? "../Mps/Sample/" : "..\\Mps\\Sample\\";
109 
110  // Set directory containing netlib data files.
111  std::string netlibDir;
112  if (parms.find("-netlibDir") != parms.end())
113    netlibDir=parms["-netlibDir"] + dirsep;
114  else 
115    netlibDir = dirsep == '/' ? "../Mps/Netlib/" : "..\\Mps\\Netlib\\";
116
117  testingMessage( "Testing ClpSimplex\n" );
118  ClpSimplexUnitTest(mpsDir,netlibDir);
119  if (parms.find("-netlib") != parms.end())
120  {
121    unsigned int m;
122   
123    // Define test problems:
124    //   mps names,
125    //   maximization or minimization,
126    //   Number of rows and columns in problem, and
127    //   objective function value
128    std::vector<std::string> mpsName;
129    std::vector<bool> min;
130    std::vector<int> nRows;
131    std::vector<int> nCols;
132    std::vector<double> objValue;
133    std::vector<double> objValueTol;
134    mpsName.push_back("25fv47");
135    min.push_back(true);
136    nRows.push_back(822);
137    nCols.push_back(1571);
138    objValueTol.push_back(1.E-10);
139    objValue.push_back(5.5018458883E+03);
140
141#if 1
142    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);
143    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);
144    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);
145   
146    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);
147    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);
148    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);
149    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);
150    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);
151    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);
152    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);
153    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);
154    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);
155    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);
156    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);
157    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);
158    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);
159    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);
160    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);
161    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);
162    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);
163    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);
164    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);
165    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);
166    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);
167    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);
168    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);
169    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);
170    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);
171    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.
172    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 );
173    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);
174    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);
175    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);
176    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);
177    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);
178    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);
179    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);
180    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);
181    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);
182#endif
183    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);
184    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);
185    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);
186    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);
187    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);
188    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);
189    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);
190    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);
191    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);
192    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);
193    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);
194    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);
195    //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);
196    //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);
197    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);
198    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);
199    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);
200    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);
201    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);
202    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);
203    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);
204    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);
205    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);
206    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);
207    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);
208    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);
209    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);
210    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);
211    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);
212    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);
213    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);
214    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);
215    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);
216    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);
217    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);
218    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);
219    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);
220    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);
221    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);
222    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);
223    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);
224    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);
225    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);
226    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);
227    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);
228    //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);
229    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); 
230    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);
231    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);
232    //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);
233    //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);
234    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);
235    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);
236    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);
237    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);
238  // Loop once for each Mps File
239    for (m=0; m<mpsName.size(); m++ ) {
240      std::cerr <<"  processing mps file: " <<mpsName[m] 
241                <<" (" <<m+1 <<" out of " <<mpsName.size() <<")" <<std::endl;
242   
243      // Read data mps file,
244      std::string fn = netlibDir+mpsName[m];
245      OsiMpsReader mps;
246      mps.readMps(fn.c_str(),"mps");
247      ClpSimplex solution=empty;
248      solution.loadProblem(*mps.getMatrixByCol(),mps.getColLower(),
249                           mps.getColUpper(),
250                           mps.getObjCoefficients(),
251                           mps.getRowLower(),mps.getRowUpper());
252
253      if (doDual) {
254#if 0
255        solution.scaling(1);
256        solution.setDualBound(1.0e6);
257        solution.setDualTolerance(1.0e-7);
258        // set objective sense,
259        if(min[m])
260          solution.setOptimizationDirection(1);
261        else       
262          solution.setOptimizationDirection(-1);
263        ClpDualRowSteepest steep;
264        solution.setDualRowPivotAlgorithm(steep);
265#endif
266        solution.setDblParam(OsiObjOffset,mps.objectiveOffset());
267        solution.dual();
268      } else {
269#if 0
270        solution.setPrimalTolerance(1.0e-8);
271        solution.scaling(1);
272        ClpPrimalColumnSteepest steep;
273        solution.setPrimalColumnPivotAlgorithm(steep);
274        // set objective sense,
275        if(min[m])
276          solution.setOptimizationDirection(1);
277        else       
278          solution.setOptimizationDirection(-1);
279        solution.setInfeasibilityCost(1.0e6);
280#endif
281        solution.setDblParam(OsiObjOffset,mps.objectiveOffset());
282        solution.primal();
283      }
284      // Test objective solution value
285      {
286        double soln = solution.objectiveValue();
287        OsiRelFltEq eq(objValueTol[m]);
288        std::cerr <<soln <<",  " <<objValue[m] <<" diff "<<
289          soln-objValue[m]<<std::endl;
290        if(!eq(soln,objValue[m]))
291          printf("** difference fails\n");
292      }
293    }
294   
295  }
296  else {
297    testingMessage( "***Skipped Testing on netlib    ***\n" );
298    testingMessage( "***use -netlib to test class***\n" );
299  }
300
301  testingMessage( "All tests completed successfully\n" );
302  return 0;
303}
304
305 
306// Display message on stdout and stderr
307void testingMessage( const char * const msg )
308{
309  std::cerr <<msg;
310  //cout <<endl <<"*****************************************"
311  //     <<endl <<msg <<endl;
312}
313
314//--------------------------------------------------------------------------
315// test factorization methods and simplex method
316void
317ClpSimplexUnitTest(const std::string & mpsDir,
318                   const std::string & netlibDir)
319{
320 
321  OsiRelFltEq eq(0.000001);
322
323  {
324    ClpSimplex solution;
325 
326    // matrix data
327    //deliberate hiccup of 2 between 0 and 1
328    int start[5]={0,4,7,8,9};
329    int length[5]={2,3,1,1,1};
330    int rows[11]={0,2,-1,-1,0,1,2,0,1,2};
331    double elements[11]={7.0,2.0,1.0e10,1.0e10,-2.0,1.0,-2.0,1,1,1};
332    OsiPackedMatrix matrix(true,3,5,8,elements,rows,start,length);
333   
334    // rim data
335    double objective[7]={-4.0,1.0,0.0,0.0,0.0,0.0,0.0};
336    double rowLower[5]={14.0,3.0,3.0,1.0e10,1.0e10};
337    double rowUpper[5]={14.0,3.0,3.0,-1.0e10,-1.0e10};
338    double colLower[7]={0.0,0.0,0.0,0.0,0.0,0.0,0.0};
339    double colUpper[7]={100.0,100.0,100.0,100.0,100.0,100.0,100.0};
340   
341    // basis 1
342    int rowBasis1[3]={-1,-1,-1};
343    int colBasis1[5]={1,1,-1,-1,1};
344    int i;
345    OsiWarmStartBasis warm;
346    warm.setSize(5,3);
347    for (i=0;i<3;i++) {
348      if (rowBasis1[i]<0) {
349        warm.setArtifStatus(i,OsiWarmStartBasis::atLowerBound);
350      } else {
351        warm.setArtifStatus(i,OsiWarmStartBasis::basic);
352      }
353    }
354    for (i=0;i<5;i++) {
355      if (colBasis1[i]<0) {
356        warm.setStructStatus(i,OsiWarmStartBasis::atLowerBound);
357      } else {
358        warm.setStructStatus(i,OsiWarmStartBasis::basic);
359      }
360    }
361    solution.loadProblem(matrix,colLower,colUpper,objective,
362                         rowLower,rowUpper);
363    solution.setLogLevel(3+4+8+16+32);
364    solution.primal();
365    solution.setBasis(warm);
366    assert(!solution.factorize ( ));
367    const double * colsol = solution.primalColumnSolution();
368    const double * rowsol = solution.primalRowSolution();
369    solution.getSolution(rowsol,colsol);
370    double colsol1[5]={20.0/7.0,3.0,0.0,0.0,23.0/7.0};
371    for (i=0;i<5;i++) {
372      assert(eq(colsol[i],colsol1[i]));
373    }
374    // now feed in again without actually doing factorization
375    ClpFactorization factorization2 = *solution.factorization();
376    ClpSimplex solution2 = solution;
377    solution2.setFactorization(factorization2);
378    solution2.setBasis(warm);
379    solution2.getSolution(rowsol,colsol);
380    colsol = solution2.primalColumnSolution();
381    rowsol = solution2.primalRowSolution();
382    for (i=0;i<5;i++) {
383      assert(eq(colsol[i],colsol1[i]));
384    }
385    solution2.setDualBound(0.1);
386    solution2.dual();
387    objective[2]=-1.0;
388    objective[3]=-0.5;
389    objective[4]=10.0;
390    solution.dual();
391    for (i=0;i<3;i++) {
392      rowLower[i]=-1.0e50;
393      colUpper[i+2]=0.0;
394    }
395    solution.setLogLevel(3);
396    solution.dual();
397    double rowObjective[]={1.0,0.5,-10.0};
398    solution.loadProblem(matrix,colLower,colUpper,objective,
399                         rowLower,rowUpper,rowObjective);
400    solution.dual();
401  }
402  {   
403    OsiMpsReader m;
404    std::string fn = mpsDir+"exmip1";
405    m.readMps(fn.c_str(),"mps");
406    ClpSimplex solution;
407    solution.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(),
408                         m.getObjCoefficients(),
409                         m.getRowLower(),m.getRowUpper());
410    solution.dual();
411  }
412  // test steepest edge
413  {   
414    OsiMpsReader m;
415    std::string fn = netlibDir+"finnis";
416    m.readMps(fn.c_str(),"mps");
417    ClpModel model;
418    model.loadProblem(*m.getMatrixByCol(),m.getColLower(),
419                    m.getColUpper(),
420                    m.getObjCoefficients(),
421                    m.getRowLower(),m.getRowUpper());
422    ClpSimplex solution(model);
423
424    solution.scaling(1); 
425    solution.setDualBound(1.0e8);
426    //solution.factorization()->maximumPivots(1);
427    //solution.setLogLevel(3);
428    solution.setDualTolerance(1.0e-7);
429    // set objective sense,
430    ClpDualRowSteepest steep;
431    solution.setDualRowPivotAlgorithm(steep);
432    solution.setDblParam(OsiObjOffset,m.objectiveOffset());
433    solution.dual();
434  }
435  // test normal solution
436  {   
437    OsiMpsReader m;
438    std::string fn = netlibDir+"afiro";
439    m.readMps(fn.c_str(),"mps");
440    ClpSimplex solution;
441    ClpModel model;
442    // do twice - without and with scaling
443    int iPass;
444    for (iPass=0;iPass<2;iPass++) {
445      // explicit row objective for testing
446      int nr = m.getNumRows();
447      double * rowObj = new double[nr];
448      CoinFillN(rowObj,nr,0.0);
449      model.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(),
450                      m.getObjCoefficients(),
451                      m.getRowLower(),m.getRowUpper(),rowObj);
452      delete [] rowObj;
453      solution = ClpSimplex(model);
454      if (iPass) {
455        solution.scaling();
456      }
457      solution.dual();
458      solution.dual();
459      // test optimal
460      assert (solution.status()==0);
461      int numberColumns = solution.numberColumns();
462      int numberRows = solution.numberRows();
463      OsiPackedVector colsol(numberColumns,solution.primalColumnSolution());
464      double * objective = solution.objective();
465      double objValue = colsol.dotProduct(objective);
466      OsiRelFltEq eq(1.0e-8);
467      assert(eq(objValue,-4.6475314286e+02));
468      double * lower = solution.columnLower();
469      double * upper = solution.columnUpper();
470      double * sol = solution.primalColumnSolution();
471      double * result = new double[numberColumns];
472      CoinFillN ( result, numberColumns,0.0);
473      solution.matrix()->transposeTimes(solution.dualRowSolution(), result);
474      int iRow , iColumn;
475      // see if feasible and dual feasible
476      for (iColumn=0;iColumn<numberColumns;iColumn++) {
477        double value = sol[iColumn];
478        assert(value<upper[iColumn]+1.0e-8);
479        assert(value>lower[iColumn]-1.0e-8);
480        value = objective[iColumn]-result[iColumn];
481        assert (value>-1.0e-5);
482        if (sol[iColumn]>1.0e-5)
483          assert (value<1.0e-5);
484      }
485      delete [] result;
486      result = new double[numberRows];
487      CoinFillN ( result, numberRows,0.0);
488      solution.matrix()->times(colsol, result);
489      lower = solution.rowLower();
490      upper = solution.rowUpper();
491      sol = solution.primalRowSolution();
492      for (iRow=0;iRow<numberRows;iRow++) {
493        double value = result[iRow];
494        assert(eq(value,sol[iRow]));
495        assert(value<upper[iRow]+1.0e-8);
496        assert(value>lower[iRow]-1.0e-8);
497      }
498      delete [] result;
499      // test row objective
500      double * rowObjective = solution.rowObjective();
501      CoinDisjointCopyN(solution.dualRowSolution(),numberRows,rowObjective);
502      CoinDisjointCopyN(solution.dualColumnSolution(),numberColumns,objective);
503      OsiWarmStartBasis basis;
504      solution.setBasis(basis);
505      solution.dual();
506      CoinFillN(rowObjective,numberRows,0.0);
507      CoinDisjointCopyN(m.getObjCoefficients(),numberColumns,objective);
508      solution.dual();
509    }
510  }
511  // test unbounded
512  {   
513    OsiMpsReader m;
514    std::string fn = netlibDir+"brandy";
515    m.readMps(fn.c_str(),"mps");
516    ClpSimplex solution;
517    // do twice - without and with scaling
518    int iPass;
519    for (iPass=0;iPass<2;iPass++) {
520      solution.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(),
521                      m.getObjCoefficients(),
522                      m.getRowLower(),m.getRowUpper());
523      if (iPass)
524        solution.scaling();
525      solution.setOptimizationDirection(-1);
526      // test unbounded and ray
527#ifdef DUAL
528      solution.setDualBound(100.0);
529      solution.dual();
530#else
531      solution.primal();
532#endif
533      assert (solution.status()==2);
534      int numberColumns = solution.numberColumns();
535      int numberRows = solution.numberRows();
536      double * lower = solution.columnLower();
537      double * upper = solution.columnUpper();
538      double * sol = solution.primalColumnSolution();
539      double * ray = solution.unboundedRay();
540      double * objective = solution.objective();
541      double objChange=0.0;
542      int iRow , iColumn;
543      // make sure feasible and columns form ray
544      for (iColumn=0;iColumn<numberColumns;iColumn++) {
545        double value = sol[iColumn];
546        assert(value<upper[iColumn]+1.0e-8);
547        assert(value>lower[iColumn]-1.0e-8);
548        value = ray[iColumn];
549        if (value>0.0)
550          assert(upper[iColumn]>1.0e30);
551        else if (value<0.0)
552          assert(lower[iColumn]<-1.0e30);
553        objChange += value*objective[iColumn];
554      }
555      // make sure increasing objective
556      assert(objChange>0.0);
557      double * result = new double[numberRows];
558      CoinFillN ( result, numberRows,0.0);
559      solution.matrix()->times(sol, result);
560      lower = solution.rowLower();
561      upper = solution.rowUpper();
562      sol = solution.primalRowSolution();
563      for (iRow=0;iRow<numberRows;iRow++) {
564        double value = result[iRow];
565        assert(eq(value,sol[iRow]));
566        assert(value<upper[iRow]+1.0e-8);
567        assert(value>lower[iRow]-1.0e-8);
568      }
569      CoinFillN ( result, numberRows,0.0);
570      solution.matrix()->times(ray, result);
571      // there may be small differences (especially if scaled)
572      for (iRow=0;iRow<numberRows;iRow++) {
573        double value = result[iRow];
574        if (value>1.0e-8)
575          assert(upper[iRow]>1.0e30);
576        else if (value<-1.0e-8)
577          assert(lower[iRow]<-1.0e30);
578      }
579      delete [] result;
580      delete [] ray;
581    }
582  }
583  // test infeasible
584  {   
585    OsiMpsReader m;
586    std::string fn = netlibDir+"brandy";
587    m.readMps(fn.c_str(),"mps");
588    ClpSimplex solution;
589    // do twice - without and with scaling
590    int iPass;
591    for (iPass=0;iPass<2;iPass++) {
592      solution.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(),
593                      m.getObjCoefficients(),
594                      m.getRowLower(),m.getRowUpper());
595      if (iPass)
596        solution.scaling();
597      // test infeasible and ray
598      solution.columnUpper()[0]=0.0;
599#ifdef DUAL
600      solution.setDualBound(100.0);
601      solution.dual();
602#else
603      solution.primal();
604#endif
605      assert (solution.status()==1);
606      int numberColumns = solution.numberColumns();
607      int numberRows = solution.numberRows();
608      double * lower = solution.rowLower();
609      double * upper = solution.rowUpper();
610      double * ray = solution.infeasibilityRay();
611      assert(ray);
612      // construct proof of infeasibility
613      int iRow , iColumn;
614      double lo=0.0,up=0.0;
615      int nl=0,nu=0;
616      for (iRow=0;iRow<numberRows;iRow++) {
617        if (lower[iRow]>-1.0e20) {
618          lo += ray[iRow]*lower[iRow];
619        } else {
620          if (ray[iRow]>1.0e-8) 
621            nl++;
622        }
623        if (upper[iRow]<1.0e20) {
624          up += ray[iRow]*upper[iRow];
625        } else {
626          if (ray[iRow]>1.0e-8) 
627            nu++;
628        }
629      }
630      if (nl)
631        lo=-1.0e100;
632      if (nu)
633        up=1.0e100;
634      double * result = new double[numberColumns];
635      double lo2=0.0,up2=0.0;
636      CoinFillN ( result, numberColumns,0.0);
637      solution.matrix()->transposeTimes(ray, result);
638      lower = solution.columnLower();
639      upper = solution.columnUpper();
640      nl=nu=0;
641      for (iColumn=0;iColumn<numberColumns;iColumn++) {
642        if (result[iColumn]>1.0e-8) {
643          if (lower[iColumn]>-1.0e20)
644            lo2 += result[iColumn]*lower[iColumn];
645          else
646            nl++;
647          if (upper[iColumn]<1.0e20)
648            up2 += result[iColumn]*upper[iColumn];
649          else
650            nu++;
651        } else if (result[iColumn]<-1.0e-8) {
652          if (lower[iColumn]>-1.0e20)
653            up2 += result[iColumn]*lower[iColumn];
654          else
655            nu++;
656          if (upper[iColumn]<1.0e20)
657            lo2 += result[iColumn]*upper[iColumn];
658          else
659            nl++;
660        }
661      }
662      if (nl)
663        lo2=-1.0e100;
664      if (nu)
665        up2=1.0e100;
666      // make sure inconsistency
667      assert(lo2>up||up2<lo);
668      delete [] result;
669      delete [] ray;
670    }
671  }
672 
673}
Note: See TracBrowser for help on using the repository browser.