File: CbcCountRowCut.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 (731 lines) | stat: -rw-r--r-- 18,160 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
728
729
730
731
/* $Id: CbcCountRowCut.cpp 2124 2015-02-01 09:33:30Z forrest $ */
// 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).

#if defined(_MSC_VER)
// Turn off compiler warning about long names
#  pragma warning(disable:4786)
#endif
#include <cassert>

#include "OsiRowCut.hpp"
#include "CbcModel.hpp"
#include "CbcCountRowCut.hpp"
#include "CbcNode.hpp"
//#define CHECK_CUT_COUNTS
// Default Constructor
CbcCountRowCut::CbcCountRowCut ()
        :
        OsiRowCut(),
        owner_(NULL),
        ownerCut_(-1),
        numberPointingToThis_(0),
        whichCutGenerator_(-1)
{
#ifdef CHECK_CUT_COUNTS
    printf("CbcCountRowCut default constructor %x\n", this);
#endif
}

// Copy Constructor
CbcCountRowCut::CbcCountRowCut (const OsiRowCut & rhs)
        : OsiRowCut(rhs),
        owner_(NULL),
        ownerCut_(-1),
        numberPointingToThis_(0),
        whichCutGenerator_(-1)
{
#ifdef CHECK_CUT_COUNTS
    printf("CbcCountRowCut constructor %x from RowCut\n", this);
#endif
}
// Copy Constructor
CbcCountRowCut::CbcCountRowCut (const OsiRowCut & rhs,
                                CbcNodeInfo * info, int whichOne,
                                int whichGenerator,
                                int numberPointingToThis)
        : OsiRowCut(rhs),
        owner_(info),
        ownerCut_(whichOne),
        numberPointingToThis_(numberPointingToThis),
        whichCutGenerator_(whichGenerator)
{
#ifdef CHECK_CUT_COUNTS
    printf("CbcCountRowCut constructor %x from RowCut and info %d\n",
           this, numberPointingToThis_);
#endif
    //assert (!numberPointingToThis||numberPointingToThis==1000000000);
}
CbcCountRowCut::~CbcCountRowCut()
{
#ifdef CHECK_CUT_COUNTS
    printf("CbcCountRowCut destructor %x - references %d\n", this,
           numberPointingToThis_);
#endif
    // Look at owner and delete
    if (owner_)
        owner_->deleteCut(ownerCut_);
    ownerCut_ = -1234567;
}
// Increment number of references
void
CbcCountRowCut::increment(int change)
{
    assert(ownerCut_ != -1234567);
    numberPointingToThis_ += change;
}

// Decrement number of references and return number left
int
CbcCountRowCut::decrement(int change)
{
    assert(ownerCut_ != -1234567);
    // See if plausible number
    if (change < 900000000) {
        //assert(numberPointingToThis_>=change);
        assert(numberPointingToThis_ >= 0);
        if (numberPointingToThis_ < change) {
            assert(numberPointingToThis_ > 0);
            COIN_DETAIL_PRINT(printf("negative cut count %d - %d\n", numberPointingToThis_, change));
            change = numberPointingToThis_;
        }
        numberPointingToThis_ -= change;
    }
    return numberPointingToThis_;
}

// Set information
void
CbcCountRowCut::setInfo(CbcNodeInfo * info, int whichOne)
{
    owner_ = info;
    ownerCut_ = whichOne;
}
// Returns true if can drop cut if slack basic
bool
CbcCountRowCut::canDropCut(const OsiSolverInterface * solver, int iRow) const
{
    // keep if COIN_DBL_MAX otherwise keep if slack zero
    if (effectiveness() < 1.0e20) {
        return true;
    } else if (effectiveness() != COIN_DBL_MAX) {
        if (iRow >= solver->getNumRows())
            return true;
        const double * rowActivity = solver->getRowActivity();
        const double * rowLower = solver->getRowLower();
        const double * rowUpper = solver->getRowUpper();
        double tolerance;
        solver->getDblParam(OsiPrimalTolerance, tolerance) ;
        double value = rowActivity[iRow];
        if (value < rowLower[iRow] + tolerance ||
                value > rowUpper[iRow] - tolerance)
            return false;
        else
            return true;
    } else {
        return false;
    }
}
static double multiplier[] = {1.23456789e2,-9.87654321};
static int hashCut (const OsiRowCut2 & x, int size) 
{
  int xN =x.row().getNumElements();
  double xLb = x.lb();
  double xUb = x.ub();
  const int * xIndices = x.row().getIndices();
  const double * xElements = x.row().getElements();
  unsigned int hashValue;
  double value=1.0;
  if (xLb>-1.0e10)
    value += xLb*multiplier[0];
  if (xUb<1.0e10)
    value += xUb*multiplier[1];
  for( int j=0;j<xN;j++) {
    int xColumn = xIndices[j];
    double xValue = xElements[j];
    int k=(j&1);
    value += (j+1)*multiplier[k]*(xColumn+1)*xValue;
  }
  // should be compile time but too lazy for now
  if (sizeof(value)>sizeof(hashValue)) {
    assert (sizeof(value)==2*sizeof(hashValue));
    union { double d; int i[2]; } xx;
    xx.d = value;
    hashValue = (xx.i[0] + xx.i[1]);
  } else {
    assert (sizeof(value)==sizeof(hashValue));
    union { double d; unsigned int i[2]; } xx;
    xx.d = value;
    hashValue = xx.i[0];
  }
  return hashValue%(size);
}
static int hashCut2 (const OsiRowCut2 & x, int size) 
{
  int xN =x.row().getNumElements();
  double xLb = x.lb();
  double xUb = x.ub();
  const int * xIndices = x.row().getIndices();
  const double * xElements = x.row().getElements();
  unsigned int hashValue;
  double value=1.0;
  if (xLb>-1.0e10)
    value += xLb*multiplier[0];
  if (xUb<1.0e10)
    value += xUb*multiplier[1];
  for( int j=0;j<xN;j++) {
    int xColumn = xIndices[j];
    double xValue = xElements[j];
    int k=(j&1);
    value += (j+1)*multiplier[k]*(xColumn+1)*xValue;
  }
  // should be compile time but too lazy for now
  if (sizeof(value)>sizeof(hashValue)) {
    assert (sizeof(value)==2*sizeof(hashValue));
    union { double d; int i[2]; } xx;
    xx.d = value;
    hashValue = (xx.i[0] + xx.i[1]);
  } else {
    assert (sizeof(value)==sizeof(hashValue));
    union { double d; unsigned int i[2]; } xx;
    xx.d = value;
    hashValue = xx.i[0];
  }
  return hashValue%(size);
}
static bool same (const OsiRowCut2 & x, const OsiRowCut2 & y) 
{
  int xN =x.row().getNumElements();
  int yN =y.row().getNumElements();
  bool identical=false;
  if (xN==yN) {
    double xLb = x.lb();
    double xUb = x.ub();
    double yLb = y.lb();
    double yUb = y.ub();
    if (fabs(xLb-yLb)<1.0e-8&&fabs(xUb-yUb)<1.0e-8) {
      const int * xIndices = x.row().getIndices();
      const double * xElements = x.row().getElements();
      const int * yIndices = y.row().getIndices();
      const double * yElements = y.row().getElements();
      int j;
      for( j=0;j<xN;j++) {
	if (xIndices[j]!=yIndices[j])
	  break;
	if (fabs(xElements[j]-yElements[j])>1.0e-12)
	  break;
      }
      identical =  (j==xN);
    }
  }
  return identical;
}
static bool same2 (const OsiRowCut2 & x, const OsiRowCut2 & y) 
{
  int xN =x.row().getNumElements();
  int yN =y.row().getNumElements();
  bool identical=false;
  if (xN==yN) {
    double xLb = x.lb();
    double xUb = x.ub();
    double yLb = y.lb();
    double yUb = y.ub();
    if (fabs(xLb-yLb)<1.0e-8&&fabs(xUb-yUb)<1.0e-8) {
      const int * xIndices = x.row().getIndices();
      const double * xElements = x.row().getElements();
      const int * yIndices = y.row().getIndices();
      const double * yElements = y.row().getElements();
      int j;
      for( j=0;j<xN;j++) {
	if (xIndices[j]!=yIndices[j])
	  break;
	if (fabs(xElements[j]-yElements[j])>1.0e-12)
	  break;
      }
      identical =  (j==xN);
    }
  }
  return identical;
}
CbcRowCuts::CbcRowCuts(int initialMaxSize, int hashMultiplier)
{
  numberCuts_=0;
  size_ = initialMaxSize;
  hashMultiplier_ = hashMultiplier;
  int hashSize=hashMultiplier_*size_;
  if (size_) {
    rowCut_ = new  OsiRowCut2 * [size_];
    hash_ = new CoinHashLink[hashSize];
  } else {
    rowCut_ = NULL;
    hash_ = NULL;
  }
  for (int i=0;i<hashSize;i++) {
    hash_[i].index=-1;
    hash_[i].next=-1;
  }
  lastHash_=-1;
}
CbcRowCuts::~CbcRowCuts()
{
  for (int i=0;i<numberCuts_;i++)
    delete rowCut_[i];
  delete [] rowCut_;
  delete [] hash_;
}
CbcRowCuts::CbcRowCuts(const CbcRowCuts& rhs)
{
  numberCuts_=rhs.numberCuts_;
  hashMultiplier_ = rhs.hashMultiplier_;
  size_ = rhs.size_;
  int hashSize= size_*hashMultiplier_;
  lastHash_=rhs.lastHash_;
  if (size_) {
    rowCut_ = new  OsiRowCut2 * [size_];
    hash_ = new CoinHashLink[hashSize];
    for (int i=0;i<hashSize;i++) {
      hash_[i] = rhs.hash_[i];
    }
    for (int i=0;i<numberCuts_;i++) {
      if (rhs.rowCut_[i])
	rowCut_[i]=new OsiRowCut2(*rhs.rowCut_[i]);
      else
	rowCut_[i]=NULL;
    }
  } else {
    rowCut_ = NULL;
    hash_ = NULL;
  }
}
CbcRowCuts& 
CbcRowCuts::operator=(const CbcRowCuts& rhs)
{
  if (this != &rhs) {
    for (int i=0;i<numberCuts_;i++)
      delete rowCut_[i];
    delete [] rowCut_;
    delete [] hash_;
    numberCuts_=rhs.numberCuts_;
    hashMultiplier_ = rhs.hashMultiplier_;
    size_ = rhs.size_;
    lastHash_=rhs.lastHash_;
    if (size_) {
      rowCut_ = new  OsiRowCut2 * [size_];
      int hashSize= size_*hashMultiplier_;
      hash_ = new CoinHashLink[hashSize];
      for (int i=0;i<hashSize;i++) {
	hash_[i] = rhs.hash_[i];
      }
      for (int i=0;i<numberCuts_;i++) {
	if (rhs.rowCut_[i])
	  rowCut_[i]=new OsiRowCut2(*rhs.rowCut_[i]);
	else
	  rowCut_[i]=NULL;
      }
    } else {
      rowCut_ = NULL;
      hash_ = NULL;
    }
  }
  return *this;
}
void 
CbcRowCuts::eraseRowCut(int sequence)
{
  // find
  assert (sequence>=0&&sequence<numberCuts_);
  OsiRowCut2 * cut = rowCut_[sequence];
  int hashSize= size_*hashMultiplier_;
  int ipos = hashCut(*cut,hashSize);
  int found = -1;
  while ( true ) {
    int j1 = hash_[ipos].index;
    if ( j1 >= 0 ) {
      if (j1!=sequence) {
	int k = hash_[ipos].next;
	if ( k != -1 )
	  ipos = k;
	else
	  break;
      } else {
	found = j1;
	break;
      }
    } else {
      break;
    }
  }
  assert (found>=0);
  assert (hash_[ipos].index==sequence);
  // shuffle up
  while (hash_[ipos].next>=0) {
    int k = hash_[ipos].next;
    hash_[ipos]=hash_[k];
    ipos=k;
  }
  hash_[ipos].index=-1;
  // move last to found
  numberCuts_--;
  assert (found==numberCuts_); // debug when fails
  if (numberCuts_&&found<numberCuts_) {
    ipos = hashCut(*rowCut_[numberCuts_],hashSize);
    while ( true ) {
      int j1 = hash_[ipos].index;
      if (j1!=numberCuts_) {
	int k = hash_[ipos].next;
	ipos = k;
	assert (ipos>=0);
      } else {
	// change
	hash_[ipos].index=found;
	rowCut_[found]=rowCut_[numberCuts_];
	rowCut_[numberCuts_]=NULL;
	break;
      }
    }
  }
  delete cut;
  rowCut_[numberCuts_]=NULL;
  //assert (!rowCut_[numberCuts_-1]);
}
// Truncate
void 
CbcRowCuts::truncate(int numberAfter)
{
  if (numberAfter<0||numberAfter>=numberCuts_)
    return;
  for (int i=numberAfter;i<numberCuts_;i++) {
    delete rowCut_[i];
    rowCut_[i]=NULL;
  }
  numberCuts_=numberAfter;
  int hashSize= size_*hashMultiplier_;
  for (int i=0;i<hashSize;i++) {
    hash_[i].index=-1;
    hash_[i].next=-1;
  }
  OsiRowCut2 ** temp = new  OsiRowCut2 * [size_];
  lastHash_=-1;
  for (int i=0;i<numberCuts_;i++) {
    temp[i]=rowCut_[i];
    int ipos = hashCut(*temp[i],hashSize);
    int found = -1;
    int jpos=ipos;
    while ( true ) {
      int j1 = hash_[ipos].index;
      if ( j1 >= 0 ) {
	if ( !same(*temp[i],*temp[j1]) ) {
	  int k = hash_[ipos].next;
	  if ( k != -1 )
	    ipos = k;
	  else
	    break;
	} else {
	  found = j1;
	  break;
	}
      } else {
	break;
      }
    }
    if (found<0) {
      assert (hash_[ipos].next==-1);
      if (ipos==jpos) {
	// first
	hash_[ipos].index=i;
      } else {
	// find next space 
	while ( true ) {
	  ++lastHash_;
	  assert (lastHash_<hashSize);
	  if ( hash_[lastHash_].index == -1 ) 
	    break;
	}
	hash_[ipos].next = lastHash_;
	hash_[lastHash_].index = i;
      }
    }
  }
  delete [] rowCut_;
  rowCut_ = temp;
}
// Return 0 if added, 1 if not, -1 if not added because of space
int 
CbcRowCuts::addCutIfNotDuplicate(const OsiRowCut & cut,int whichType)
{
  int hashSize= size_*hashMultiplier_;
  bool globallyValid=cut.globallyValid();
  if (numberCuts_==size_) {
    size_ = 2*size_+100;
    hashSize=hashMultiplier_*size_;
    OsiRowCut2 ** temp = new  OsiRowCut2 * [size_];
    delete [] hash_;
    hash_ = new CoinHashLink[hashSize];
    for (int i=0;i<hashSize;i++) {
      hash_[i].index=-1;
      hash_[i].next=-1;
    }
    lastHash_=-1;
    for (int i=0;i<numberCuts_;i++) {
      temp[i]=rowCut_[i];
      int ipos = hashCut(*temp[i],hashSize);
      int found = -1;
      int jpos=ipos;
      while ( true ) {
	int j1 = hash_[ipos].index;
	
	if ( j1 >= 0 ) {
	  if ( !same(*temp[i],*temp[j1]) ) {
	    int k = hash_[ipos].next;
	    if ( k != -1 )
	      ipos = k;
	    else
	      break;
	  } else {
	    found = j1;
	    break;
	  }
	} else {
	  break;
	}
      }
      if (found<0) {
	assert (hash_[ipos].next==-1);
	if (ipos==jpos) {
	  // first
	  hash_[ipos].index=i;
	} else {
	  // find next space 
	  while ( true ) {
	    ++lastHash_;
	    assert (lastHash_<hashSize);
	    if ( hash_[lastHash_].index == -1 ) 
	      break;
	  }
	  hash_[ipos].next = lastHash_;
	  hash_[lastHash_].index = i;
	}
      }
    }
    delete [] rowCut_;
    rowCut_ = temp;
  }
  if (numberCuts_<size_) {
    double newLb = cut.lb();
    double newUb = cut.ub();
    CoinPackedVector vector = cut.row();
    int numberElements =vector.getNumElements();
    int * newIndices = vector.getIndices();
    double * newElements = vector.getElements();
    CoinSort_2(newIndices,newIndices+numberElements,newElements);
    int i;
    bool bad=false;
    for (i=0;i<numberElements;i++) {
      double value = fabs(newElements[i]);
      if (value<1.0e-12||value>1.0e12) 
	bad=true;
    }
    if (bad)
      return 1;
    OsiRowCut2 newCut(whichType);
    newCut.setLb(newLb);
    newCut.setUb(newUb);
    newCut.setRow(vector);
    int ipos = hashCut(newCut,hashSize);
    int found = -1;
    int jpos=ipos;
    while ( true ) {
      int j1 = hash_[ipos].index;
      
      if ( j1 >= 0 ) {
	if ( !same(newCut,*rowCut_[j1]) ) {
	  int k = hash_[ipos].next;
	  if ( k != -1 )
	    ipos = k;
	  else
	    break;
	} else {
	  found = j1;
	  break;
	}
      } else {
	break;
      }
    }
    if (found<0) {
      assert (hash_[ipos].next==-1);
      if (ipos==jpos) {
	// first
	hash_[ipos].index=numberCuts_;
      } else {
	// find next space 
	while ( true ) {
	  ++lastHash_;
	  assert (lastHash_<hashSize);
	  if ( hash_[lastHash_].index == -1 ) 
	    break;
	}
	hash_[ipos].next = lastHash_;
	hash_[lastHash_].index = numberCuts_;
      }
      OsiRowCut2 * newCutPtr = new OsiRowCut2(whichType);
      newCutPtr->setLb(newLb);
      newCutPtr->setUb(newUb);
      newCutPtr->setRow(vector);
      newCutPtr->setGloballyValid(globallyValid);
      rowCut_[numberCuts_++]=newCutPtr;
      //printf("addedGlobalCut of size %d to %x - cuts size %d\n",
      //     cut.row().getNumElements(),this,numberCuts_);
      return 0;
    } else {
      return 1;
    }
  } else {
    return -1;
  }
}
// Return 0 if added, 1 if not, -1 if not added because of space
int 
CbcRowCuts::addCutIfNotDuplicateWhenGreedy(const OsiRowCut & cut,int whichType)
{
  int hashSize= size_*hashMultiplier_;
  if (numberCuts_==size_) {
    size_ = 2*size_+100;
    hashSize=hashMultiplier_*size_;
    OsiRowCut2 ** temp = new  OsiRowCut2 * [size_];
    delete [] hash_;
    hash_ = new CoinHashLink[hashSize];
    for (int i=0;i<hashSize;i++) {
      hash_[i].index=-1;
      hash_[i].next=-1;
    }
    lastHash_=-1;
    for (int i=0;i<numberCuts_;i++) {
      temp[i]=rowCut_[i];
      int ipos = hashCut2(*temp[i],hashSize);
      int found = -1;
      int jpos=ipos;
      while ( true ) {
	int j1 = hash_[ipos].index;
	
	if ( j1 >= 0 ) {
	  if ( !same2(*temp[i],*temp[j1]) ) {
	    int k = hash_[ipos].next;
	    if ( k != -1 )
	      ipos = k;
	    else
	      break;
	  } else {
	    found = j1;
	    break;
	  }
	} else {
	  break;
	}
      }
      if (found<0) {
	assert (hash_[ipos].next==-1);
	if (ipos==jpos) {
	  // first
	  hash_[ipos].index=i;
	} else {
	  // find next space 
	  while ( true ) {
	    ++lastHash_;
	    assert (lastHash_<hashSize);
	    if ( hash_[lastHash_].index == -1 ) 
	      break;
	  }
	  hash_[ipos].next = lastHash_;
	  hash_[lastHash_].index = i;
	}
      }
    }
    delete [] rowCut_;
    rowCut_ = temp;
  }
  if (numberCuts_<size_) {
    double newLb = cut.lb();
    double newUb = cut.ub();
    CoinPackedVector vector = cut.row();
    int numberElements =vector.getNumElements();
    int * newIndices = vector.getIndices();
    double * newElements = vector.getElements();
    CoinSort_2(newIndices,newIndices+numberElements,newElements);
    int i;
    bool bad=false;
    for (i=0;i<numberElements;i++) {
      double value = fabs(newElements[i]);
      if (value<1.0e-12||value>1.0e12) 
	bad=true;
    }
    if (bad)
      return 1;
    OsiRowCut2 newCut(whichType);
    newCut.setLb(newLb);
    newCut.setUb(newUb);
    newCut.setRow(vector);
    int ipos = hashCut2(newCut,hashSize);
    int found = -1;
    int jpos=ipos;
    while ( true ) {
      int j1 = hash_[ipos].index;
      
      if ( j1 >= 0 ) {
	if ( !same2(newCut,*rowCut_[j1]) ) {
	  int k = hash_[ipos].next;
	  if ( k != -1 )
	    ipos = k;
	  else
	    break;
	} else {
	  found = j1;
	  break;
	}
      } else {
	break;
      }
    }
    if (found<0) {
      assert (hash_[ipos].next==-1);
      if (ipos==jpos) {
	// first
	hash_[ipos].index=numberCuts_;
      } else {
	// find next space 
	while ( true ) {
	  ++lastHash_;
	  assert (lastHash_<hashSize);
	  if ( hash_[lastHash_].index == -1 ) 
	    break;
	}
	hash_[ipos].next = lastHash_;
	hash_[lastHash_].index = numberCuts_;
      }
      OsiRowCut2 * newCutPtr = new OsiRowCut2(whichType);
      newCutPtr->setLb(newLb);
      newCutPtr->setUb(newUb);
      newCutPtr->setRow(vector);
      rowCut_[numberCuts_++]=newCutPtr;
      //printf("addedGreedyGlobalCut of size %d to %p - cuts size %d\n",
      //     cut.row().getNumElements(),this,numberCuts_);
      return 0;
    } else {
      return 1;
    }
  } else {
    return -1;
  }
}
// Add in cuts as normal cuts and delete
void 
CbcRowCuts::addCuts(OsiCuts & cs)
{
  for (int i=0;i<numberCuts_;i++) {
    cs.insert(*rowCut_[i]);
    delete rowCut_[i] ;
    rowCut_[i] = NULL ;
  }
  numberCuts_=0;
}