Alps  2.0.2
AlpsSolutionPool.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: *
8  * *
9  * Yan Xu, Lehigh University *
10  * Aykut Bulut, Lehigh University *
11  * Ted Ralphs, Lehigh University *
12  * *
13  * Conceptual Design: *
14  * *
15  * Yan Xu, Lehigh University *
16  * Ted Ralphs, Lehigh University *
17  * Laszlo Ladanyi, IBM T.J. Watson Research Center *
18  * Matthew Saltzman, Clemson University *
19  * *
20  * *
21  * Copyright (C) 2001-2023, Lehigh University, Yan Xu, Aykut Bulut, and *
22  * Ted Ralphs. *
23  * All Rights Reserved. *
24  *===========================================================================*/
25 
26 
27 #ifndef AlpsSolutionPool_h_
28 #define AlpsSolutionPool_h_
29 
30 #include "AlpsKnowledgePool.h"
31 #include "AlpsSolution.h"
32 
33 // todo(aykut) we do want to allow solutions with the same priority, but do
34 // todo(aykut) we want to allow identical solutions?
35 
44  std::multimap<double, AlpsSolution*> solutions_;
46 
47 public:
49 
50  AlpsSolutionPool(int maxsols=1);
51  virtual ~AlpsSolutionPool();
53 
55 
56  virtual int getNumKnowledges() const;
58  virtual std::pair<AlpsKnowledge*, double> getKnowledge() const;
60  virtual bool hasKnowledge() const;
62  virtual int getMaxNumKnowledges() const { return maxNumSolutions_; }
65  virtual std::pair<AlpsKnowledge*, double> getBestKnowledge() const;
68  virtual void getAllKnowledges (std::vector<std::pair<AlpsKnowledge*,
69  double> >& sols) const;
71 
73 
74  virtual void addKnowledge(AlpsKnowledge* sol, double priority);
76  virtual void popKnowledge();
78 
80 
81  virtual void setMaxNumKnowledges(int maxsols);
84  void clean();
86 
87 private:
92 };
93 
94 #define AlpsSolutionInterface(ref) \
95 int getNumSolutions() const { \
96  (ref).getNumSolutions(); \
97 } \
98 int getMaxNumSolutions() const { \
99  return (ref).getMaxNumSolutions(); \
100 } \
101 void setMaxNumSolutions(int num) { \
102  (ref).setMaxNumSolutions(num); \
103 } \
104 bool hasSolution() const { \
105  return (ref).hasSolution(); \
106 } \
107 std::pair<const AlpsSolution*, double> getBestSolution() const { \
108  return (ref).getBestSolution(); \
109 } \
110 void getAllSolutions \
111  (std::vector<std::pair<const AlpsSolution*, double> >& sols) { \
112  return (ref).getAllSolutions(sols); \
113 } \
114 void addSolution(const AlpsSolution* sol, double priority) { \
115  (ref).addSolution(sol, priority); \
116 }
117 
118 #endif
AlpsSolutionPool::popKnowledge
virtual void popKnowledge()
Remove a solution from the pool.
AlpsSolutionPool::operator=
AlpsSolutionPool & operator=(const AlpsSolutionPool &)
Disable copy assignment operator.
AlpsSolutionPool::maxNumSolutions_
int maxNumSolutions_
Definition: AlpsSolutionPool.h:45
AlpsSolutionPool::getAllKnowledges
virtual void getAllKnowledges(std::vector< std::pair< AlpsKnowledge *, double > > &sols) const
Return all the solutions of the solution pool in the provided argument vector.
AlpsSolutionPool::setMaxNumKnowledges
virtual void setMaxNumKnowledges(int maxsols)
Set maximum number of solutions.
AlpsSolutionPool::addKnowledge
virtual void addKnowledge(AlpsKnowledge *sol, double priority)
Add a knowledge to pool.
AlpsKnowledgePool
This is an abstract base class, fixing an API for pool types of Alps, AlpsNodePool,...
Definition: AlpsKnowledgePool.h:47
AlpsSolution.h
AlpsSolutionPool::~AlpsSolutionPool
virtual ~AlpsSolutionPool()
AlpsSolutionPool::getKnowledge
virtual std::pair< AlpsKnowledge *, double > getKnowledge() const
Check the first item in the pool.
AlpsSolutionPool::AlpsSolutionPool
AlpsSolutionPool(int maxsols=1)
AlpsKnowledge
The abstract base class of Alps knowledges generated during the search.
Definition: AlpsKnowledge.h:63
AlpsKnowledgePool.h
AlpsSolutionPool::hasKnowledge
virtual bool hasKnowledge() const
Return true if there are any solution stored in the solution pool.
AlpsSolutionPool::clean
void clean()
Delete all the solutions in pool.
AlpsSolutionPool::solutions_
std::multimap< double, AlpsSolution * > solutions_
Definition: AlpsSolutionPool.h:44
AlpsSolutionPool
This class is a comtainer for the solutions found during the search.
Definition: AlpsSolutionPool.h:43
AlpsSolutionPool::getBestKnowledge
virtual std::pair< AlpsKnowledge *, double > getBestKnowledge() const
Return the best solution.
AlpsSolutionPool::getMaxNumKnowledges
virtual int getMaxNumKnowledges() const
query the maximum number of solutions.
Definition: AlpsSolutionPool.h:62
AlpsSolutionPool::getNumKnowledges
virtual int getNumKnowledges() const
Query the current number of solutions.