-
Notifications
You must be signed in to change notification settings - Fork 117
/
ClpQuadInterface.cpp
134 lines (125 loc) · 4.32 KB
/
ClpQuadInterface.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
// Copyright (C) 2004, International Business Machines
// Corporation and others. All Rights Reserved.
// This code is licensed under the terms of the Eclipse Public License (EPL).
#include <cassert>
#include "CoinHelperFunctions.hpp"
//#include "CoinIndexedVector.hpp"
#include "ClpQuadraticObjective.hpp"
#include "ClpLinearObjective.hpp"
#include "ClpObjective.hpp"
//#include "ClpSimplex.hpp"
#include "ClpQuadInterface.hpp"
//#############################################################################
// Solve methods
//#############################################################################
void ClpQuadInterface::initialSolve()
{
// save cutoff
double cutoff = modelPtr_->dualObjectiveLimit();
modelPtr_->setDualObjectiveLimit(1.0e50);
modelPtr_->scaling(0);
modelPtr_->setLogLevel(0);
// solve with no objective to get feasible solution
setBasis(basis_, modelPtr_);
modelPtr_->dual();
basis_ = getBasis(modelPtr_);
modelPtr_->setDualObjectiveLimit(cutoff);
if (modelPtr_->problemStatus()) {
assert(modelPtr_->problemStatus() == 1);
return;
}
ClpObjective *saveObjective = modelPtr_->objectiveAsObject();
modelPtr_->setObjectivePointer(quadraticObjective_);
//modelPtr_->setLogLevel(1);
// Could load up any data into a solver
modelPtr_->primal();
modelPtr_->setDualObjectiveLimit(cutoff);
if (modelPtr_->objectiveValue() > cutoff)
modelPtr_->setProblemStatus(1);
// zero reduced costs
// Should not have to as convex
//CoinZeroN(modelPtr_->dualRowSolution(),modelPtr_->numberRows());
//CoinZeroN(modelPtr_->dualColumnSolution(),modelPtr_->numberColumns());
modelPtr_->setObjectivePointer(saveObjective);
}
//-----------------------------------------------------------------------------
void ClpQuadInterface::resolve()
{
initialSolve();
}
//#############################################################################
// Constructors, destructors clone and assignment
//#############################################################################
//-------------------------------------------------------------------
// Default Constructor
//-------------------------------------------------------------------
ClpQuadInterface::ClpQuadInterface()
: OsiClpSolverInterface()
{
quadraticObjective_ = NULL;
}
//-------------------------------------------------------------------
// Clone
//-------------------------------------------------------------------
OsiSolverInterface *
ClpQuadInterface::clone(bool CopyData) const
{
if (CopyData) {
return new ClpQuadInterface(*this);
} else {
printf("warning ClpQuadInterface clone with copyData false\n");
return new ClpQuadInterface();
}
}
//-------------------------------------------------------------------
// Copy constructor
//-------------------------------------------------------------------
ClpQuadInterface::ClpQuadInterface(
const ClpQuadInterface &rhs)
: OsiClpSolverInterface(rhs)
{
if (rhs.quadraticObjective_)
quadraticObjective_ = rhs.quadraticObjective_->clone();
else
quadraticObjective_ = NULL;
}
//-------------------------------------------------------------------
// Destructor
//-------------------------------------------------------------------
ClpQuadInterface::~ClpQuadInterface()
{
delete quadraticObjective_;
}
//-------------------------------------------------------------------
// Assignment operator
//-------------------------------------------------------------------
ClpQuadInterface &
ClpQuadInterface::operator=(const ClpQuadInterface &rhs)
{
if (this != &rhs) {
OsiClpSolverInterface::operator=(rhs);
if (rhs.quadraticObjective_)
quadraticObjective_ = rhs.quadraticObjective_->clone();
else
quadraticObjective_ = NULL;
}
return *this;
}
//-------------------------------------------------------------------
// Real initializer
//-------------------------------------------------------------------
void ClpQuadInterface::initialize()
{
// Save true objective and create a fake one
delete quadraticObjective_;
quadraticObjective_ = modelPtr_->objectiveAsObject();
ClpLinearObjective *linearObjective = new ClpLinearObjective(NULL, modelPtr_->numberColumns());
modelPtr_->setObjectivePointer(linearObjective);
}
// Get objective function value (can't use default)
double
ClpQuadInterface::getObjValue() const
{
// first try easy way
return modelPtr_->objectiveValue();
}