source: branches/devel-1/ClpPrimalColumnDantzig.cpp @ 15

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

Hope this works from wincvs

Fix error in values pass

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 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
9#include "ClpSimplex.hpp"
10#include "ClpPrimalColumnDantzig.hpp"
11#include "OsiIndexedVector.hpp"
12#include "ClpFactorization.hpp"
13#include "ClpPackedMatrix.hpp"
14#include <stdio.h>
15//#############################################################################
16// Constructors / Destructor / Assignment
17//#############################################################################
18
19//-------------------------------------------------------------------
20// Default Constructor
21//-------------------------------------------------------------------
22ClpPrimalColumnDantzig::ClpPrimalColumnDantzig () 
23: ClpPrimalColumnPivot()
24{
25  type_=1;
26}
27
28//-------------------------------------------------------------------
29// Copy constructor
30//-------------------------------------------------------------------
31ClpPrimalColumnDantzig::ClpPrimalColumnDantzig (const ClpPrimalColumnDantzig & source) 
32: ClpPrimalColumnPivot(source)
33{ 
34
35}
36
37//-------------------------------------------------------------------
38// Destructor
39//-------------------------------------------------------------------
40ClpPrimalColumnDantzig::~ClpPrimalColumnDantzig ()
41{
42
43}
44
45//----------------------------------------------------------------
46// Assignment operator
47//-------------------------------------------------------------------
48ClpPrimalColumnDantzig &
49ClpPrimalColumnDantzig::operator=(const ClpPrimalColumnDantzig& rhs)
50{
51  if (this != &rhs) {
52    ClpPrimalColumnPivot::operator=(rhs);
53  }
54  return *this;
55}
56
57// Returns pivot column, -1 if none
58int 
59ClpPrimalColumnDantzig::pivotColumn(OsiIndexedVector * updates,
60                                    OsiIndexedVector * spareRow1,
61                                    OsiIndexedVector * spareRow2,
62                                    OsiIndexedVector * spareColumn1,
63                                    OsiIndexedVector * spareColumn2)
64{
65  assert(model_);
66  int iSection,j;
67  int number;
68  int * index;
69  double * updateBy;
70  double * reducedCost;
71  double dj = model_->dualIn();
72
73  bool anyUpdates;
74
75  if (updates->getNumElements()) {
76    // would have to have two goes for devex, three for steepest
77    anyUpdates=true;
78    // add in pivot contribution
79    if (model_->pivotRow()>=0) 
80      updates->add(model_->pivotRow(),-dj);
81  } else if (model_->pivotRow()>=0) {
82    updates->insert(model_->pivotRow(),-dj);
83    anyUpdates=true;
84  } else {
85    // sub flip - nothing to do
86    anyUpdates=false;
87  }
88
89  if (anyUpdates) {
90    model_->factorization()->updateColumnTranspose(spareRow2,updates);
91    // put row of tableau in rowArray and columnArray
92    model_->clpMatrix()->transposeTimes(model_,-1.0,
93                                        updates,spareColumn2,spareColumn1);
94    for (iSection=0;iSection<2;iSection++) {
95     
96      reducedCost=model_->djRegion(iSection);
97     
98      if (!iSection) {
99        number = updates->getNumElements();
100        index = updates->getIndices();
101        updateBy = updates->denseVector();
102      } else {
103        number = spareColumn1->getNumElements();
104        index = spareColumn1->getIndices();
105        updateBy = spareColumn1->denseVector();
106      }
107     
108      for (j=0;j<number;j++) {
109        int iSequence = index[j];
110        double value = reducedCost[iSequence];
111        value -= updateBy[iSequence];
112        updateBy[iSequence]=0.0;
113        reducedCost[iSequence] = value;
114      }
115     
116    }
117    updates->setNumElements(0);
118    spareColumn1->setNumElements(0);
119  }
120
121
122  // update of duals finished - now do pricing
123
124  double largest=model_->currentPrimalTolerance();
125  // we can't really trust infeasibilities if there is primal error
126  if (model_->largestDualError()>1.0e-8)
127    largest *= model_->largestDualError()/1.0e-8;
128
129 
130
131  double bestDj = model_->dualTolerance();
132  int bestSequence=-1;
133
134  double bestFreeDj = model_->dualTolerance();
135  int bestFreeSequence=-1;
136 
137  number = model_->numberRows()+model_->numberColumns();
138  int iSequence;
139  reducedCost=model_->djRegion();
140
141  for (iSequence=0;iSequence<number;iSequence++) {
142    double value = reducedCost[iSequence];
143    if (!model_->fixed(iSequence)) {
144      ClpSimplex::Status status = model_->getStatus(iSequence);
145     
146      switch(status) {
147
148      case ClpSimplex::basic:
149        break;
150      case ClpSimplex::isFree:
151      case ClpSimplex::superBasic:
152        if (fabs(value)>bestFreeDj) { 
153          bestFreeDj = fabs(value);
154          bestFreeSequence = iSequence;
155        }
156        break;
157      case ClpSimplex::atUpperBound:
158        if (value>bestDj) {
159          bestDj = value;
160          bestSequence = iSequence;
161        }
162        break;
163      case ClpSimplex::atLowerBound:
164        if (value<-bestDj) {
165          bestDj = -value;
166          bestSequence = iSequence;
167        }
168      }
169    }
170  }
171  // bias towards free
172  if (bestFreeSequence>=0&&bestFreeDj > 0.1*bestDj) 
173    bestSequence = bestFreeSequence;
174  return bestSequence;
175}
176 
177//-------------------------------------------------------------------
178// Clone
179//-------------------------------------------------------------------
180ClpPrimalColumnPivot * ClpPrimalColumnDantzig::clone(bool CopyData) const
181{
182  if (CopyData) {
183    return new ClpPrimalColumnDantzig(*this);
184  } else {
185    return new ClpPrimalColumnDantzig();
186  }
187}
188
Note: See TracBrowser for help on using the repository browser.