23#ifndef AlpsSolutionPool_h_
24#define AlpsSolutionPool_h_
42 std::multimap< double, AlpsSolution* > solutions_;
59 if (! solutions_.empty()) {
67 return static_cast<int> (solutions_.size());
72 {
return solutions_.empty() ? false :
true; }
82 (solutions_.begin()->second),
83 solutions_.begin()->first);
88 throw CoinError(
"Can not call popKnowledge()",
89 "popKnowledge()",
"AlpsSolutionPool");
105 std::pair<const double, AlpsSolution*> ps(priority,
dynamic_cast<AlpsSolution*
>(sol));
106 solutions_.insert(ps);
109 if ((maxNumSolutions_ > 0) &&
110 (
static_cast<int>(solutions_.size()) > maxNumSolutions_)) {
111 std::multimap< double, AlpsSolution* >::iterator si =
115 solutions_.erase(si);
138 if (
static_cast<int>(solutions_.size()) > maxsols) {
139 std::multimap<double, AlpsSolution*>::
140 iterator si = solutions_.begin();
141 for (
int i = 0; i < maxsols; ++i)
143 solutions_.erase(si, solutions_.end());
146 maxNumSolutions_ = maxsols;
157 (solutions_.begin()->second),
158 solutions_.begin()->first);
173 (std::vector<std::pair<AlpsKnowledge*, double> >& sols)
const {
174 sols.reserve(sols.size() + solutions_.size());
175 std::multimap<double, AlpsSolution*>::const_iterator si;
176 for (si = solutions_.begin(); si != solutions_.end(); ++si) {
178 (si->second), si->first));
184 while (!solutions_.empty()) {
185 std::multimap< double, AlpsSolution* >::iterator si =
189 solutions_.erase(si);
200#define AlpsSolutionInterface(ref) \
201int getNumSolutions() const { \
202 (ref).getNumSolutions(); \
204int getMaxNumSolutions() const { \
205 return (ref).getMaxNumSolutions(); \
207void setMaxNumSolutions(int num) { \
208 (ref).setMaxNumSolutions(num); \
210bool hasSolution() const { \
211 return (ref).hasSolution(); \
213std::pair<const AlpsSolution*, double> getBestSolution() const { \
214 return (ref).getBestSolution(); \
216void getAllSolutions \
217 (std::vector<std::pair<const AlpsSolution*, double> >& sols) { \
218 return (ref).getAllSolutions(sols); \
220void addSolution(const AlpsSolution* sol, double priority) { \
221 (ref).addSolution(sol, priority); \
The abstract base class of any user-defined class that Alps has to know about in order to encode/deco...
In the solution pool we assume that the lower the priority value the more desirable the solution is.
void addKnowledge(AlpsKnowledge *sol, double priority)
Append the solution to the end of the vector of solutions.
void popKnowledge()
Remove a solution from the pool.
int getNumKnowledges() const
query the current number of solutions
bool hasKnowledge() const
return true if there are any solution stored in the solution pool
void setMaxNumKnowledges(int maxsols)
reset the maximum number of solutions
std::pair< AlpsKnowledge *, double > getKnowledge() const
Get a solution from solution pool, doesn't remove it from the pool.
AlpsSolutionPool(int maxsols=1)
void getAllKnowledges(std::vector< std::pair< AlpsKnowledge *, double > > &sols) const
Return all the solutions of the solution pool in the provided argument vector.
void clean()
Delete all the solutions in pool.
virtual ~AlpsSolutionPool()
std::pair< AlpsKnowledge *, double > getBestKnowledge() const
Return the best solution.
int getMaxNumKnowledges() const
query the maximum number of solutions