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

Last change on this file since 2470 was 2385, checked in by unxusr, 9 months ago

formatting

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