source: tags/move-to-subversion/ClpDualRowDantzig.cpp @ 753

Last change on this file since 753 was 399, checked in by forrest, 16 years ago

to CoinMax? and CoinMin?

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 KB
Line 
1// Copyright (C) 2002, International Business Machines
2// Corporation and others.  All Rights Reserved.
3
4#include "CoinPragma.hpp"
5#include "ClpSimplex.hpp"
6#include "ClpDualRowDantzig.hpp"
7#include "CoinIndexedVector.hpp"
8#include "CoinHelperFunctions.hpp"
9
10//#############################################################################
11// Constructors / Destructor / Assignment
12//#############################################################################
13
14//-------------------------------------------------------------------
15// Default Constructor
16//-------------------------------------------------------------------
17ClpDualRowDantzig::ClpDualRowDantzig () 
18: ClpDualRowPivot()
19{
20  type_=1;
21}
22
23//-------------------------------------------------------------------
24// Copy constructor
25//-------------------------------------------------------------------
26ClpDualRowDantzig::ClpDualRowDantzig (const ClpDualRowDantzig & source) 
27: ClpDualRowPivot(source)
28{ 
29
30}
31
32//-------------------------------------------------------------------
33// Destructor
34//-------------------------------------------------------------------
35ClpDualRowDantzig::~ClpDualRowDantzig ()
36{
37
38}
39
40//----------------------------------------------------------------
41// Assignment operator
42//-------------------------------------------------------------------
43ClpDualRowDantzig &
44ClpDualRowDantzig::operator=(const ClpDualRowDantzig& rhs)
45{
46  if (this != &rhs) {
47    ClpDualRowPivot::operator=(rhs);
48  }
49  return *this;
50}
51
52// Returns pivot row, -1 if none
53int 
54ClpDualRowDantzig::pivotRow()
55{
56  assert(model_);
57  int iRow;
58  const int * pivotVariable = model_->pivotVariable();
59  double largest=model_->currentPrimalTolerance();
60  // we can't really trust infeasibilities if there is primal error
61  if (model_->largestPrimalError()>1.0e-8)
62    largest *= model_->largestPrimalError()/1.0e-8;
63  int chosenRow=-1;
64  for (iRow=0;iRow<model_->numberRows();iRow++) {
65    int iPivot=pivotVariable[iRow];
66    double value = model_->solution(iPivot);
67    double lower = model_->lower(iPivot);
68    double upper = model_->upper(iPivot);
69    if (CoinMax(value-upper,lower-value)>largest) {
70      int iSequence = pivotVariable[iRow];
71      if (!model_->flagged(iSequence)) {
72        chosenRow=iRow;
73        largest=CoinMax(value-upper,lower-value);
74      }
75    }
76  }
77  return chosenRow;
78}
79// Returns pivot alpha
80double
81ClpDualRowDantzig::updateWeights(CoinIndexedVector * input,
82                                  CoinIndexedVector * spare,
83                                  CoinIndexedVector * updatedColumn)
84{
85  // pivot element
86  double alpha=0.0;
87  // look at updated column
88  double * work = updatedColumn->denseVector();
89  int number = updatedColumn->getNumElements();
90  int * which = updatedColumn->getIndices();
91  int i;
92  int pivotRow = model_->pivotRow();
93
94  if (updatedColumn->packedMode()) {
95    for (i =0; i < number; i++) {
96      int iRow = which[i];
97      if (iRow==pivotRow) {
98        alpha = work[i];
99        break;
100      }
101    }
102  } else {
103    alpha = work[pivotRow];
104  }
105  return alpha;
106}
107 
108/* Updates primal solution (and maybe list of candidates)
109   Uses input vector which it deletes
110   Computes change in objective function
111*/
112void 
113ClpDualRowDantzig::updatePrimalSolution(CoinIndexedVector * primalUpdate,
114                                        double primalRatio,
115                                        double & objectiveChange)
116{
117  double * work = primalUpdate->denseVector();
118  int number = primalUpdate->getNumElements();
119  int * which = primalUpdate->getIndices();
120  int i;
121  double changeObj=0.0;
122  const int * pivotVariable = model_->pivotVariable();
123  if (primalUpdate->packedMode()) {
124    for (i=0;i<number;i++) {
125      int iRow=which[i];
126      int iPivot=pivotVariable[iRow];
127      double & value = model_->solutionAddress(iPivot);
128      double cost = model_->cost(iPivot);
129      double change = primalRatio*work[i];
130      value -= change;
131      changeObj -= change*cost;
132      work[i]=0.0;
133    }
134  } else {
135    for (i=0;i<number;i++) {
136      int iRow=which[i];
137      int iPivot=pivotVariable[iRow];
138      double & value = model_->solutionAddress(iPivot);
139      double cost = model_->cost(iPivot);
140      double change = primalRatio*work[iRow];
141      value -= change;
142      changeObj -= change*cost;
143      work[iRow]=0.0;
144    }
145  }
146  primalUpdate->setNumElements(0);
147  objectiveChange += changeObj;
148}
149//-------------------------------------------------------------------
150// Clone
151//-------------------------------------------------------------------
152ClpDualRowPivot * ClpDualRowDantzig::clone(bool CopyData) const
153{
154  if (CopyData) {
155    return new ClpDualRowDantzig(*this);
156  } else {
157    return new ClpDualRowDantzig();
158  }
159}
160
Note: See TracBrowser for help on using the repository browser.