/home/coin/SVN-release/CoinAll-1.1.0/Alps/src/AlpsKnowledgeBrokerSerial.h

Go to the documentation of this file.
00001 /*===========================================================================*
00002  * This file is part of the Abstract Library for Parallel Search (ALPS).     *
00003  *                                                                           *
00004  * ALPS is distributed under the Common Public License as part of the        *
00005  * COIN-OR repository (http://www.coin-or.org).                              *
00006  *                                                                           *
00007  * Authors:                                                                  *
00008  *                                                                           *
00009  *          Yan Xu, Lehigh University                                        *
00010  *          Ted Ralphs, Lehigh University                                    *
00011  *                                                                           *
00012  * Conceptual Design:                                                        *
00013  *                                                                           *
00014  *          Yan Xu, Lehigh University                                        *
00015  *          Ted Ralphs, Lehigh University                                    *
00016  *          Laszlo Ladanyi, IBM T.J. Watson Research Center                  *
00017  *          Matthew Saltzman, Clemson University                             *
00018  *                                                                           * 
00019  *                                                                           *
00020  * Copyright (C) 2001-2007, Lehigh University, Yan Xu, and Ted Ralphs.       *
00021  *===========================================================================*/
00022 
00023 #ifndef AlpsKnowledgeBrokerSerial_h_
00024 #define AlpsKnowledgeBrokerSerial_h_
00025 
00026 #include "Alps.h"
00027 #include "AlpsEnumProcessT.h"
00028 #include "AlpsKnowledgeBroker.h"
00029 #include "AlpsMessage.h"
00030 #include "AlpsModel.h"
00031 #include "AlpsParams.h"
00032 
00033 //#############################################################################
00034 
00035 class AlpsKnowledgeBrokerSerial : public AlpsKnowledgeBroker {
00036  private:
00037     AlpsKnowledgeBrokerSerial(const AlpsKnowledgeBrokerSerial&);
00038     AlpsKnowledgeBrokerSerial& operator=(const AlpsKnowledgeBrokerSerial&);
00039 
00040  public:
00042     AlpsKnowledgeBrokerSerial() 
00043         : 
00044         AlpsKnowledgeBroker() 
00045         {} 
00046 
00049     AlpsKnowledgeBrokerSerial(AlpsModel& model) 
00050         : 
00051         AlpsKnowledgeBroker() 
00052         {
00053             initializeSearch(0, NULL, model); 
00054         }   
00055 
00058     AlpsKnowledgeBrokerSerial(int argc, 
00059                               char* argv[], 
00060                               AlpsModel& model) 
00061         : 
00062         AlpsKnowledgeBroker() 
00063         { 
00064             initializeSearch(argc, argv, model); 
00065         }
00066 
00067 
00069     virtual ~AlpsKnowledgeBrokerSerial() {}
00070 
00071     //-------------------------------------------------------------------------
00076 
00078     virtual void searchLog();
00079     
00081     virtual double getIncumbentValue() const {
00082         return getBestQuality();
00083     }
00084 
00087     virtual double getBestQuality() const {
00088         if (AlpsKnowledgeBroker::hasKnowledge(AlpsKnowledgeTypeSolution)) {
00089             return getBestKnowledge(AlpsKnowledgeTypeSolution).second;
00090         }
00091         else {
00092             return ALPS_INC_MAX;
00093         }
00094     }
00095 
00098     virtual void printBestSolution(char* outputFile = 0) const {
00099 
00100         if (msgLevel_ < 1) return;
00101         
00102         if (getNumKnowledges(AlpsKnowledgeTypeSolution) <= 0) {
00103             std::cout << "\nALPS did not find a solution."
00104                       << std::endl;
00105             return;
00106         }
00107         if (outputFile != 0) {                 
00108             // Write to outputFile
00109             std::ofstream os(outputFile);
00110             os << "============================================" << std::endl;
00111             if (getSolStatus() == AlpsExitStatusOptimal) {
00112                 os << "Optimal solution:" << std::endl;
00113             }
00114             else {
00115                 os << "Best solution found:" << std::endl;
00116             }
00117             os << "Cost = " << getBestQuality();
00118             os << std::endl;
00119             dynamic_cast<AlpsSolution* >
00120                 (getBestKnowledge(AlpsKnowledgeTypeSolution).first)->print(os);
00121         }
00122         else {                                  // Write to std::cout
00123             std::cout << "============================================" << std::endl;
00124             if (getSolStatus() == AlpsExitStatusOptimal) {
00125                 std::cout << "Optimal solution:" << std::endl;
00126             }
00127             else {
00128                 std::cout << "Best solution found:" << std::endl;
00129             }
00130             std::cout << "Cost = " << getBestQuality();
00131             std::cout << std::endl;
00132             dynamic_cast<AlpsSolution* >
00133                 (getBestKnowledge(AlpsKnowledgeTypeSolution).first)->print(std::cout);
00134             std::cout << "============================================" << std::endl;
00135         }
00136     }
00138 
00140     virtual void initializeSearch(int argc, 
00141                                   char* argv[], 
00142                                   AlpsModel& model);
00143     
00145     virtual void rootSearch(AlpsTreeNode* root);
00146     
00147 };
00148 #endif

Generated on Sun Nov 14 14:06:28 2010 for Coin-All by  doxygen 1.4.7