Alps  1.5.7
AlpsKnowledgeBrokerSerial.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  * 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  * *
20  * Copyright (C) 2001-2019, Lehigh University, Yan Xu, and Ted Ralphs. *
21  *===========================================================================*/
22 
23 #ifndef AlpsKnowledgeBrokerSerial_h_
24 #define AlpsKnowledgeBrokerSerial_h_
25 
26 #include "Alps.h"
27 #include "AlpsEnumProcessT.h"
28 #include "AlpsKnowledgeBroker.h"
29 #include "AlpsMessage.h"
30 #include "AlpsModel.h"
31 #include "AlpsParams.h"
32 
33 //#############################################################################
34 
36  private:
39 
40  public:
43  :
45  {}
46 
50  :
52  {
53  initializeSearch(0, NULL, model);
54  }
55 
59  char* argv[],
60  AlpsModel& model)
61  :
62  AlpsKnowledgeBroker(model)
63  {
64  initializeSearch(argc, argv, model);
65  }
66 
67 
70 
71  //-------------------------------------------------------------------------
76 
78  virtual void searchLog();
79 
81  virtual double getIncumbentValue() const {
82  return getBestQuality();
83  }
84 
87  virtual double getBestQuality() const {
90  }
91  else {
92  return ALPS_INC_MAX;
93  }
94  }
95 
98  virtual void printBestSolution(char* outputFile = 0) const {
99 
100  if (msgLevel_ < 1) return;
101 
103  std::cout << "\nALPS did not find a solution."
104  << std::endl;
105  return;
106  }
107  if (outputFile != 0) {
108  // Write to outputFile
109  std::ofstream os(outputFile);
110  os << "============================================" << std::endl;
112  os << "Optimal solution:" << std::endl;
113  }
114  else {
115  os << "Best solution found:" << std::endl;
116  }
117  os << "Cost = " << getBestQuality();
118  os << std::endl;
119  dynamic_cast<AlpsSolution* >
120  (getBestKnowledge(AlpsKnowledgeTypeSolution).first)->print(os);
121  }
122  else { // Write to std::cout
123  std::cout << "============================================" << std::endl;
125  std::cout << "Optimal solution:" << std::endl;
126  }
127  else {
128  std::cout << "Best solution found:" << std::endl;
129  }
130  std::cout << "Cost = " << getBestQuality();
131  std::cout << std::endl;
132  dynamic_cast<AlpsSolution* >
133  (getBestKnowledge(AlpsKnowledgeTypeSolution).first)->print(std::cout);
134  std::cout << "============================================" << std::endl;
135  }
136  }
138 
140  virtual void initializeSearch(int argc,
141  char* argv[],
142  AlpsModel& model);
143 
145  virtual void rootSearch(AlpsTreeNode* root);
146 
147 };
148 #endif
AlpsModel.h
AlpsKnowledgeBrokerSerial::rootSearch
virtual void rootSearch(AlpsTreeNode *root)
Search for best solution.
AlpsModel
Definition: AlpsModel.h:36
AlpsExitStatusOptimal
@ AlpsExitStatusOptimal
Definition: Alps.h:103
AlpsKnowledgeBroker.h
AlpsKnowledgeBrokerSerial::printBestSolution
virtual void printBestSolution(char *outputFile=0) const
The process outputs the best solution and the quality that it finds to a file or std::out.
Definition: AlpsKnowledgeBrokerSerial.h:98
AlpsKnowledgeBroker::getSolStatus
AlpsExitStatus getSolStatus() const
Query search termination status.
Definition: AlpsKnowledgeBroker.h:463
ALPS_INC_MAX
#define ALPS_INC_MAX
Definition: Alps.h:144
AlpsKnowledgeBroker::getNumKnowledges
virtual int getNumKnowledges(AlpsKnowledgeType kt) const
Query the number of knowledge in the given type of a knowledge pool.
AlpsKnowledgeBroker::msgLevel_
int msgLevel_
The leve of printing message to screen of the master and general message.
Definition: AlpsKnowledgeBroker.h:176
AlpsTreeNode
This class holds one node of the search tree.
Definition: AlpsTreeNode.h:50
AlpsSolution
Definition: AlpsSolution.h:35
Alps.h
AlpsKnowledgeBrokerSerial::AlpsKnowledgeBrokerSerial
AlpsKnowledgeBrokerSerial(int argc, char *argv[], AlpsModel &model)
Userful constructor.
Definition: AlpsKnowledgeBrokerSerial.h:58
AlpsMessage.h
AlpsKnowledgeBrokerSerial::AlpsKnowledgeBrokerSerial
AlpsKnowledgeBrokerSerial(AlpsModel &model)
Useful constructor.
Definition: AlpsKnowledgeBrokerSerial.h:49
AlpsKnowledgeBrokerSerial::AlpsKnowledgeBrokerSerial
AlpsKnowledgeBrokerSerial()
Default constructor.
Definition: AlpsKnowledgeBrokerSerial.h:42
AlpsKnowledgeBroker
The base class of knowledge broker class.
Definition: AlpsKnowledgeBroker.h:48
AlpsKnowledgeBrokerSerial::getIncumbentValue
virtual double getIncumbentValue() const
The process queries the quality of the incumbent that it stores.
Definition: AlpsKnowledgeBrokerSerial.h:81
AlpsKnowledgeBrokerSerial
Definition: AlpsKnowledgeBrokerSerial.h:35
AlpsEnumProcessT.h
AlpsKnowledgeBrokerSerial::~AlpsKnowledgeBrokerSerial
virtual ~AlpsKnowledgeBrokerSerial()
Destructor.
Definition: AlpsKnowledgeBrokerSerial.h:69
AlpsKnowledgeBrokerSerial::initializeSearch
virtual void initializeSearch(int argc, char *argv[], AlpsModel &model)
Reading in Alps and user parameter sets, and read in model data.
AlpsParams.h
AlpsKnowledgeBroker::hasKnowledge
virtual bool hasKnowledge(AlpsKnowledgeType kt) const
Query whether there are knowledges in the given type of knowledge pools.
Definition: AlpsKnowledgeBroker.h:366
AlpsKnowledgeBrokerSerial::searchLog
virtual void searchLog()
Search log.
AlpsKnowledgeBrokerSerial::getBestQuality
virtual double getBestQuality() const
The process queries the quality of the best solution that it finds.
Definition: AlpsKnowledgeBrokerSerial.h:87
AlpsKnowledgeTypeSolution
@ AlpsKnowledgeTypeSolution
Definition: Alps.h:92
AlpsKnowledgeBroker::getBestKnowledge
virtual std::pair< AlpsKnowledge *, double > getBestKnowledge(AlpsKnowledgeType kt) const
Get the best knowledge in the given type of knowledge pools.