source: trunk/ClpDualRowDantzig.cpp @ 225

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

This should break everything

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