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