- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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-2013, 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
35 class AlpsKnowledgeBrokerSerial : public AlpsKnowledgeBroker {
36 private:
37 AlpsKnowledgeBrokerSerial(const AlpsKnowledgeBrokerSerial&);
38 AlpsKnowledgeBrokerSerial& operator=(const AlpsKnowledgeBrokerSerial&);
39
40 public:
42 AlpsKnowledgeBrokerSerial()
43 :
44 AlpsKnowledgeBroker()
45 {}
46
49 AlpsKnowledgeBrokerSerial(AlpsModel& model)
50 :
51 AlpsKnowledgeBroker()
52 {
53 initializeSearch(0, NULL, model);
54 }
55
58 AlpsKnowledgeBrokerSerial(int argc,
59 char* argv[],
60 AlpsModel& model)
61 :
62 AlpsKnowledgeBroker()
63 {
64 initializeSearch(argc, argv, model);
65 }
66
67
69 virtual ~AlpsKnowledgeBrokerSerial() {}
70
71 //-------------------------------------------------------------------------
76
78 virtual void searchLog();
79
81 virtual double getIncumbentValue() const {
82 return getBestQuality();
83 }
84
87 virtual double getBestQuality() const {
88 if (AlpsKnowledgeBroker::hasKnowledge(AlpsKnowledgeTypeSolution)) {
89 return getBestKnowledge(AlpsKnowledgeTypeSolution).second;
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
102 if (getNumKnowledges(AlpsKnowledgeTypeSolution) <= 0) {
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;
111 if (getSolStatus() == AlpsExitStatusOptimal) {
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;
124 if (getSolStatus() == AlpsExitStatusOptimal) {
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
AlpsKnowledgeBroker
The base class of knowledge broker class.
Definition: AlpsKnowledgeBroker.h:48
AlpsExitStatusOptimal
Definition: Alps.h:103
AlpsKnowledgeBrokerSerial::searchLog
virtual void searchLog()
Search log.
ALPS_INC_MAX
#define ALPS_INC_MAX
Definition: Alps.h:144
AlpsModel.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
AlpsModel
Definition: AlpsModel.h:36
AlpsParams.h
AlpsEnumProcessT.h
AlpsKnowledgeBrokerSerial::operator=
AlpsKnowledgeBrokerSerial & operator=(const AlpsKnowledgeBrokerSerial &)
AlpsKnowledgeBrokerSerial::AlpsKnowledgeBrokerSerial
AlpsKnowledgeBrokerSerial()
Default constructor.
Definition: AlpsKnowledgeBrokerSerial.h:42
AlpsKnowledgeBrokerSerial
Definition: AlpsKnowledgeBrokerSerial.h:35
Alps.h
AlpsKnowledgeBrokerSerial::AlpsKnowledgeBrokerSerial
AlpsKnowledgeBrokerSerial(int argc, char *argv[], AlpsModel &model)
Userful constructor.
Definition: AlpsKnowledgeBrokerSerial.h:58
AlpsTreeNode
This class holds one node of the search tree.
Definition: AlpsTreeNode.h:50
AlpsKnowledgeBrokerSerial::rootSearch
virtual void rootSearch(AlpsTreeNode *root)
Search for best solution.
AlpsKnowledgeBroker::msgLevel_
int msgLevel_
The leve of printing message to screen of the master and general message.
Definition: AlpsKnowledgeBroker.h:176
AlpsKnowledgeBrokerSerial::getBestQuality
virtual double getBestQuality() const
The process queries the quality of the best solution that it finds.
Definition: AlpsKnowledgeBrokerSerial.h:87
AlpsKnowledgeBrokerSerial::getIncumbentValue
virtual double getIncumbentValue() const
The process queries the quality of the incumbent that it stores.
Definition: AlpsKnowledgeBrokerSerial.h:81
AlpsMessage.h
AlpsKnowledgeBroker::getBestKnowledge
virtual std::pair< AlpsKnowledge *, double > getBestKnowledge(AlpsKnowledgeType kt) const
Get the best knowledge in the given type of knowledge pools.
AlpsKnowledgeBrokerSerial::~AlpsKnowledgeBrokerSerial
virtual ~AlpsKnowledgeBrokerSerial()
Destructor.
Definition: AlpsKnowledgeBrokerSerial.h:69
AlpsKnowledgeBroker.h
AlpsKnowledgeBrokerSerial::initializeSearch
virtual void initializeSearch(int argc, char *argv[], AlpsModel &model)
Reading in Alps and user parameter sets, and read in model data.
AlpsSolution
Definition: AlpsSolution.h:35
AlpsKnowledgeBroker::getSolStatus
AlpsExitStatus getSolStatus() const
Query search termination status.
Definition: AlpsKnowledgeBroker.h:460
AlpsKnowledgeBroker::hasKnowledge
virtual bool hasKnowledge(AlpsKnowledgeType kt) const
Query whether there are knowledges in the given type of knowledge pools.
Definition: AlpsKnowledgeBroker.h:363
AlpsKnowledgeTypeSolution
Definition: Alps.h:92
AlpsKnowledgeBroker::getNumKnowledges
virtual int getNumKnowledges(AlpsKnowledgeType kt) const
Query the number of knowledge in the given type of a knowledge pool.
AlpsKnowledgeBrokerSerial::AlpsKnowledgeBrokerSerial
AlpsKnowledgeBrokerSerial(AlpsModel &model)
Useful constructor.
Definition: AlpsKnowledgeBrokerSerial.h:49