23#ifndef AlpsKnowledgeBroker_h_
24#define AlpsKnowledgeBroker_h_
31#include "CoinMessageHandler.hpp"
81 std::map<AlpsKnowledgeType, AlpsKnowledgePool*>*
pools_;
235 std::map<int, AlpsKnowledge*>::iterator pos, pos1;
271 bool showBanner =
true) = 0;
319 (std::pair<AlpsKnowledgeType, AlpsKnowledgePool*>(kt, kp));
322 throw CoinError(
"Broker doesn't manage this type of knowledge",
323 "addKnowledgePool()",
"AlpsKnowledgeBroker");
333 throw CoinError(
"Broker doesn't manage this type of knowledge",
334 "getKnowledgePool()",
"AlpsKnowledgeBroker");
348 throw CoinError(
"Broker doesn't manage this type of knowledge",
349 "getMaxNumKnowledges()",
"AlpsKnowledgeBroker");
360 throw CoinError(
"Broker doesn't manage this type of knowledge",
361 "setMaxNumKnowledges()",
"AlpsKnowledgeBroker");
371 throw CoinError(
"Broker doesn't manage this type of knowledge",
372 "hasKnowledge()",
"AlpsKnowledgeBroker");
376 virtual std::pair<AlpsKnowledge*, double>
382 throw CoinError(
"Broker doesn't manage this type of knowledge",
383 "getKnowledge()",
"AlpsKnowledgeBroker");
393 throw CoinError(
"Broker doesn't manage this type of knowledge",
394 "popKnowledge()",
"AlpsKnowledgeBroker");
399 virtual std::pair<AlpsKnowledge*, double>
405 double> >& kls)
const {
410 throw CoinError(
"Broker doesn't manage this type of knowledge",
411 "popKnowledge()",
"AlpsKnowledgeBroker");
423 throw CoinError(
"Broker doesn't manage this type of knowledge",
424 "popKnowledge()",
"AlpsKnowledgeBroker");
AlpsProcessType
This enumerative constant describes the various process types.
@ AlpsProcessTypeSerial
Serial.
@ AlpsKnowledgeTypeSolution
@ AlpsKnowledgeTypeSubTree
virtual void searchLog()=0
Search statistics log.
bool userBalancePeriod_
Has user input balance period.
virtual bool hasKnowledge(AlpsKnowledgeType kt) const
Query whether there are knowledges in the given type of knowledge pools.
virtual int updateNumNodesLeft()
Update the number of left nodes on this process.
int nodeProcessedNum_
The number of nodes that have been processed.
AlpsSubTree * workingSubTree_
Point to the subtree that being explored.
void passInMessageHandler(CoinMessageHandler *handler)
Pass in Message handler (not deleted at end).
AlpsKnowledgePool * getKnowledgePool(AlpsKnowledgeType kt) const
Retrieve a knowledge pool in the Knowledge base.
std::string logfile_
The log file.
virtual void search(AlpsModel *model)
Search best solution for a given model.
void setNodeSelection(AlpsSearchStrategy< AlpsTreeNode * > *nc)
void setExitStatus(AlpsExitStatus status)
Set terminate status.
virtual void addKnowledge(AlpsKnowledgeType kt, AlpsKnowledge *kl, double value)
Add a knowledge in the given type of knowledge pools.
virtual int getNumKnowledges(AlpsKnowledgeType kt) const
Query the number of knowledge in the given type of a knowledge pool.
AlpsSearchStrategy< AlpsSubTree * > * treeSelection_
Tree selection criterion.
AlpsNodeIndex_t getMaxNodeIndex() const
Queriy the upper bound of node indices.
void newLanguage(CoinMessages::Language language)
Set language.
AlpsSearchStrategy< AlpsTreeNode * > * getNodeSelection() const
virtual int getNumNodeLeftSystem()
void setModel(AlpsModel *m)
AlpsKnowledgeBroker()
Default constructor.
int getlogFileLevel()
Return log file level.
AlpsExitStatus getSolStatus() const
Query search termination status.
std::map< int, AlpsKnowledge * > decodeMap_
Stores registered knowledge.
AlpsModel * model_
Pointer to model.
double getPeakMemory()
Get peak memory usage.
double nodeProcessingTime_
The approximately CPU time to process a node.
void setMaxNodeIndex(AlpsNodeIndex_t s)
Set the upper bound of node indices.
bool needWorkingSubTree_
Indicate whether need a new subtree.
void setupKnowledgePools()
Set up knowledge pools for this broker.
int getNumNodesProcessedSystem() const
Query the number of node processed by the system.
AlpsSearchStrategy< AlpsTreeNode * > * rampUpNodeSelection_
Node selection criterion.
int nodeDiscardedNum_
The number of nodes that have been discarded before processing.
CoinMessageHandler * handler_
Message handler.
AlpsKnowledgeBroker(AlpsModel &model)
Constructor passing in model.
virtual int getProcRank() const
Qeury the global rank of process.
CoinMessageHandler * messageHandler() const
Return handler.
CoinMessages * messagesPointer()
Return pointer to messages.
CoinMessages messages()
Return messages.
AlpsKnowledgeBroker(const AlpsKnowledgeBroker &)
int nodeLeftNum_
The number of nodes left.
AlpsSubTreePool * subTreePool_
A subtree pool holding a collection of subtrees.
AlpsSubTree * getWorkingSubTree()
AlpsSearchStrategy< AlpsSubTree * > * getSubTreeSelection() const
AlpsSearchStrategy< AlpsTreeNode * > * nodeSelection_
Node selection criterion.
CoinMessages messages_
Alps messages.
void addKnowledgePool(AlpsKnowledgeType kt, AlpsKnowledgePool *kp)
Add a knowledge pool into the Knowledge pools.
AlpsNodeIndex_t nextNodeIndex()
Query the next index assigned to a newly created node, and then increment the nextIndex_ by 1.
AlpsNodeIndex_t getNextNodeIndex() const
Query the next index assigned to a newly created node.
virtual std::pair< AlpsKnowledge *, double > getKnowledge(AlpsKnowledgeType kt) const
Get a knowledge, but doesn't remove it from the pool.
int getHubMsgLevel()
Return msg level.
int logFileLevel_
The degree of log file.
AlpsNodeIndex_t nextIndex_
The index to be assigned to a new search tree node.
virtual void popKnowledge(AlpsKnowledgeType kt)
Remove the a knowledge from the given type of knowledge pools.
virtual double getBestEstimateQuality()
Get best estimalted quality in system.
virtual void rootSearch(AlpsTreeNode *root)=0
Explore the tree rooted as the given root.
AlpsTimer & subTreeTimer()
Query subtree timer.
int numNodeLog_
Times that node log is printed.
virtual void initializeSearch(int argc, char *argv[], AlpsModel &model, bool showBanner=true)=0
Do some initialization for search.
AlpsNodeIndex_t maxIndex_
The maximum index can been assigned on this process.
AlpsTimer subTreeTimer_
Subtree timer.
AlpsPhase phase_
Alps phase.
virtual ~AlpsKnowledgeBroker()
Destructor.
int getNumNodesPartial() const
Query the number of node in the queue that are pregnant.
int nodeBranchedNum_
The number of nodes that have been branched.
virtual double getIncumbentValue() const =0
The process queries the objective value of the incumbent that it stores.
virtual AlpsProcessType getProcType() const
Query the type (master, hub, or worker) of the process.
int nodeMemSize_
The approximate memory size (bytes) of a node with full description.
int workerMsgLevel_
The leve of printing message to screen of workers.
virtual AlpsTreeNode * getBestNode() const
Query the best node in the subtree pool.
AlpsSolutionPool * solPool_
A solution pool containing the solutions found.
AlpsTimer & tempTimer()
Query secondary timer.
AlpsTimer timer_
Main timer.
AlpsExitStatus exitStatus_
The status of search when terminated.
void setNumNodeLog(int num)
Get times that node log has been printed.
std::map< AlpsKnowledgeType, AlpsKnowledgePool * > * pools_
The collection of pools managed by the knowledge broker.
int getMasterMsgLevel()
Return msg level.
const AlpsKnowledge * decoderObject(int name)
This method returns the pointer to an empty object of the registered class name.
virtual void getAllKnowledges(AlpsKnowledgeType kt, std::vector< std::pair< AlpsKnowledge *, double > > &kls) const
Get all knowledges in the given type of knowledge pools.
void registerClass(int name, AlpsKnowledge *userKnowledge)
Every user derived knowledge class must register.
virtual void printBestSolution(char *outputFile=0) const =0
The process (serial) / the master (parallel) outputs the best solution that it knows to a file or std...
int hubMsgLevel_
The leve of printing message to screen of hubs.
int getMsgLevel()
Return msg level.
void setPeakMemory(double size)
Set peak memory usage.
virtual double getBestQuality() const =0
The process (serial) / the master (parallel) queries the quality of the best solution that it knows.
AlpsKnowledgeBroker & operator=(const AlpsKnowledgeBroker &)
int getNumNodeLog() const
Get times that node log has been printed.
void setRampUpNodeSelection(AlpsSearchStrategy< AlpsTreeNode * > *nc)
int getTreeDepth()
Get tree depth.
int getNumNodesProcessed() const
Query the number of node processed by this process.
virtual int getMaxNumKnowledges(AlpsKnowledgeType kt) const
Query the max number of knowledge can be stored in a given type of knowledge pools.
double peakMemory_
Peak memory usage.
int getNumNodesBranched() const
Query the number of node processed by this process.
virtual void setMaxNumKnowledges(AlpsKnowledgeType kt, int num)
Set the max number of knowledge can be stored in a given type o fknowledge pools.
virtual int getMasterRank() const
Query the global rank of the Master.
virtual std::pair< AlpsKnowledge *, double > getBestKnowledge(AlpsKnowledgeType kt) const
Get the best knowledge in the given type of knowledge pools.
std::string instanceName_
The instance name.
void setNextNodeIndex(AlpsNodeIndex_t s)
Set nextIndex_.
AlpsTimer & timer()
Query timer.
void setNodeMemSize(int ms)
AlpsSearchStrategy< AlpsTreeNode * > * getRampUpNodeSelection() const
AlpsTimer tempTimer_
Secondary timer.
int getNumNodesDiscarded() const
Query the number of node processed by this process.
int largeSize_
The size of largest message buffer can be sent or received.
void setLanguage(CoinMessages::Language language)
int msgLevel_
The leve of printing message to screen of the master and general message.
void setSubTreeSelection(AlpsSearchStrategy< AlpsSubTree * > *tc)
int systemNodeProcessed_
To record how many nodes processed by the system (used in parallel code).
void setNodeProcessingTime(double npTime)
int treeDepth_
The depth of the tree.
int bestSolNode_
The number of nodes pocessed to find the solution.
double getNodeProcessingTime()
void setPhase(AlpsPhase ph)
int nodePartialNum_
The number of nodes that are pregnant.
int solNum_
The number of solutions found.
virtual void setMaxNumKnowledges(int num)
Set the quantity limit of knowledges that can be stored in the pool.
virtual void addKnowledge(AlpsKnowledge *nk, double priority)=0
Add a knowledge to pool.
virtual void getAllKnowledges(std::vector< std::pair< AlpsKnowledge *, double > > &kls) const
Get a reference to all the knowledges in the pool.
virtual void popKnowledge()
Remove the queried knowledge from the pool.
virtual bool hasKnowledge() const
Check whether the pool has knowledge.
virtual int getMaxNumKnowledges() const
Query the quantity limit of knowledges.
virtual std::pair< AlpsKnowledge *, double > getKnowledge() const =0
Query a knowledge, but doesn't remove it from the pool.
The abstract base class of any user-defined class that Alps has to know about in order to encode/deco...
virtual AlpsTreeNode * createRoot()
Create the root node.
In the solution pool we assume that the lower the priority value the more desirable the solution is.
The subtree pool is used to store subtrees.
This class contains the data pertaining to a particular subtree in the search tree.
This class holds one node of the search tree.