source: trunk/Cbc/examples/ClpQuadInterface.cpp @ 1422

Last change on this file since 1422 was 270, checked in by forrest, 13 years ago

quad

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