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

Last change on this file since 1402 was 1402, checked in by forrest, 10 years ago

get rid of compiler warnings

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