Alps 1.5.12
Loading...
Searching...
No Matches
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-2023, 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:
46
50 :
52 {
53 initializeSearch(0, NULL, model);
54 }
55
59 char* argv[],
60 AlpsModel& model,
61 bool showBanner = true)
62 :
64 {
65 initializeSearch(argc, argv, model, showBanner);
66 }
67
68
71
72 //-------------------------------------------------------------------------
77
79 virtual void searchLog();
80
82 virtual double getIncumbentValue() const {
83 return getBestQuality();
84 }
85
88 virtual double getBestQuality() const {
91 }
92 else {
93 return ALPS_INC_MAX;
94 }
95 }
96
99 virtual void printBestSolution(char* outputFile = 0) const {
100
101 if (msgLevel_ < 1) return;
102
104 std::cout << "\nALPS did not find a solution."
105 << std::endl;
106 return;
107 }
108 if (outputFile != 0) {
109 // Write to outputFile
110 std::ofstream os(outputFile);
111 os << "============================================" << std::endl;
113 os << "Optimal solution:" << std::endl;
114 }
115 else {
116 os << "Best solution found:" << std::endl;
117 }
118 os << "Cost = " << getBestQuality();
119 os << std::endl;
120 dynamic_cast<AlpsSolution* >
122 }
123 else { // Write to std::cout
124 std::cout << "============================================" << std::endl;
126 std::cout << "Optimal solution:" << std::endl;
127 }
128 else {
129 std::cout << "Best solution found:" << std::endl;
130 }
131 std::cout << "Cost = " << getBestQuality();
132 std::cout << std::endl;
133 dynamic_cast<AlpsSolution* >
134 (getBestKnowledge(AlpsKnowledgeTypeSolution).first)->print(std::cout);
135 std::cout << "============================================" << std::endl;
136 }
137 }
138
139
141 virtual void initializeSearch(int argc,
142 char* argv[],
143 AlpsModel& model,
144 bool showBanner = true);
145
147 virtual void rootSearch(AlpsTreeNode* root);
148
149};
150#endif
@ AlpsKnowledgeTypeSolution
Definition Alps.h:92
#define ALPS_INC_MAX
Definition Alps.h:144
@ AlpsExitStatusOptimal
Definition Alps.h:103
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.
virtual void searchLog()
Search log.
AlpsKnowledgeBrokerSerial(AlpsModel &model)
Useful constructor.
virtual void rootSearch(AlpsTreeNode *root)
Search for best solution.
AlpsKnowledgeBrokerSerial(const AlpsKnowledgeBrokerSerial &)
AlpsKnowledgeBrokerSerial & operator=(const AlpsKnowledgeBrokerSerial &)
virtual double getIncumbentValue() const
The process queries the quality of the incumbent that it stores.
virtual void initializeSearch(int argc, char *argv[], AlpsModel &model, bool showBanner=true)
Reading in Alps and user parameter sets, and read in model data.
virtual double getBestQuality() const
The process queries the quality of the best solution that it finds.
AlpsKnowledgeBrokerSerial()
Default constructor.
AlpsKnowledgeBrokerSerial(int argc, char *argv[], AlpsModel &model, bool showBanner=true)
Userful constructor.
virtual ~AlpsKnowledgeBrokerSerial()
Destructor.
virtual bool hasKnowledge(AlpsKnowledgeType kt) const
Query whether there are knowledges 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.
AlpsExitStatus getSolStatus() const
Query search termination status.
AlpsKnowledgeBroker(const AlpsKnowledgeBroker &)
virtual std::pair< AlpsKnowledge *, double > getBestKnowledge(AlpsKnowledgeType kt) const
Get the best knowledge in the given type of knowledge pools.
int msgLevel_
The leve of printing message to screen of the master and general message.
This class holds one node of the search tree.