File: unitTestClp.cpp

package info (click to toggle)
coinor-cbc 2.9.9+repack1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,848 kB
  • ctags: 5,787
  • sloc: cpp: 104,337; sh: 8,921; xml: 2,950; makefile: 520; ansic: 491; awk: 197
file content (727 lines) | stat: -rw-r--r-- 24,880 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
/* $Id: unitTestClp.cpp 2271 2016-02-22 00:11:27Z tkr $ */
// Copyright (C) 2002, International Business Machines
// Corporation and others.  All Rights Reserved.
// This code is licensed under the terms of the Eclipse Public License (EPL).


#include <cstdio>
#include <string>
#include <iostream>
#include <iomanip>

#include "CoinTime.hpp"
#include "CoinFileIO.hpp"
#include "CbcModel.hpp"
#include "CbcHeuristic.hpp"
#include "CbcCutGenerator.hpp"
#include "CbcBranchCut.hpp"
#include "CglProbing.hpp"
#include "OsiClpSolverInterface.hpp"
#include "ClpFactorization.hpp"
#include "OsiRowCutDebugger.hpp"
//#############################################################################

#ifdef NDEBUG
#undef NDEBUG
#endif

//#############################################################################

// Display message on stdout and stderr
void testingMessage( const char * const msg )
{
    std::cout << msg;
    //cout <<endl <<"*****************************************"
    //     <<endl <<msg <<endl;
}

//#############################################################################

static inline bool CbcTestFile(const std::string name)
{
    FILE *fp = fopen(name.c_str(), "r");
    if (fp) {
        fclose(fp);
        return true;
    }
    return false;
}

//#############################################################################

bool CbcTestMpsFile(std::string& fname)
{
    if (CbcTestFile(fname)) {
        return true;
    }
    if (CbcTestFile(fname + ".mps")) {
        fname += ".mps";
        return true;
    }
    if (CbcTestFile(fname + ".MPS")) {
        fname += ".MPS";
        return true;
    }
    if (CoinFileInput::haveGzipSupport()) {
      if (CbcTestFile(fname + ".gz")) {
        return true;
      }
      if (CbcTestFile(fname + ".mps.gz")) {
        fname += ".mps";
        return true;
      }
      if (CbcTestFile(fname + ".MPS.gz")) {
        fname += ".MPS";
        return true;
      }
      if (CbcTestFile(fname + ".MPS.GZ")) {
        fname += ".MPS";
        return true;
      }
    }
    if (CoinFileInput::haveBzip2Support()) {
      if (CbcTestFile(fname + ".bz2")) {
        return true;
      }
      if (CbcTestFile(fname + ".mps.bz2")) {
        fname += ".mps";
        return true;
      }
      if (CbcTestFile(fname + ".MPS.bz2")) {
        fname += ".MPS";
        return true;
      }
      if (CbcTestFile(fname + ".MPS.BZ2")) {
        fname += ".MPS";
        return true;
      }
    }
    return false;
}

//#############################################################################
/*
  jjf: testSwitch -2 unitTest, -1 normal (==2)

  MiplibTest might be more appropriate.

  TestSwitch and stuff[6] together control how much of miplib is executed:
    For testSwitch set to:
      -2: solve p0033 and p0201 only (the unit test)
      -1: solve miplib sets #0 and #1
       0: solve nothing
       k: execute sets j:k, where j is determined by the value of stuff[6]
  The last parameter of PUSH_MPS specifies the test set membership.

  For -miplib, -extra2 sets testSwitch, -extra3 sets stuff[6]. The command
    cbc -extra2 -2 -miplib
  will execute the unit test on the miplib directory.

  dirMiplib should end in the directory separator character for the platform.

  If you want to activate the row cut debugger for a given problem, change the
  last parameter of the PUSH_MPS macro for the problem to true.

  Returns 0 if all goes well, -1 if the Miplib directory is missing, otherwise
     100*(number with bad objective)+(number that exceeded node limit)
*/
int CbcClpUnitTest (const CbcModel &saveModel, const std::string &dirMiplib,
                    int testSwitch, const double *stuff)
{
  // Stop Windows popup
  WindowsErrorPopupBlocker() ;
  unsigned int m ;

  // Do an existence check.
  std::string test1 = dirMiplib+"p0033";
  bool doTest = CbcTestMpsFile(test1);
  if (!doTest) {
    std::cout
      << "Not doing miplib run as can't find mps files." << std::endl
      << "Perhaps you're trying to read gzipped (.gz) files without libz?"
      << std::endl ;
    return (0) ;
  }
  int dfltPrecision = static_cast<int>(std::cout.precision()) ;
/*
  Set the range of problems to be tested. testSwitch = -2 is special and is
  picked up below.
*/
    int loSet = 0 ;
    int hiSet = 0 ;
    if (testSwitch == -1) {
      loSet = 0 ;
      hiSet = 1 ;
    } else if (testSwitch >= 0) {
      loSet = static_cast<int>(stuff[6]) ;
      hiSet = testSwitch ;
      std::cout
        << "Solving miplib problems in sets " << loSet
	<< ":" << hiSet << "." << std::endl ;
    }
/*
  Vectors to hold test problem names and characteristics.
*/
    std::vector<std::string> mpsName ;
    std::vector<int> nRows ;
    std::vector<int> nCols ;
    std::vector<double> objValueC ;
    std::vector<double> objValue ;
    std::vector<int> testSet ;
    std::vector<int> rowCutDebugger ;
/*
  A macro to make the vector creation marginally readable. Parameters are
  name, rows, columns, integer objective, continuous objective, set ID,
  row cut debugger

  To enable the row cut debugger for a given problem, change the last
  parameter to true. Don't forget to turn it off before committing changes!
*/
#define PUSH_MPS(zz_mpsName_zz,\
		 zz_nRows_zz,zz_nCols_zz,zz_objValue_zz,zz_objValueC_zz, \
                 zz_testSet_zz, zz_rcDbg_zz) \
  mpsName.push_back(zz_mpsName_zz) ; \
  nRows.push_back(zz_nRows_zz) ; \
  nCols.push_back(zz_nCols_zz) ; \
  objValueC.push_back(zz_objValueC_zz) ; \
  testSet.push_back(zz_testSet_zz) ; \
  objValue.push_back(zz_objValue_zz) ; \
  rowCutDebugger.push_back(zz_rcDbg_zz) ;
/*
  Push the miplib problems. Except for -2 (unitTest), push all, even if we're
  not going to do all of them.
*/
  if (testSwitch == -2) {
      PUSH_MPS("p0033", 16, 33, 3089, 2520.57, 0, false);
      PUSH_MPS("p0201", 133, 201, 7615, 6875.0, 0, false);
      // PUSH_MPS("flugpl", 18, 18, 1201500, 1167185.7, 0, false);
  } else {
/*
  Load up the problem vector. Note that the row counts here include the
  objective function.
*/
#if 1
    PUSH_MPS("10teams", 230, 2025, 924, 917, 1, false);
    PUSH_MPS("air03", 124, 10757, 340160, 338864.25, 0, false);
    PUSH_MPS("air04", 823, 8904, 56137, 55535.436, 2, false);
    PUSH_MPS("air05", 426, 7195, 26374, 25877.609, 2, false);
    PUSH_MPS("arki001", 1048, 1388, 7580813.0459, 7579599.80787, 7, false);
    PUSH_MPS("bell3a", 123, 133, 878430.32, 862578.64, 0, false);
    PUSH_MPS("bell5", 91, 104, 8966406.49, 8608417.95, 1, false);
    PUSH_MPS("blend2", 274, 353, 7.598985, 6.9156751140, 0, false);
    PUSH_MPS("cap6000", 2176, 6000, -2451377, -2451537.325, 1, false);
    PUSH_MPS("dano3mip", 3202, 13873, 728.1111, 576.23162474, 7, false);
    PUSH_MPS("danoint", 664, 521, 65.67, 62.637280418, 6, false);
    PUSH_MPS("dcmulti", 290, 548, 188182, 183975.5397, 0, false);
    PUSH_MPS("dsbmip", 1182, 1886, -305.19817501, -305.19817501, 0, false);
    PUSH_MPS("egout", 98, 141, 568.101, 149.589, 0, false);
    PUSH_MPS("enigma", 21, 100, 0.0, 0.0, 0, false);
    PUSH_MPS("fast0507", 507, 63009, 174, 172.14556668, 5, false);
    PUSH_MPS("fiber", 363, 1298, 405935.18000, 156082.51759, 0, false);
    PUSH_MPS("fixnet6", 478, 878, 3983, 1200.88, 1, false);
    PUSH_MPS("flugpl", 18, 18, 1201500, 1167185.7, 0, false);
    PUSH_MPS("gen", 780, 870, 112313, 112130.0, 0, false);
    PUSH_MPS("gesa2", 1392, 1224, 25779856.372, 25476489.678, 1, false);
    PUSH_MPS("gesa2_o", 1248, 1224, 25779856.372, 25476489.678, 1, false);
    PUSH_MPS("gesa3", 1368, 1152, 27991042.648, 27833632.451, 0, false);
    PUSH_MPS("gesa3_o", 1224, 1152, 27991042.648, 27833632.451, 0, false);
    PUSH_MPS("gt2", 29, 188, 21166.000, 13460.233074, 0, false);
    PUSH_MPS("harp2", 112, 2993, -73899798.00, -74353341.502, 6, false);
    PUSH_MPS("khb05250", 101, 1350, 106940226, 95919464.0, 0, false);
    PUSH_MPS("l152lav", 97, 1989, 4722, 4656.36, 1, false);
    PUSH_MPS("lseu", 28, 89, 1120, 834.68, 0, false);
    PUSH_MPS("mas74", 13, 151, 11801.18573, 10482.79528, 3, false);
    PUSH_MPS("mas76", 12, 151, 40005.05414, 38893.9036, 2, false);
    PUSH_MPS("misc03", 96, 160, 3360, 1910., 0, false);
    PUSH_MPS("misc06", 820, 1808, 12850.8607, 12841.6, 0, false);
    PUSH_MPS("misc07", 212, 260, 2810, 1415.0, 1, false);
    PUSH_MPS("mitre", 2054, 10724, 115155, 114740.5184, 1, false);
    PUSH_MPS("mkc", 3411, 5325, -553.75, -611.85, 7, false); // suboptimal
    PUSH_MPS("mod008", 6, 319, 307, 290.9, 0, false);
    PUSH_MPS("mod010", 146, 2655, 6548, 6532.08, 0, false);
    PUSH_MPS("mod011", 4480, 10958, -54558535, -62121982.55, 2, false);
    PUSH_MPS("modglob", 291, 422, 20740508, 20430947., 2, false);
    PUSH_MPS("noswot", 182, 128, -43, -43.0, 6, false);
    PUSH_MPS("nw04", 36, 87482, 16862, 16310.66667, 1, false);
    PUSH_MPS("p0033", 16, 33, 3089, 2520.57, 0, false);
    PUSH_MPS("p0201", 133, 201, 7615, 6875.0, 0, false);
    PUSH_MPS("p0282", 241, 282, 258411, 176867.50, 0, false);
    PUSH_MPS("p0548", 176, 548, 8691, 315.29, 0, false);
    PUSH_MPS("p2756", 755, 2756, 3124, 2688.75, 0, false);
    PUSH_MPS("pk1", 45, 86, 11.0, 0.0, 2, false);
    PUSH_MPS("pp08a", 136, 240, 7350.0, 2748.3452381, 1, false);
    PUSH_MPS("pp08aCUTS", 246, 240, 7350.0, 5480.6061563, 1, false);
    PUSH_MPS("qiu", 1192, 840, -132.873137, -931.638857, 3, false);
    PUSH_MPS("qnet1", 503, 1541, 16029.692681, 14274.102667, 0, false);
    PUSH_MPS("qnet1_o", 456, 1541, 16029.692681, 12095.571667, 0, false);
    PUSH_MPS("rentacar", 6803, 9557, 30356761, 28806137.644, 0, false);
    PUSH_MPS("rgn", 24, 180, 82.1999, 48.7999, 0, false);
    PUSH_MPS("rout", 291, 556, 1077.56, 981.86428571, 3, false);
    PUSH_MPS("set1ch", 492, 712, 54537.75, 32007.73, 5, false);
    PUSH_MPS("seymour", 4944, 1372, 423, 403.84647413, 7, false);
    PUSH_MPS("seymour_1", 4944, 1372, 410.76370, 403.84647413, 5, false);
    PUSH_MPS("stein27", 118, 27, 18, 13.0, 0, false);
    PUSH_MPS("stein45", 331, 45, 30, 22.0, 1, false);
    PUSH_MPS("swath", 884, 6805, 497.603, 334.4968581, 7, false);
    PUSH_MPS("vpm1", 234, 378, 20, 15.4167, 0, false);
#endif
    PUSH_MPS("vpm2", 234, 378, 13.75, 9.8892645972, 0, false);
  }
#undef PUSH_MPS

/*
  Normally the problems are executed in order. Define RANDOM_ORDER below to
  randomize.

  #define RANDOM_ORDER
*/
  int which[100];
  int nLoop = static_cast<int>(mpsName.size());
  assert (nLoop <= 100);
  for (int i = 0; i < nLoop; i++) which[i] = i;

# ifdef RANDOM_ORDER
  unsigned int iTime = static_cast<unsigned int>(CoinGetTimeOfDay()-1.256e9);
  std::cout << "Time (seed) " << iTime << "." << std::endl ;
  double sort[100];
  CoinDrand48(true,iTime);
  for (int i = 0; i < nLoop; i++) sort[i] = CoinDrand48();
  CoinSort_2(sort,sort+nLoop,which);
# endif

  int problemCnt = 0;
  for (m = 0 ; m < mpsName.size() ; m++) {
    int setID = testSet[m];
    if (loSet <= setID && setID <= hiSet) problemCnt++;
  }

  int numberFailures = 0;
  int numberAttempts = 0;
  int numProbSolved = 0;
  double timeTaken = 0.0;

//#define CLP_FACTORIZATION_INSTRUMENT
# ifdef CLP_FACTORIZATION_INSTRUMENT
  double timeTakenFac = 0.0;
# endif

/*
  Open the main loop to step through the MPS problems.
*/
  for (unsigned int mw = 0 ; mw < mpsName.size() ; mw++) {
    m = which[mw];
    int setID = testSet[m];
    // Skip if problem is not in specified problem set(s)
    if (!(loSet <= setID && setID <= hiSet)) continue ;
   
    numberAttempts++;
    std::cout << "  processing mps file: " << mpsName[m]
	      << " (" << numberAttempts << " out of "
	      << problemCnt << ")" << std::endl ;
/*
  Stage 1: Read the MPS and make sure the size of the constraint matrix
	   is correct.
*/
    CbcModel *model = new CbcModel(saveModel) ;

    std::string fn = dirMiplib+mpsName[m] ;
    if (!CbcTestMpsFile(fn)) {
      std::cout << "ERROR: Cannot find MPS file " << fn << "." << std::endl ;
      continue;
    }
    model->solver()->readMps(fn.c_str(), "") ;
    assert(model->getNumRows() == nRows[m]) ;
    assert(model->getNumCols() == nCols[m]) ;

    // Careful! We're initialising for the benefit of other code.
    CoinDrand48(true,1234567);
    //printf("RAND1 %g %g\n",CoinDrand48(true,1234567),model->randomNumberGenerator()->randomDouble());
    //printf("RAND1 %g\n",CoinDrand48(true,1234567));

    // Higher limits for the serious problems.
    int testMaximumNodes = 200000;
    if (hiSet > 1)
	testMaximumNodes = 20000000;
    if (model->getMaximumNodes() > testMaximumNodes) {
	model->setMaximumNodes(testMaximumNodes);
    }
/*
  Stage 2: Call solver to solve the problem.
*/

#   ifdef CLP_FACTORIZATION_INSTRUMENT
    extern double factorization_instrument(int type);
    double facTime1 = factorization_instrument(0);
    std::cout
      << "Factorization - initial solve " << facTime1 << " seconds."
      << std::endl ;
      timeTakenFac += facTime1;
#   endif

    double startTime = CoinCpuTime()+CoinCpuTimeJustChildren();

    // Setup specific to clp
    OsiClpSolverInterface *siClp =
	dynamic_cast<OsiClpSolverInterface *>(model->solver()) ;
    ClpSimplex *modelC = NULL;
    if (siClp) {
      modelC = siClp->getModelPtr();
      ClpMatrixBase * matrix = modelC->clpMatrix();
      ClpPackedMatrix * clpMatrix = dynamic_cast< ClpPackedMatrix*>(matrix);
      if (stuff && stuff[9] && clpMatrix) {
	// vector matrix!
	clpMatrix->makeSpecialColumnCopy();
      }

#     ifdef JJF_ZERO
      if (clpMatrix) {
	int numberRows = clpMatrix->getNumRows();
	int numberColumns = clpMatrix->getNumCols();
	double * elements = clpMatrix->getMutableElements();
	const int * row = clpMatrix->getIndices();
	const CoinBigIndex * columnStart = clpMatrix->getVectorStarts();
	const int * columnLength = clpMatrix->getVectorLengths();
	double * smallest = new double [numberRows];
	double * largest = new double [numberRows];
	char * flag = new char [numberRows];
	CoinZeroN(flag, numberRows);
	for (int i = 0; i < numberRows; i++) {
	    smallest[i] = COIN_DBL_MAX;
	    largest[i] = 0.0;
	}
	for (int iColumn = 0; iColumn < numberColumns; iColumn++) {
	    bool isInteger = modelC->isInteger(iColumn);
	    CoinBigIndex j;
	    for (j = columnStart[iColumn];
		    j < columnStart[iColumn] + columnLength[iColumn]; j++) {
		int iRow = row[j];
		double value = fabs(elements[j]);
		if (!isInteger)
		    flag[iRow] = 1;
		smallest[iRow] = CoinMin(smallest[iRow], value);
		largest[iRow] = CoinMax(largest[iRow], value);
	    }
	}
	double * rowLower = modelC->rowLower();
	double * rowUpper = modelC->rowUpper();
	bool changed = false;
	for (int i = 0; i < numberRows; i++) {
	    if (flag[i] && smallest[i] > 10.0 && false) {
		smallest[i] = 1.0 / smallest[i];
		if (rowLower[i] > -1.0e20)
		    rowLower[i] *= smallest[i];
		if (rowUpper[i] < 1.0e20)
		    rowUpper[i] *= smallest[i];
		changed = true;
	    } else {
		smallest[i] = 0.0;
	    }
	}
	if (changed) {
	    printf("SCALED\n");
	    for (int iColumn = 0; iColumn < numberColumns; iColumn++) {
		CoinBigIndex j;
		for (j = columnStart[iColumn];
			j < columnStart[iColumn] + columnLength[iColumn]; j++) {
		    int iRow = row[j];
		    if (smallest[iRow])
			elements[j] *= smallest[iRow];
		}
	    }
	}
	delete [] smallest;
	delete [] largest;
	delete [] flag;
      }
#     endif    // JJF_ZERO

      model->checkModel();
      modelC->tightenPrimalBounds(0.0, 0, true);
      model->initialSolve();
      if (modelC->dualBound() == 1.0e10) {
	// user did not set - so modify
	// get largest scaled away from bound
	ClpSimplex temp = *modelC;
	temp.dual(0, 7);
	double largestScaled = 1.0e-12;
	double largest = 1.0e-12;
	int numberRows = temp.numberRows();
	const double * rowPrimal = temp.primalRowSolution();
	const double * rowLower = temp.rowLower();
	const double * rowUpper = temp.rowUpper();
	const double * rowScale = temp.rowScale();
	int iRow;
	for (iRow = 0; iRow < numberRows; iRow++) {
	  double value = rowPrimal[iRow];
	  double above = value - rowLower[iRow];
	  double below = rowUpper[iRow] - value;
	  if (above < 1.0e12) {
	      largest = CoinMax(largest, above);
	  }
	  if (below < 1.0e12) {
	      largest = CoinMax(largest, below);
	  }
	  if (rowScale) {
	      double multiplier = rowScale[iRow];
	      above *= multiplier;
	      below *= multiplier;
	  }
	  if (above < 1.0e12) {
	      largestScaled = CoinMax(largestScaled, above);
	  }
	  if (below < 1.0e12) {
	      largestScaled = CoinMax(largestScaled, below);
	  }
	}

	int numberColumns = temp.numberColumns();
	const double * columnPrimal = temp.primalColumnSolution();
	const double * columnLower = temp.columnLower();
	const double * columnUpper = temp.columnUpper();
	const double * columnScale = temp.columnScale();
	int iColumn;
	for (iColumn = 0; iColumn < numberColumns; iColumn++) {
	  double value = columnPrimal[iColumn];
	  double above = value - columnLower[iColumn];
	  double below = columnUpper[iColumn] - value;
	  if (above < 1.0e12) {
	      largest = CoinMax(largest, above);
	  }
	  if (below < 1.0e12) {
	      largest = CoinMax(largest, below);
	  }
	  if (columnScale) {
	      double multiplier = 1.0 / columnScale[iColumn];
	      above *= multiplier;
	      below *= multiplier;
	  }
	  if (above < 1.0e12) {
	      largestScaled = CoinMax(largestScaled, above);
	  }
	  if (below < 1.0e12) {
	      largestScaled = CoinMax(largestScaled, below);
	  }
	}
	std::cout << "Largest (scaled) away from bound " << largestScaled
		  << " unscaled " << largest << std::endl;
#       ifdef JJF_ZERO
	modelC->setDualBound(CoinMax(1.0001e8,
				 CoinMin(1000.0*largestScaled,1.00001e10)));
#       else
	modelC->setDualBound(CoinMax(1.0001e9,
				 CoinMin(1000.0*largestScaled,1.0001e10)));
#       endif
      }
    }    // end clp-specific setup
/*
  Cut passes: For small models (n < 500) always do 100 passes, if possible
  (-100). For larger models, use minimum drop to stop (100, 20).
*/
    model->setMinimumDrop(CoinMin(5.0e-2,
		      fabs(model->getMinimizationObjValue())*1.0e-3+1.0e-4));
    if (CoinAbs(model->getMaximumCutPassesAtRoot()) <= 100) {
	if (model->getNumCols() < 500) {
	  model->setMaximumCutPassesAtRoot(-100);
	} else if (model->getNumCols() < 5000) {
	  model->setMaximumCutPassesAtRoot(100);
	} else {
	  model->setMaximumCutPassesAtRoot(20);
	}
    }
    // If defaults then increase trust for small models
    if (model->numberStrong() == 5 && model->numberBeforeTrust() == 10) {
	int numberColumns = model->getNumCols();
	if (numberColumns <= 50) {
	    model->setNumberBeforeTrust(1000);
	} else if (numberColumns <= 100) {
	    model->setNumberBeforeTrust(100);
	} else if (numberColumns <= 300) {
	    model->setNumberBeforeTrust(50);
	}
    }
    //if (model->getNumCols()>=500) {
    // switch off Clp stuff
    //model->setFastNodeDepth(-1);
    //}
/*
  Activate the row cut debugger, if requested.
*/
    if (rowCutDebugger[m] == true) {
      std::string probName ;
      model->solver()->getStrParam(OsiProbName,probName) ;
      model->solver()->activateRowCutDebugger(probName.c_str()) ;
      if (model->solver()->getRowCutDebugger())
	std::cout << "Row cut debugger activated for " ;
      else
        std::cout << "Failed to activate row cut debugger for " ;
      std::cout << mpsName[m] << "." << std::endl ;
    }
    setCutAndHeuristicOptions(*model) ;
/*
  More clp-specific setup.
*/
    if (siClp) {
#     ifdef CLP_MULTIPLE_FACTORIZATIONS
      if (!modelC->factorization()->isDenseOrSmall()) {
	  int denseCode = stuff ? static_cast<int> (stuff[4]) : -1;
	  int smallCode = stuff ? static_cast<int> (stuff[10]) : -1;
	  if (stuff && stuff[8] >= 1) {
	      if (denseCode < 0)
		  denseCode = 40;
	      if (smallCode < 0)
		  smallCode = 40;
	  }
	  if (denseCode > 0)
	      modelC->factorization()->setGoDenseThreshold(denseCode);
	  if (smallCode > 0)
	      modelC->factorization()->setGoSmallThreshold(smallCode);
	  if (denseCode >= modelC->numberRows()) {
	      //printf("problem going dense\n");
	      //modelC->factorization()->goDenseOrSmall(modelC->numberRows());
	  }
      }
#     endif
      if (stuff && stuff[8] >= 1) {
	printf("Fast node size Columns %d rows %d - depth %d\n",
	       modelC->numberColumns(),modelC->numberRows(),
	       model->fastNodeDepth());
	  if (modelC->numberColumns() + modelC->numberRows() <= 10000 &&
		  model->fastNodeDepth() == -1)
	    model->setFastNodeDepth(-10/*-9*/);
      }
    }
#ifdef CONFLICT_CUTS
    {
      model->setCutoffAsConstraint(true);
      int moreOptions=model->moreSpecialOptions();
      model->setMoreSpecialOptions(moreOptions|4194304);
    }
#endif
/*
  Finally, the actual call to solve the MIP with branch-and-cut.
*/
    model->branchAndBound();

#   ifdef CLP_FACTORIZATION_INSTRUMENT
    double facTime = factorization_instrument(0);
    std::cout << "Factorization " << facTime << " seconds." << std::endl ,
    timeTakenFac += facTime;
#   endif

/*
  Stage 3: Do the statistics and check the answer.
*/
    double timeOfSolution = CoinCpuTime()+CoinCpuTimeJustChildren()-startTime;
    std::cout
      << "Cuts at root node changed objective from "
      << model->getContinuousObjective() << " to "
      << model->rootObjectiveAfterCuts() << std::endl ;
    int numberGenerators = model->numberCutGenerators();
    for (int iGenerator = 0 ; iGenerator < numberGenerators ; iGenerator++) {
      CbcCutGenerator *generator = model->cutGenerator(iGenerator);
#     ifdef CLIQUE_ANALYSIS
#     ifndef CLP_INVESTIGATE
      CglImplication *implication =
	    dynamic_cast<CglImplication*>(generator->generator());
      if (implication) continue;
#     endif
#     endif
      std::cout
        << generator->cutGeneratorName() << " was tried "
	<< generator->numberTimesEntered() << " times and created "
	<< generator->numberCutsInTotal() << " cuts of which "
	<< generator->numberCutsActive()
	<< " were active after adding rounds of cuts";
      if (generator->timing())
	std::cout << " (" << generator->timeInCutGenerator() << " seconds)" ;
      std::cout << "." << std::endl;
    }
    std::cout
      << model->getNumberHeuristicSolutions()
      << " solutions found by heuristics." << std::endl ;
    int numberHeuristics = model->numberHeuristics();
    for (int iHeuristic = 0 ; iHeuristic < numberHeuristics ; iHeuristic++) {
      CbcHeuristic *heuristic = model->heuristic(iHeuristic);
      if (heuristic->numRuns()) {
	std::cout
	  << heuristic->heuristicName() << " was tried "
	  << heuristic->numRuns() << " times out of "
	  << heuristic->numCouldRun() << " and created "
	  << heuristic->numberSolutionsFound() << " solutions." << std::endl ;
	}
    }
/*
  Check for the correct answer.
*/
    if (!model->status()) {

      double objActual = model->getObjValue() ;
      double objExpect = objValue[m] ;
      double tolerance = CoinMin(fabs(objActual),fabs(objExpect)) ;
      tolerance = CoinMax(1.0e-5,1.0e-5*tolerance) ;
      //CoinRelFltEq eq(1.0e-3) ;

      std::cout
        << "cbc_clp (" << mpsName[m] << ") "
	<< std::setprecision(10) << objActual ;
      if (fabs(objActual-objExpect) < tolerance) {
	std::cout << std::setprecision(dfltPrecision) << "; okay" ;
	  numProbSolved++;
      } else  {
	std::cout
	  << " != " << objExpect << std::setprecision(dfltPrecision)
	  << "; error = " << fabs(objExpect-objActual) ;
	  numberFailures++;
	//#ifdef COIN_DEVELOP
	//abort();
	//#endif
      }
    } else {
      std::cout
        << "cbc_clp (" << mpsName[m] << ") status not optimal; "
        << "assuming too many nodes" ;
    }
    timeTaken += timeOfSolution;
    std::cout
      << " -- (" << model->getNodeCount() << " n / "
      << model->getIterationCount() << " i / "
      << timeOfSolution << " s) (subtotal " << timeTaken << " seconds)"
      << std::endl;
    delete model;
  }
/*
  End main loop on MPS problems. Print a summary and calculate the return
  value.
*/
  int returnCode = 0;
  std::cout
    << "cbc_clp solved " << numProbSolved << " out of " << numberAttempts;
  int numberOnNodes = numberAttempts-numProbSolved-numberFailures;
  if (numberFailures || numberOnNodes) {
    if (numberOnNodes) {
      std::cout << " (" << numberOnNodes << " stopped on nodes)";
      returnCode = numberOnNodes;
    }
    if (numberFailures) {
      std::cout << " (" << numberFailures << " gave bad answer!)";
      returnCode += 100*numberFailures;
    }
  }
  std::cout
    << " and took " << timeTaken << " seconds." << std::endl;

  if (testSwitch == -2) {
    if (numberFailures || numberOnNodes) {
      std::cout << "****** Unit Test failed." << std::endl ;
      std::cerr << "****** Unit Test failed." << std::endl ;
    } else {
      std::cerr << "****** Unit Test succeeded." << std::endl ;
    }
  }
# ifdef CLP_FACTORIZATION_INSTRUMENT
  std::cout
    << "Total factorization time " << timeTakenFac << "seconds." << std::endl ;
# endif
  return (returnCode) ;
}