- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

BcpsObjectPool.h
Go to the documentation of this file.
1 /*===========================================================================*
2 * This file is part of the Branch, Constrain and Price Software (BiCePS) *
3 * *
4 * BiCePS is distributed under the Eclipse Public License as part of the *
5 * COIN-OR repository (http://www.coin-or.org). *
6 * *
7 * Authors: *
8 * *
9 * Yan Xu, Lehigh University *
10 * Ted Ralphs, Lehigh University *
11 * *
12 * Conceptual Design: *
13 * *
14 * Yan Xu, Lehigh University *
15 * Ted Ralphs, Lehigh University *
16 * Laszlo Ladanyi, IBM T.J. Watson Research Center *
17 * Matthew Saltzman, Clemson University *
18 * *
19 * Copyright (C) 2001-2013, Lehigh University, Yan Xu, and Ted Ralphs. *
20 * All Rights Reserved. *
21 *===========================================================================*/
22
23 #ifndef BcpsObjectPool_h_
24 #define BcpsObjectPool_h_
25
26 #include <vector>
27
28 #include "AlpsKnowledgePool.h"
29
30 #include "BcpsObject.h"
31
32 //#############################################################################
34 //#############################################################################
35
36 class BcpsObjectPool : public AlpsKnowledgePool {
37
38 protected:
39
40 std::vector<AlpsKnowledge *> objects_;
41
42 public:
43
45 BcpsObjectPool() {}
46 virtual ~BcpsObjectPool() {
47 if (! objects_.empty()) {
48 freeGuts();
49 }
50 }
51
53 inline void freeGuts() {
54 for (int i = static_cast<int> (objects_.size() - 1); i > -1; --i) {
55 delete objects_[i];
56 }
57 objects_.clear();
58 }
59
61 inline void clear(){ objects_.clear(); }
62
64 virtual void addKnowledge(AlpsKnowledge * nk, double priority) {
65 objects_.push_back(nk);
66 }
67
69 virtual int getNumKnowledges() const {
70 return static_cast<int>(objects_.size());
71 }
72
74 virtual std::pair<AlpsKnowledge*, double> getKnowledge() const {
75 return std::make_pair(objects_[0], 0.0);
76 }
77
79 virtual bool hasKnowledge() const
80 { return objects_.empty() ? false : true; }
81
83 void deleteObject(int k) {
84 assert(k > -1 && k < ((int)objects_.size()));
85
86 AlpsKnowledge *objectK = getObject(k);
87 std::vector<AlpsKnowledge *>::iterator pos;
88 pos = objects_.begin() + k;
89 objects_.erase(pos);
90
91 // Free memory of object k.
92 delete objectK;
93 }
94
96 const std::vector<AlpsKnowledge *>& getObjects() const { return objects_; }
97
99 AlpsKnowledge *getObject(int k) const { return objects_[k]; }
100 };
101
102 //#############################################################################
103
104 class BcpsConstraintPool : public BcpsObjectPool {
105 public:
106 BcpsConstraintPool() {}
107 virtual ~BcpsConstraintPool() {}
108
110 void addConstraint(BcpsConstraint * con) { objects_.push_back(con); }
111
113 void deleteConstraint(int k) { deleteObject(k); }
114
116 int getNumConstraints() const { return getNumKnowledges(); }
117
119 const std::vector<AlpsKnowledge *>& getConstraints() const {return objects_;}
120
122 AlpsKnowledge *getConstraint(int k) const {return getObject(k);}
123 };
124
125 //#############################################################################
126
127 class BcpsVariablePool : public BcpsObjectPool {
128 public:
129 BcpsVariablePool() {}
130 virtual ~BcpsVariablePool() {}
131
133 void addVariable(BcpsVariable * var) { objects_.push_back(var); }
134
136 void deleteVariable(int k) { deleteObject(k); }
137
139 int getNumVariables() const { return getNumKnowledges(); }
140
142 const std::vector<AlpsKnowledge *>& getVariables() const {return objects_;}
143
145 AlpsKnowledge *getVariable(int k) const {return getObject(k);}
146 };
147
148 //#############################################################################
149
150 #endif // End of file
BcpsConstraintPool::getNumConstraints
int getNumConstraints() const
Query how many constraints are in the pool.
Definition: BcpsObjectPool.h:116
BcpsObjectPool::BcpsObjectPool
BcpsObjectPool()
Default construct.
Definition: BcpsObjectPool.h:45
BcpsConstraintPool::deleteConstraint
void deleteConstraint(int k)
Delete constraint k from pool.
Definition: BcpsObjectPool.h:113
BcpsObjectPool::freeGuts
void freeGuts()
Free object pointers.
Definition: BcpsObjectPool.h:53
BcpsVariablePool::BcpsVariablePool
BcpsVariablePool()
Definition: BcpsObjectPool.h:129
BcpsObjectPool::deleteObject
void deleteObject(int k)
Delete object k from pool.
Definition: BcpsObjectPool.h:83
BcpsObjectPool::hasKnowledge
virtual bool hasKnowledge() const
Check whether the pool has knowledge.
Definition: BcpsObjectPool.h:79
BcpsVariablePool
Definition: BcpsObjectPool.h:127
BcpsObjectPool::getKnowledge
virtual std::pair< AlpsKnowledge *, double > getKnowledge() const
Query a knowledge, but doesn&#39;t remove it from the pool.
Definition: BcpsObjectPool.h:74
BcpsVariable
Definition: BcpsObject.h:383
BcpsVariablePool::getVariables
const std::vector< AlpsKnowledge * > & getVariables() const
Get the vector of variables.
Definition: BcpsObjectPool.h:142
BcpsConstraintPool::~BcpsConstraintPool
virtual ~BcpsConstraintPool()
Definition: BcpsObjectPool.h:107
BcpsConstraintPool::BcpsConstraintPool
BcpsConstraintPool()
Definition: BcpsObjectPool.h:106
BcpsObjectPool::getObject
AlpsKnowledge * getObject(int k) const
Get a object.
Definition: BcpsObjectPool.h:99
BcpsObjectPool::getObjects
const std::vector< AlpsKnowledge * > & getObjects() const
Get all objects.
Definition: BcpsObjectPool.h:96
BcpsVariablePool::getNumVariables
int getNumVariables() const
Query how many variables are in the pool.
Definition: BcpsObjectPool.h:139
AlpsKnowledgePool.h
BcpsConstraint
Definition: BcpsObject.h:355
BcpsObjectPool
Object pool is used to store objects.
Definition: BcpsObjectPool.h:36
BcpsObjectPool::~BcpsObjectPool
virtual ~BcpsObjectPool()
Definition: BcpsObjectPool.h:46
BcpsConstraintPool::getConstraints
const std::vector< AlpsKnowledge * > & getConstraints() const
Get the vector of constraints.
Definition: BcpsObjectPool.h:119
BcpsObject.h
BcpsVariablePool::~BcpsVariablePool
virtual ~BcpsVariablePool()
Definition: BcpsObjectPool.h:130
BcpsConstraintPool::getConstraint
AlpsKnowledge * getConstraint(int k) const
Get a constraints.
Definition: BcpsObjectPool.h:122
BcpsVariablePool::getVariable
AlpsKnowledge * getVariable(int k) const
Get the vector of variables.
Definition: BcpsObjectPool.h:145
BcpsObjectPool::clear
void clear()
Reset to empty.
Definition: BcpsObjectPool.h:61
BcpsConstraintPool
Definition: BcpsObjectPool.h:104
AlpsKnowledgePool
Definition: AlpsKnowledgePool.h:36
AlpsKnowledge
The abstract base class of any user-defined class that Alps has to know about in order to encode/deco...
Definition: AlpsKnowledge.h:51
BcpsVariablePool::addVariable
void addVariable(BcpsVariable *var)
Add a variable to pool.
Definition: BcpsObjectPool.h:133
BcpsObjectPool::objects_
std::vector< AlpsKnowledge * > objects_
Definition: BcpsObjectPool.h:40
BcpsVariablePool::deleteVariable
void deleteVariable(int k)
Delete variable k from pool.
Definition: BcpsObjectPool.h:136
BcpsConstraintPool::addConstraint
void addConstraint(BcpsConstraint *con)
Add a constraint to pool.
Definition: BcpsObjectPool.h:110
BcpsObjectPool::getNumKnowledges
virtual int getNumKnowledges() const
Query how many knowledges are in the pool.
Definition: BcpsObjectPool.h:69
BcpsObjectPool::addKnowledge
virtual void addKnowledge(AlpsKnowledge *nk, double priority)
Add a knowledge to pool.
Definition: BcpsObjectPool.h:64