source: trunk/Clp/src/ClpDualRowDantzig.cpp @ 1304

Last change on this file since 1304 was 1197, checked in by forrest, 12 years ago

many changes to try and improve performance

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