1 | /*===========================================================================* |
---|
2 | * This file is part of the Abstract Library for Parallel Search (ALPS). * |
---|
3 | * * |
---|
4 | * ALPS is distributed under the Common Public License as part of the * |
---|
5 | * COIN-OR repository (http://www.coin-or.org). * |
---|
6 | * * |
---|
7 | * Authors: Yan Xu, SAS Institute Inc. * |
---|
8 | * Ted Ralphs, Lehigh University * |
---|
9 | * Laszlo Ladanyi, IBM T.J. Watson Research Center * |
---|
10 | * Matthew Saltzman, Clemson University * |
---|
11 | * * |
---|
12 | * * |
---|
13 | * Copyright (C) 2001-2004, International Business Machines * |
---|
14 | * Corporation, Lehigh University, Yan Xu, Ted Ralphs, Matthew Salzman and * |
---|
15 | * others. All Rights Reserved. * |
---|
16 | *===========================================================================*/ |
---|
17 | |
---|
18 | #ifndef AbcTreeNode_h_ |
---|
19 | #define AbcTreeNode_h_ |
---|
20 | |
---|
21 | //#include <utility> |
---|
22 | #include "AlpsKnowledgeBroker.h" |
---|
23 | #include "AlpsTreeNode.h" |
---|
24 | |
---|
25 | #include "AbcModel.h" |
---|
26 | #include "AbcNodeDesc.h" |
---|
27 | |
---|
28 | //############################################################################# |
---|
29 | |
---|
30 | enum AbcVarStatus { |
---|
31 | AbcVarFree, |
---|
32 | AbcVarFixedToUB, |
---|
33 | AbcVarFixedToLB |
---|
34 | }; |
---|
35 | |
---|
36 | //############################################################################# |
---|
37 | |
---|
38 | class AbcTreeNode : public AlpsTreeNode { |
---|
39 | private: |
---|
40 | // NO: default constructor, copy constructor, assignment operator |
---|
41 | AbcTreeNode(const AbcTreeNode&); |
---|
42 | AbcTreeNode& operator=(const AbcTreeNode&); |
---|
43 | |
---|
44 | private: |
---|
45 | /** The index of the branching variable */ |
---|
46 | int branchedOn_; |
---|
47 | |
---|
48 | /** The solution value (non-integral) of the branching variable. */ |
---|
49 | double branchedOnVal_; |
---|
50 | |
---|
51 | /** Branching direction */ |
---|
52 | int branchedDir_; |
---|
53 | |
---|
54 | /// Guessed satisfied Objective value |
---|
55 | double guessedObjectiveValue_; |
---|
56 | |
---|
57 | /// The number of objects unsatisfied at this node. |
---|
58 | int numberUnsatisfied_; |
---|
59 | |
---|
60 | public: |
---|
61 | AbcTreeNode() |
---|
62 | : |
---|
63 | branchedOn_(-1), |
---|
64 | branchedOnVal_(ALPS_BND_MAX), |
---|
65 | branchedDir_(0), |
---|
66 | guessedObjectiveValue_(ALPS_OBJ_MAX), |
---|
67 | numberUnsatisfied_(0) |
---|
68 | { |
---|
69 | desc_ = new AbcNodeDesc(dynamic_cast<AbcModel*> |
---|
70 | (getKnowledgeBroker()->getModel())); |
---|
71 | } |
---|
72 | |
---|
73 | AbcTreeNode(AbcModel* m) |
---|
74 | : |
---|
75 | branchedOn_(-1), |
---|
76 | branchedOnVal_(ALPS_BND_MAX), |
---|
77 | branchedDir_(0), |
---|
78 | guessedObjectiveValue_(ALPS_OBJ_MAX), |
---|
79 | numberUnsatisfied_(0) |
---|
80 | { |
---|
81 | desc_ = new AbcNodeDesc(m); |
---|
82 | } |
---|
83 | |
---|
84 | AbcTreeNode(AbcNodeDesc*& desc) |
---|
85 | : |
---|
86 | branchedOn_(-1), |
---|
87 | branchedOnVal_(ALPS_BND_MAX), |
---|
88 | branchedDir_(0), |
---|
89 | guessedObjectiveValue_(ALPS_OBJ_MAX), |
---|
90 | numberUnsatisfied_(0) |
---|
91 | { |
---|
92 | desc_ = desc; |
---|
93 | desc = 0; |
---|
94 | //At the time of registering node, that node hasn't set broker |
---|
95 | //desc_->setModel(getKnowledgeBroker()->getDataPool()->getModel()); |
---|
96 | } |
---|
97 | |
---|
98 | ~AbcTreeNode() |
---|
99 | { |
---|
100 | } |
---|
101 | |
---|
102 | virtual AlpsTreeNode* createNewTreeNode(AlpsNodeDesc*& desc) const; |
---|
103 | |
---|
104 | /** Performing the bounding operation. */ |
---|
105 | virtual int process(bool isRoot = false, bool rampUp = false); |
---|
106 | |
---|
107 | /** Select the branch variable. |
---|
108 | Return value: |
---|
109 | <ul> |
---|
110 | <li> 0: A branching object has been installed |
---|
111 | <li> -1: A monotone object was discovered |
---|
112 | <li> -2: An infeasible object was discovered |
---|
113 | </ul> |
---|
114 | */ |
---|
115 | int chooseBranch (AbcModel * model, bool& strongFound); |
---|
116 | |
---|
117 | /** Query/set the objective value (could be approximately or not exit) |
---|
118 | of the node. */ |
---|
119 | ///@{ |
---|
120 | inline double getObjValue() const { return quality_; } |
---|
121 | inline void setObjValue(const double objValue) { quality_ = objValue; } |
---|
122 | ///@} |
---|
123 | |
---|
124 | virtual std::vector< CoinTriple<AlpsNodeDesc*, AlpsNodeStatus, double> > |
---|
125 | branch(); |
---|
126 | |
---|
127 | /// Get the number of objects unsatisfied at this node. |
---|
128 | inline int numberUnsatisfied() const |
---|
129 | { return numberUnsatisfied_; } |
---|
130 | |
---|
131 | /// Guessed objective value (for solution) |
---|
132 | inline double guessedObjectiveValue() const |
---|
133 | { return guessedObjectiveValue_; } |
---|
134 | /// |
---|
135 | inline void setGuessedObjectiveValue(double value) |
---|
136 | { guessedObjectiveValue_ = value; } |
---|
137 | /// |
---|
138 | void setBranchedOn(int b) { branchedOn_ = b; } |
---|
139 | /// |
---|
140 | void setBranchedDir(int d) { branchedDir_ = d; } |
---|
141 | /// |
---|
142 | void setBranchedOnValue(double b) { branchedOnVal_ = b; } |
---|
143 | /// |
---|
144 | int getBranchedOn() const { return branchedOn_; } |
---|
145 | /// |
---|
146 | int getBranchedDir() const { return branchedDir_; } |
---|
147 | /// |
---|
148 | double getBranchedOnValue() const { return branchedOnVal_; } |
---|
149 | /// |
---|
150 | virtual AlpsEncoded* encode() const; |
---|
151 | /// |
---|
152 | virtual AlpsKnowledge* decode(AlpsEncoded&) const; |
---|
153 | |
---|
154 | }; |
---|
155 | |
---|
156 | #endif |
---|