Bcps 0.95.1
Loading...
Searching...
No Matches
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-2023, 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 "BcpsConfig.h"
31#include "BcpsObject.h"
32
33//#############################################################################
35//#############################################################################
36
37class BCPSLIB_EXPORT BcpsObjectPool : public AlpsKnowledgePool {
38
39 protected:
40
41 std::vector<AlpsKnowledge *> objects_;
42
43 public:
44
47 virtual ~BcpsObjectPool() {
48 if (! objects_.empty()) {
49 freeGuts();
50 }
51 }
52
54 inline void freeGuts() {
55 for (int i = static_cast<int> (objects_.size() - 1); i > -1; --i) {
56 delete objects_[i];
57 }
58 objects_.clear();
59 }
60
62 inline void clear(){ objects_.clear(); }
63
65 virtual void addKnowledge(AlpsKnowledge * nk, double priority) {
66 objects_.push_back(nk);
67 }
68
70 virtual int getNumKnowledges() const {
71 return static_cast<int>(objects_.size());
72 }
73
75 virtual std::pair<AlpsKnowledge*, double> getKnowledge() const {
76 return std::make_pair(objects_[0], 0.0);
77 }
78
80 virtual bool hasKnowledge() const
81 { return objects_.empty() ? false : true; }
82
84 void deleteObject(int k) {
85 assert(k > -1 && k < ((int)objects_.size()));
86
87 AlpsKnowledge *objectK = getObject(k);
88 std::vector<AlpsKnowledge *>::iterator pos;
89 pos = objects_.begin() + k;
90 objects_.erase(pos);
91
92 // Free memory of object k.
93 delete objectK;
94 }
95
97 const std::vector<AlpsKnowledge *>& getObjects() const { return objects_; }
98
100 AlpsKnowledge *getObject(int k) const { return objects_[k]; }
101};
102
103//#############################################################################
104
106 public:
109
111 void addConstraint(BcpsConstraint * con) { objects_.push_back(con); }
112
114 void deleteConstraint(int k) { deleteObject(k); }
115
117 int getNumConstraints() const { return getNumKnowledges(); }
118
120 const std::vector<AlpsKnowledge *>& getConstraints() const {return objects_;}
121
123 AlpsKnowledge *getConstraint(int k) const {return getObject(k);}
124};
125
126//#############################################################################
127
129 public:
131 virtual ~BcpsVariablePool() {}
132
134 void addVariable(BcpsVariable * var) { objects_.push_back(var); }
135
137 void deleteVariable(int k) { deleteObject(k); }
138
140 int getNumVariables() const { return getNumKnowledges(); }
141
143 const std::vector<AlpsKnowledge *>& getVariables() const {return objects_;}
144
146 AlpsKnowledge *getVariable(int k) const {return getObject(k);}
147};
148
149//#############################################################################
150
151#endif // End of file
const std::vector< AlpsKnowledge * > & getConstraints() const
Get the vector of constraints.
virtual ~BcpsConstraintPool()
void deleteConstraint(int k)
Delete constraint k from pool.
AlpsKnowledge * getConstraint(int k) const
Get a constraints.
void addConstraint(BcpsConstraint *con)
Add a constraint to pool.
int getNumConstraints() const
Query how many constraints are in the pool.
Object pool is used to store objects.
virtual std::pair< AlpsKnowledge *, double > getKnowledge() const
Query a knowledge, but doesn't remove it from the pool.
virtual void addKnowledge(AlpsKnowledge *nk, double priority)
Add a knowledge to pool.
const std::vector< AlpsKnowledge * > & getObjects() const
Get all objects.
std::vector< AlpsKnowledge * > objects_
BcpsObjectPool()
Default construct.
virtual bool hasKnowledge() const
Check whether the pool has knowledge.
AlpsKnowledge * getObject(int k) const
Get a object.
void deleteObject(int k)
Delete object k from pool.
void freeGuts()
Free object pointers.
virtual int getNumKnowledges() const
Query how many knowledges are in the pool.
virtual ~BcpsObjectPool()
void clear()
Reset to empty.
virtual ~BcpsVariablePool()
int getNumVariables() const
Query how many variables are in the pool.
void addVariable(BcpsVariable *var)
Add a variable to pool.
AlpsKnowledge * getVariable(int k) const
Get the vector of variables.
void deleteVariable(int k)
Delete variable k from pool.
const std::vector< AlpsKnowledge * > & getVariables() const
Get the vector of variables.
#define BCPSLIB_EXPORT
Definition config.h:5