source: trunk/ClpPrimalColumnDantzig.cpp @ 73

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

Take out comment

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 KB
Line 
1// Copyright (C) 2002, International Business Machines
2// Corporation and others.  All Rights Reserved.
3
4#include "CoinPragma.hpp"
5
6#include <cstdio>
7
8#include "CoinIndexedVector.hpp"
9
10#include "ClpSimplex.hpp"
11#include "ClpPrimalColumnDantzig.hpp"
12#include "ClpFactorization.hpp"
13#include "ClpPackedMatrix.hpp"
14
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(CoinIndexedVector * updates,
60                                    CoinIndexedVector * spareRow1,
61                                    CoinIndexedVector * spareRow2,
62                                    CoinIndexedVector * spareColumn1,
63                                    CoinIndexedVector * 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    anyUpdates=true;
77    // add in pivot contribution
78    if (model_->pivotRow()>=0) 
79      updates->add(model_->pivotRow(),-dj);
80  } else if (model_->pivotRow()>=0) {
81    updates->insert(model_->pivotRow(),-dj);
82    anyUpdates=true;
83  } else {
84    // sub flip - nothing to do
85    anyUpdates=false;
86  }
87
88  if (anyUpdates) {
89    model_->factorization()->updateColumnTranspose(spareRow2,updates);
90    // put row of tableau in rowArray and columnArray
91    model_->clpMatrix()->transposeTimes(model_,-1.0,
92                                        updates,spareColumn2,spareColumn1);
93    for (iSection=0;iSection<2;iSection++) {
94     
95      reducedCost=model_->djRegion(iSection);
96     
97      if (!iSection) {
98        number = updates->getNumElements();
99        index = updates->getIndices();
100        updateBy = updates->denseVector();
101      } else {
102        number = spareColumn1->getNumElements();
103        index = spareColumn1->getIndices();
104        updateBy = spareColumn1->denseVector();
105      }
106     
107      for (j=0;j<number;j++) {
108        int iSequence = index[j];
109        double value = reducedCost[iSequence];
110        value -= updateBy[iSequence];
111        updateBy[iSequence]=0.0;
112        reducedCost[iSequence] = value;
113      }
114     
115    }
116    updates->setNumElements(0);
117    spareColumn1->setNumElements(0);
118  }
119
120
121  // update of duals finished - now do pricing
122
123  double largest=model_->currentPrimalTolerance();
124  // we can't really trust infeasibilities if there is primal error
125  if (model_->largestDualError()>1.0e-8)
126    largest *= model_->largestDualError()/1.0e-8;
127
128 
129
130  double bestDj = model_->dualTolerance();
131  int bestSequence=-1;
132
133  double bestFreeDj = model_->dualTolerance();
134  int bestFreeSequence=-1;
135 
136  number = model_->numberRows()+model_->numberColumns();
137  int iSequence;
138  reducedCost=model_->djRegion();
139
140  for (iSequence=0;iSequence<number;iSequence++) {
141    double value = reducedCost[iSequence];
142    if (!model_->fixed(iSequence)) {
143      ClpSimplex::Status status = model_->getStatus(iSequence);
144     
145      switch(status) {
146
147      case ClpSimplex::basic:
148        break;
149      case ClpSimplex::isFree:
150      case ClpSimplex::superBasic:
151        if (fabs(value)>bestFreeDj) { 
152          bestFreeDj = fabs(value);
153          bestFreeSequence = iSequence;
154        }
155        break;
156      case ClpSimplex::atUpperBound:
157        if (value>bestDj) {
158          bestDj = value;
159          bestSequence = iSequence;
160        }
161        break;
162      case ClpSimplex::atLowerBound:
163        if (value<-bestDj) {
164          bestDj = -value;
165          bestSequence = iSequence;
166        }
167      }
168    }
169  }
170  // bias towards free
171  if (bestFreeSequence>=0&&bestFreeDj > 0.1*bestDj) 
172    bestSequence = bestFreeSequence;
173  return bestSequence;
174}
175 
176//-------------------------------------------------------------------
177// Clone
178//-------------------------------------------------------------------
179ClpPrimalColumnPivot * ClpPrimalColumnDantzig::clone(bool CopyData) const
180{
181  if (CopyData) {
182    return new ClpPrimalColumnDantzig(*this);
183  } else {
184    return new ClpPrimalColumnDantzig();
185  }
186}
187
Note: See TracBrowser for help on using the repository browser.