source: trunk/Cbc/examples/ClpQuadInterface.cpp

Last change on this file was 2469, checked in by unxusr, 2 months ago

formatting

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1// $Id: ClpQuadInterface.cpp 2469 2019-01-06 23:17:46Z forrest $
2// Copyright (C) 2004, 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 <cassert>
7
8#include "CoinHelperFunctions.hpp"
9//#include "CoinIndexedVector.hpp"
10#include "ClpQuadraticObjective.hpp"
11#include "ClpLinearObjective.hpp"
12#include "ClpObjective.hpp"
13//#include "ClpSimplex.hpp"
14#include "ClpQuadInterface.hpp"
15//#############################################################################
16// Solve methods
17//#############################################################################
18void ClpQuadInterface::initialSolve()
19{
20  // save cutoff
21  double cutoff = modelPtr_->dualObjectiveLimit();
22  modelPtr_->setDualObjectiveLimit(1.0e50);
23  modelPtr_->scaling(0);
24  modelPtr_->setLogLevel(0);
25  // solve with no objective to get feasible solution
26  setBasis(basis_, modelPtr_);
27  modelPtr_->dual();
28  basis_ = getBasis(modelPtr_);
29  modelPtr_->setDualObjectiveLimit(cutoff);
30  if (modelPtr_->problemStatus()) {
31    assert(modelPtr_->problemStatus() == 1);
32    return;
33  }
34  ClpObjective *saveObjective = modelPtr_->objectiveAsObject();
35  modelPtr_->setObjectivePointer(quadraticObjective_);
36  //modelPtr_->setLogLevel(1);
37  // Could load up any data into a solver
38  modelPtr_->primal();
39  modelPtr_->setDualObjectiveLimit(cutoff);
40  if (modelPtr_->objectiveValue() > cutoff)
41    modelPtr_->setProblemStatus(1);
42  // zero reduced costs
43  // Should not have to as convex
44  //CoinZeroN(modelPtr_->dualRowSolution(),modelPtr_->numberRows());
45  //CoinZeroN(modelPtr_->dualColumnSolution(),modelPtr_->numberColumns());
46  modelPtr_->setObjectivePointer(saveObjective);
47}
48
49//-----------------------------------------------------------------------------
50void ClpQuadInterface::resolve()
51{
52  initialSolve();
53}
54
55//#############################################################################
56// Constructors, destructors clone and assignment
57//#############################################################################
58
59//-------------------------------------------------------------------
60// Default Constructor
61//-------------------------------------------------------------------
62ClpQuadInterface::ClpQuadInterface()
63  : OsiClpSolverInterface()
64{
65  quadraticObjective_ = NULL;
66}
67
68//-------------------------------------------------------------------
69// Clone
70//-------------------------------------------------------------------
71OsiSolverInterface *
72ClpQuadInterface::clone(bool CopyData) const
73{
74  if (CopyData) {
75    return new ClpQuadInterface(*this);
76  } else {
77    printf("warning ClpQuadInterface clone with copyData false\n");
78    return new ClpQuadInterface();
79  }
80}
81
82//-------------------------------------------------------------------
83// Copy constructor
84//-------------------------------------------------------------------
85ClpQuadInterface::ClpQuadInterface(
86  const ClpQuadInterface &rhs)
87  : OsiClpSolverInterface(rhs)
88{
89  if (rhs.quadraticObjective_)
90    quadraticObjective_ = rhs.quadraticObjective_->clone();
91  else
92    quadraticObjective_ = NULL;
93}
94
95//-------------------------------------------------------------------
96// Destructor
97//-------------------------------------------------------------------
98ClpQuadInterface::~ClpQuadInterface()
99{
100  delete quadraticObjective_;
101}
102
103//-------------------------------------------------------------------
104// Assignment operator
105//-------------------------------------------------------------------
106ClpQuadInterface &
107ClpQuadInterface::operator=(const ClpQuadInterface &rhs)
108{
109  if (this != &rhs) {
110    OsiClpSolverInterface::operator=(rhs);
111    if (rhs.quadraticObjective_)
112      quadraticObjective_ = rhs.quadraticObjective_->clone();
113    else
114      quadraticObjective_ = NULL;
115  }
116  return *this;
117}
118//-------------------------------------------------------------------
119// Real initializer
120//-------------------------------------------------------------------
121void ClpQuadInterface::initialize()
122{
123  // Save true objective and create a fake one
124  delete quadraticObjective_;
125  quadraticObjective_ = modelPtr_->objectiveAsObject();
126  ClpLinearObjective *linearObjective = new ClpLinearObjective(NULL, modelPtr_->numberColumns());
127  modelPtr_->setObjectivePointer(linearObjective);
128}
129// Get objective function value (can't use default)
130double
131ClpQuadInterface::getObjValue() const
132{
133  // first try easy way
134  return modelPtr_->objectiveValue();
135}
Note: See TracBrowser for help on using the repository browser.