source: trunk/Cbc/examples/ClpQuadInterface.cpp

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

formatting

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
RevLine 
[1574]1// $Id: ClpQuadInterface.cpp 2469 2019-01-06 23:17:46Z stefan $
[12]2// Copyright (C) 2004, International Business Machines
3// Corporation and others.  All Rights Reserved.
[1574]4// This code is licensed under the terms of the Eclipse Public License (EPL).
[12]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
[2469]26  setBasis(basis_, modelPtr_);
[12]27  modelPtr_->dual();
28  basis_ = getBasis(modelPtr_);
29  modelPtr_->setDualObjectiveLimit(cutoff);
30  if (modelPtr_->problemStatus()) {
[2469]31    assert(modelPtr_->problemStatus() == 1);
[12]32    return;
33  }
[2469]34  ClpObjective *saveObjective = modelPtr_->objectiveAsObject();
[12]35  modelPtr_->setObjectivePointer(quadraticObjective_);
[270]36  //modelPtr_->setLogLevel(1);
[12]37  // Could load up any data into a solver
38  modelPtr_->primal();
39  modelPtr_->setDualObjectiveLimit(cutoff);
[2469]40  if (modelPtr_->objectiveValue() > cutoff)
[12]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//-------------------------------------------------------------------
[2469]60// Default Constructor
[12]61//-------------------------------------------------------------------
[2469]62ClpQuadInterface::ClpQuadInterface()
[12]63  : OsiClpSolverInterface()
64{
[2469]65  quadraticObjective_ = NULL;
[12]66}
67
68//-------------------------------------------------------------------
69// Clone
70//-------------------------------------------------------------------
[2469]71OsiSolverInterface *
[12]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//-------------------------------------------------------------------
[2469]83// Copy constructor
[12]84//-------------------------------------------------------------------
[2469]85ClpQuadInterface::ClpQuadInterface(
86  const ClpQuadInterface &rhs)
[12]87  : OsiClpSolverInterface(rhs)
88{
89  if (rhs.quadraticObjective_)
[2469]90    quadraticObjective_ = rhs.quadraticObjective_->clone();
[12]91  else
[2469]92    quadraticObjective_ = NULL;
[12]93}
94
95//-------------------------------------------------------------------
[2469]96// Destructor
[12]97//-------------------------------------------------------------------
[2469]98ClpQuadInterface::~ClpQuadInterface()
[12]99{
100  delete quadraticObjective_;
101}
102
103//-------------------------------------------------------------------
[2469]104// Assignment operator
[12]105//-------------------------------------------------------------------
106ClpQuadInterface &
[2469]107ClpQuadInterface::operator=(const ClpQuadInterface &rhs)
[12]108{
[2469]109  if (this != &rhs) {
[12]110    OsiClpSolverInterface::operator=(rhs);
111    if (rhs.quadraticObjective_)
[2469]112      quadraticObjective_ = rhs.quadraticObjective_->clone();
[12]113    else
[2469]114      quadraticObjective_ = NULL;
[12]115  }
116  return *this;
117}
118//-------------------------------------------------------------------
119// Real initializer
120//-------------------------------------------------------------------
[2469]121void ClpQuadInterface::initialize()
[12]122{
123  // Save true objective and create a fake one
124  delete quadraticObjective_;
125  quadraticObjective_ = modelPtr_->objectiveAsObject();
[2469]126  ClpLinearObjective *linearObjective = new ClpLinearObjective(NULL, modelPtr_->numberColumns());
[12]127  modelPtr_->setObjectivePointer(linearObjective);
128}
129// Get objective function value (can't use default)
[2469]130double
[12]131ClpQuadInterface::getObjValue() const
132{
133  // first try easy way
134  return modelPtr_->objectiveValue();
135}
Note: See TracBrowser for help on using the repository browser.