source: trunk/Cbc/examples/ClpQuadInterface.cpp

Last change on this file was 1574, checked in by lou, 7 years ago

Change to EPL license notice.

  • 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 1574 2011-01-05 01:13:55Z 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//-------------------------------------------------------------------
84// Copy constructor
85//-------------------------------------------------------------------
86ClpQuadInterface::ClpQuadInterface (
87                  const ClpQuadInterface & rhs)
88  : OsiClpSolverInterface(rhs)
89{
90  if (rhs.quadraticObjective_)
91    quadraticObjective_=rhs.quadraticObjective_->clone();
92  else
93    quadraticObjective_=NULL;
94}
95
96//-------------------------------------------------------------------
97// Destructor
98//-------------------------------------------------------------------
99ClpQuadInterface::~ClpQuadInterface ()
100{
101  delete quadraticObjective_;
102}
103
104//-------------------------------------------------------------------
105// Assignment operator
106//-------------------------------------------------------------------
107ClpQuadInterface &
108ClpQuadInterface::operator=(const ClpQuadInterface& rhs)
109{
110  if (this != &rhs) { 
111    OsiClpSolverInterface::operator=(rhs);
112    if (rhs.quadraticObjective_)
113      quadraticObjective_=rhs.quadraticObjective_->clone();
114    else
115      quadraticObjective_=NULL;
116  }
117  return *this;
118}
119//-------------------------------------------------------------------
120// Real initializer
121//-------------------------------------------------------------------
122void
123ClpQuadInterface::initialize ()
124{
125  // Save true objective and create a fake one
126  delete quadraticObjective_;
127  quadraticObjective_ = modelPtr_->objectiveAsObject();
128  ClpLinearObjective * linearObjective = new ClpLinearObjective(NULL,modelPtr_->numberColumns());
129  modelPtr_->setObjectivePointer(linearObjective);
130}
131// Get objective function value (can't use default)
132double 
133ClpQuadInterface::getObjValue() const
134{
135  // first try easy way
136  return modelPtr_->objectiveValue();
137}
Note: See TracBrowser for help on using the repository browser.