source: tags/clp-0-94-0/ClpDualRowDantzig.cpp @ 1814

Last change on this file since 1814 was 63, checked in by jpfasano, 17 years ago

-modified to use CoinPragma?.h
-modified to compile w/MS Visual C++ and gcc (on cygwin) without errors or warnings.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.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 
79/* Updates primal solution (and maybe list of candidates)
80   Uses input vector which it deletes
81   Computes change in objective function
82*/
83void 
84ClpDualRowDantzig::updatePrimalSolution(CoinIndexedVector * primalUpdate,
85                                        double primalRatio,
86                                        double & objectiveChange)
87{
88  double * work = primalUpdate->denseVector();
89  int number = primalUpdate->getNumElements();
90  int * which = primalUpdate->getIndices();
91  int i;
92  double changeObj=0.0;
93  const int * pivotVariable = model_->pivotVariable();
94  for (i=0;i<number;i++) {
95    int iRow=which[i];
96    int iPivot=pivotVariable[iRow];
97    double & value = model_->solutionAddress(iPivot);
98    double cost = model_->cost(iPivot);
99    double change = primalRatio*work[iRow];
100    value -= change;
101    changeObj -= change*cost;
102    work[iRow]=0.0;
103  }
104  primalUpdate->setNumElements(0);
105  objectiveChange += changeObj;
106}
107//-------------------------------------------------------------------
108// Clone
109//-------------------------------------------------------------------
110ClpDualRowPivot * ClpDualRowDantzig::clone(bool CopyData) const
111{
112  if (CopyData) {
113    return new ClpDualRowDantzig(*this);
114  } else {
115    return new ClpDualRowDantzig();
116  }
117}
118
Note: See TracBrowser for help on using the repository browser.