Alps  2.0.2
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  * 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 AlpsKnowledgeBrokerSerial_h_
28 #define AlpsKnowledgeBrokerSerial_h_
29 
30 #include "Alps.h"
31 #include "AlpsEnumProcessT.h"
32 #include "AlpsKnowledgeBroker.h"
33 #include "AlpsMessage.h"
34 #include "AlpsModel.h"
35 #include "AlpsParams.h"
36 
37 //#############################################################################
38 
40  private:
43 
44  public:
47  :
49  {}
50 
54  :
56  {
57  initializeSearch(0, NULL, model);
58  }
59 
63  char* argv[],
64  AlpsModel& model,
65  bool showBanner = true)
66  :
67  AlpsKnowledgeBroker(model)
68  {
69  initializeSearch(argc, argv, model, showBanner);
70  }
71 
72 
75 
76  //-------------------------------------------------------------------------
81 
83  virtual void searchLog();
84 
86  virtual double getIncumbentValue() const {
87  return getBestQuality();
88  }
89 
92  virtual double getBestQuality() const {
95  }
96  else {
97  return ALPS_INC_MAX;
98  }
99  }
100 
103  virtual void printBestSolution(char* outputFile = 0) const {
104 
105  if (msgLevel_ < 1) return;
106 
108  std::cout << "\nALPS did not find a solution."
109  << std::endl;
110  return;
111  }
112  if (outputFile != 0) {
113  // Write to outputFile
114  std::ofstream os(outputFile);
115  os << "============================================" << std::endl;
117  os << "Optimal solution:" << std::endl;
118  }
119  else {
120  os << "Best solution found:" << std::endl;
121  }
122  os << "Cost = " << getBestQuality();
123  os << std::endl;
124  dynamic_cast<AlpsSolution* >
125  (getBestKnowledge(AlpsKnowledgeTypeSolution).first)->print(os);
126  }
127  else { // Write to std::cout
128  std::cout << "============================================" << std::endl;
130  std::cout << "Optimal solution:" << std::endl;
131  }
132  else {
133  std::cout << "Best solution found:" << std::endl;
134  }
135  std::cout << "Cost = " << getBestQuality();
136  std::cout << std::endl;
137  dynamic_cast<AlpsSolution* >
138  (getBestKnowledge(AlpsKnowledgeTypeSolution).first)->print(std::cout);
139  std::cout << "============================================" << std::endl;
140  }
141  }
143 
145  virtual void initializeSearch(int argc,
146  char* argv[],
147  AlpsModel& model,
148  bool showBanner = true);
149 
151  virtual void rootSearch(AlpsTreeNode* root);
152 
153 };
154 #endif
AlpsModel.h
AlpsKnowledgeBrokerSerial::rootSearch
virtual void rootSearch(AlpsTreeNode *root)
Search for best solution.
AlpsModel
AlpsModel is a base class for user application problem data.
Definition: AlpsModel.h:132
AlpsExitStatusOptimal
@ AlpsExitStatusOptimal
Definition: Alps.h:246
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:103
AlpsKnowledgeBroker::getSolStatus
AlpsExitStatus getSolStatus() const
Query search termination status.
Definition: AlpsKnowledgeBroker.h:403
ALPS_INC_MAX
#define ALPS_INC_MAX
Definition: Alps.h:287
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:139
AlpsTreeNode
This class holds one node of the search tree.
Definition: AlpsTreeNode.h:52
AlpsSolution
Definition: AlpsSolution.h:39
Alps.h
AlpsMessage.h
AlpsKnowledgeBrokerSerial::AlpsKnowledgeBrokerSerial
AlpsKnowledgeBrokerSerial(AlpsModel &model)
Useful constructor.
Definition: AlpsKnowledgeBrokerSerial.h:53
AlpsKnowledgeBrokerSerial::initializeSearch
virtual void initializeSearch(int argc, char *argv[], AlpsModel &model, bool showBanner=true)
Reading in Alps and user parameter sets, and read in model data.
AlpsKnowledgeBrokerSerial::AlpsKnowledgeBrokerSerial
AlpsKnowledgeBrokerSerial()
Default constructor.
Definition: AlpsKnowledgeBrokerSerial.h:46
AlpsKnowledgeBroker
The base class of knowledge broker class.
Definition: AlpsKnowledgeBroker.h:52
AlpsKnowledgeBrokerSerial::getIncumbentValue
virtual double getIncumbentValue() const
The process queries the quality of the incumbent that it stores.
Definition: AlpsKnowledgeBrokerSerial.h:86
AlpsKnowledgeBrokerSerial
Definition: AlpsKnowledgeBrokerSerial.h:39
AlpsEnumProcessT.h
AlpsKnowledgeBrokerSerial::~AlpsKnowledgeBrokerSerial
virtual ~AlpsKnowledgeBrokerSerial()
Destructor.
Definition: AlpsKnowledgeBrokerSerial.h:74
AlpsKnowledgeBrokerSerial::AlpsKnowledgeBrokerSerial
AlpsKnowledgeBrokerSerial(int argc, char *argv[], AlpsModel &model, bool showBanner=true)
Userful constructor.
Definition: AlpsKnowledgeBrokerSerial.h:62
AlpsParams.h
AlpsKnowledgeBrokerSerial::operator=
AlpsKnowledgeBrokerSerial & operator=(const AlpsKnowledgeBrokerSerial &)
AlpsKnowledgeBroker::hasKnowledge
virtual bool hasKnowledge(AlpsKnowledgeType kt) const
Query whether there are knowledges in the given type of knowledge pools.
Definition: AlpsKnowledgeBroker.h:311
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:92
AlpsKnowledgeTypeSolution
@ AlpsKnowledgeTypeSolution
Definition: Alps.h:228
AlpsKnowledgeBroker::getBestKnowledge
virtual std::pair< AlpsKnowledge *, double > getBestKnowledge(AlpsKnowledgeType kt) const
Get the best knowledge in the given type of knowledge pools.