Alps 1.5.11
Loading...
Searching...
No Matches
KnapTreeNode.h
Go to the documentation of this file.
1/*===========================================================================*
2 * This file is part of the Abstract Library for Parallel Search (ALPS). *
3 * *
4 * ALPS is distributed under the Eclipse Public License as part of the *
5 * COIN-OR repository (http://www.coin-or.org). *
6 * *
7 * Authors: Yan Xu, Lehigh University *
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-2019, Lehigh University, Yan Xu, and Ted Ralphs. *
14 *===========================================================================*/
15
16#ifndef KnapTreeNode_h_
17#define KnapTreeNode_h_
18
19#include <utility>
20
21#include "AlpsTreeNode.h"
22
23#include "KnapModel.h"
24
25
26//#############################################################################
27
33
34//#############################################################################
35
36class KnapNodeDesc : public AlpsNodeDesc {
37
38 private:
39
40 /* Here, we need to fill in what the node description will look
41 like. For now, we will not use differencing -- just explicitly
42 represent it. Probably this means that we will just store the
43 original problem data and a list of the variables that have been
44 fixed. */
45
48 // In the constructor, we should allocate this array to be the right
49 // length.
51
55
56 public:
57#if 0
59 :
60 usedCapacity_(0),
61 usedValue_(0)
62 {
63 const int n =
64 dynamic_cast<const KnapModel*>(model_)->getNumItems();
66 std::fill(varStatus_, varStatus_ + n, KnapVarFree);
67 }
68#endif
69
71 :
72 AlpsNodeDesc(m),
73 usedCapacity_(0),
74 usedValue_(0)
75 {
76 //model_ = m; // data member declared in Alps
77 const int n = dynamic_cast<KnapModel* >(model_)->getNumItems();
79 std::fill(varStatus_, varStatus_ + n, KnapVarFree);
80 }
81
82 KnapNodeDesc(KnapModel* m, KnapVarStatus *& st, int cap, int val)
83 :
84 // model_(m), varStatus_(0), usedCapacity_(cap), usedValue_(val) {
85 AlpsNodeDesc(m),
86 varStatus_(0),
87 usedCapacity_(cap),
88 usedValue_(val)
89 {
90 // model_ = m;
91 std::swap(varStatus_, st);
92 }
93
94 virtual ~KnapNodeDesc() { delete[] varStatus_; }
95
96 // inline KnapModel* getModel() { return model_; }
97 // inline const KnapModel* getModel() const { return model_; }// move Alps
98
99 inline void setVarStatus(const int i, const KnapVarStatus status)
100 { varStatus_[i] = status; }
101
102 inline KnapVarStatus getVarStatus(const int i)
103 { return varStatus_[i]; }
104
105 inline const KnapVarStatus* getVarStati() const
106 { return varStatus_; }
107
108 inline int getUsedCapacity() const { return usedCapacity_; }
109 inline int getUsedValue() const { return usedValue_; }
110};
111
112//#############################################################################
113
115 private:
116 // NO: default constructor, copy constructor, assignment operator
119
120 private:
123
124 public:
126 desc_ = new KnapNodeDesc(dynamic_cast<KnapModel* >
127 (getKnowledgeBroker()->getModel()));
128 }
129
131 desc_ = new KnapNodeDesc(model);
132 }
133
135 desc_ = desc;
136 desc = 0;
137 // At the time of registering node, that node hasn't set broker
138 // desc_->setModel(getKnowledgeBroker()->getDataPool()->getModel());
139 }
140
142
143 void setBranchOn(int b) { branchedOn_ = b; }
144
146
147 virtual int process(bool isRoot = false, bool rampUp = false);
148
149 virtual std::vector< CoinTriple<AlpsNodeDesc*, AlpsNodeStatus, double> >
151
152 // We only need these for parallel execution I think...
153 virtual AlpsEncoded* encode() const;
154
156};
157
158#endif
KnapVarStatus
@ KnapVarFixedToOne
@ KnapVarFree
@ KnapVarFixedToZero
This data structure is to contain the packed form of an encodable knowledge.
Definition AlpsEncoded.h:25
The abstract base class of any user-defined class that Alps has to know about in order to encode/deco...
A class to refer to the description of a search tree node.
AlpsModel * model_
A pointer to model.
This class holds one node of the search tree.
AlpsNodeDesc * desc_
The actual description of the tree node.
AlpsKnowledgeBroker * getKnowledgeBroker() const
Functions to access/set the knwoledge broker.
KnapVarStatus * varStatus_
This array keeps track of which variables have been fixed by branching and which are still free.
int usedCapacity_
The total size of the items fixed to be put into the knapsack.
KnapNodeDesc(KnapModel *m, KnapVarStatus *&st, int cap, int val)
virtual ~KnapNodeDesc()
KnapVarStatus getVarStatus(const int i)
int getUsedValue() const
void setVarStatus(const int i, const KnapVarStatus status)
KnapNodeDesc(KnapModel *m)
const KnapVarStatus * getVarStati() const
int getUsedCapacity() const
KnapTreeNode(KnapNodeDesc *&desc)
KnapTreeNode(const KnapTreeNode &)
KnapTreeNode & operator=(const KnapTreeNode &)
virtual int process(bool isRoot=false, bool rampUp=false)
void setBranchOn(int b)
virtual AlpsEncoded * encode() const
This method should encode the content of the object and return a pointer to the encoded form.
int branchedOn_
The index of the branching variable.
virtual std::vector< CoinTriple< AlpsNodeDesc *, AlpsNodeStatus, double > > branch()
KnapTreeNode(KnapModel *model)
virtual AlpsTreeNode * createNewTreeNode(AlpsNodeDesc *&desc) const
The purpose of this function is be able to create the children of a node after branching.
virtual AlpsKnowledge * decode(AlpsEncoded &) const
This method should decode and return a pointer to a brand new object, i.e., the method must create a ...