source: branches/devel/Cbc/src/CoinChooseVariable.cpp @ 438

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

add CoinChooseVariable?

File size: 4.2 KB
Line 
1// Copyright (C) 2006, International Business Machines
2// Corporation and others.  All Rights Reserved.
3#if defined(_MSC_VER)
4// Turn off compiler warning about long names
5#  pragma warning(disable:4786)
6#endif
7
8#include "CbcConfig.h"
9
10#include <string>
11#include <cassert>
12#include <cfloat>
13#include "OsiSolverInterface.hpp"
14#include "OsiAuxInfo.hpp"
15#include "OsiSolverBranch.hpp"
16#include "CoinWarmStartBasis.hpp"
17#include "CoinTime.hpp"
18#include "CoinChooseVariable.hpp"
19using namespace std;
20
21CoinChooseVariable::CoinChooseVariable() :
22  goodObjectiveValue_(COIN_DBL_MAX),
23  goodSolution_(NULL),
24  list_(NULL),
25  useful_(NULL),
26  solver_(NULL),
27  state_(-1),
28  numberUnsatisfied_(0),
29  numberStrong_(0),
30  numberOnList_(0),
31  trustStrongForBound_(true),
32  trustStrongForSolution_(true)
33{
34}
35
36CoinChooseVariable::CoinChooseVariable(const OsiSolverInterface * solver) :
37  goodObjectiveValue_(COIN_DBL_MAX),
38  goodSolution_(NULL),
39  solver_(solver),
40  state_(-1),
41  numberUnsatisfied_(0),
42  numberStrong_(0),
43  numberOnList_(0),
44  trustStrongForBound_(true),
45  trustStrongForSolution_(true)
46{
47  // create useful arrays
48  int numberObjects = solver_->numberObjects();
49  list_ = new int [numberObjects];
50  useful_ = new double [numberObjects];
51}
52
53CoinChooseVariable::CoinChooseVariable(const CoinChooseVariable & rhs) 
54{ 
55  goodObjectiveValue_ = rhs.goodObjectiveValue_;
56  state_ = rhs.state_;
57  numberUnsatisfied_ = rhs.numberUnsatisfied_;
58  numberStrong_ = rhs.numberStrong_;
59  numberOnList_ = rhs.numberOnList_;
60  trustStrongForBound_ = rhs.trustStrongForBound_;
61  trustStrongForSolution_ = rhs.trustStrongForSolution_;
62  solver_ = rhs.solver_;
63  if (solver_) {
64    int numberObjects = solver_->numberObjects();
65    int numberColumns = solver_->getNumCols();
66    if (rhs.goodSolution_) {
67      goodSolution_ = CoinCopyOfArray(rhs.goodSolution_,numberColumns);
68    } else {
69      goodSolution_ = NULL;
70    }
71    list_ = CoinCopyOfArray(rhs.list_,numberObjects);
72    useful_ = CoinCopyOfArray(rhs.useful_,numberObjects);
73  } else {
74    goodSolution_ = NULL;
75    list_ = NULL;
76    useful_ = NULL;
77  }
78}
79
80CoinChooseVariable &
81CoinChooseVariable::operator=(const CoinChooseVariable & rhs)
82{
83  if (this != &rhs) {
84    delete [] goodSolution_;
85    delete [] list_;
86    delete [] useful_;
87    goodObjectiveValue_ = rhs.goodObjectiveValue_;
88    state_ = rhs.state_;
89    numberUnsatisfied_ = rhs.numberUnsatisfied_;
90    numberStrong_ = rhs.numberStrong_;
91    numberOnList_ = rhs.numberOnList_;
92    trustStrongForBound_ = rhs.trustStrongForBound_;
93    trustStrongForSolution_ = rhs.trustStrongForSolution_;
94    solver_ = rhs.solver_;
95    if (solver_) {
96      int numberObjects = solver_->numberObjects();
97      int numberColumns = solver_->getNumCols();
98      if (rhs.goodSolution_) {
99        goodSolution_ = CoinCopyOfArray(rhs.goodSolution_,numberColumns);
100      } else {
101        goodSolution_ = NULL;
102      }
103      list_ = CoinCopyOfArray(rhs.list_,numberObjects);
104      useful_ = CoinCopyOfArray(rhs.useful_,numberObjects);
105    } else {
106      goodSolution_ = NULL;
107      list_ = NULL;
108      useful_ = NULL;
109    }
110  }
111  return *this;
112}
113
114
115CoinChooseVariable::~CoinChooseVariable ()
116{
117  delete [] goodSolution_;
118  delete [] list_;
119  delete [] useful_;
120}
121
122// Clone
123CoinChooseVariable *
124CoinChooseVariable::clone() const
125{
126  return new CoinChooseVariable(*this);
127}
128
129
130// Initialize
131void 
132CoinChooseVariable::initialize ( OsiBranchingInformation *info)
133{
134  state_=0;
135  assert (!goodSolution_);
136  goodObjectiveValue_ = COIN_DBL_MAX;
137}
138/* Choose a variable
139   Returns -
140   -1 Node is infeasible
141   0  Normal termination - we have a candidate
142   1  All looks satisfied - no candidate
143   2  We can change the bound on a variable - but we also have a strong branching candidate
144   3  We can change the bound on a variable - but we have a non-strong branching candidate
145   4  We can change the bound on a variable - no other candidates
146   We can pick up branch from whichObject() and whichWay()
147   We can pick up a forced branch (can change bound) from whichForcedObject() and whichForcedWay()
148   If we have a solution then we can pick up from goodObjectiveValue() and goodSolution()
149*/
150int 
151CoinChooseVariable::chooseVariable( OsiBranchingInformation *info)
152{
153}
154// Finish - deletes any solution etc
155void 
156CoinChooseVariable::finalize()
157{
158  state_=0;
159  delete [] goodSolution_;
160}
Note: See TracBrowser for help on using the repository browser.