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-2019, Lehigh University, Yan Xu, Aykut Bulut, and      *
22  *                          Ted Ralphs.                                      *
23  * All Rights Reserved.                                                      *
24  *===========================================================================*/
25 
26 
27 #ifndef AlpsSolution_h_
28 #define AlpsSolution_h_
29 
30 #include <iosfwd>
31 #include <map>
32 #include <vector>
33 
34 #include "AlpsKnowledge.h"
35 #include "AlpsTreeNode.h" // to get AlpsNodeIndex_t
36 
37 //#############################################################################
38 
39 class AlpsSolution : public AlpsKnowledge {
40 
41 private:
42   /** Diable copy constructor and assignment. */
43   AlpsSolution(const AlpsSolution&);
44   AlpsSolution& operator=(const AlpsSolution&);
45 
46   /** The index of the node where the solution was found. */
47   int index_;
48 
49   /** The depth of the node where the solution was found. */
50   int depth_;
51 
52 public:
53 
54   /** Default constructor. */
AlpsSolution()55   AlpsSolution(): AlpsKnowledge(AlpsKnowledgeTypeSolution),
56                 index_(-1), depth_(-1) {
57   }
58 
59   /** Constructor to set index and depth. */
AlpsSolution(const AlpsNodeIndex_t i,const int d)60   AlpsSolution(const AlpsNodeIndex_t i, const int d): index_(i), depth_(d) {
61     setType(AlpsKnowledgeTypeSolution);
62   }
63 
64   /** Destructor. */
~AlpsSolution()65   virtual ~AlpsSolution() {}
66 
67   /** Get index where solution was found */
getIndex()68   AlpsNodeIndex_t getIndex() { return index_; }
69 
70   /** Set index where solution was found */
setIndex(const AlpsNodeIndex_t i)71   void setIndex(const AlpsNodeIndex_t i) { index_ = i; }
72 
73   /** Get depth where solution was found */
getDepth()74   int getDepth() { return depth_; }
75 
76   /** Set depth where solution was found */
setDepth(const int d)77   void setDepth(const int d) { depth_ = d; }
78 
79   /** Print out the solution.*/
print(std::ostream & os)80   virtual void print(std::ostream& os) const{
81     os << "WARNING: No solution print function is defined." << std::endl;
82   }
83 
84   /// Get encode defined in AlpsKnowledge.
85   using AlpsKnowledge::encode;
86 
87   /// Encode this into the given AlpsEncoded object.
encode(AlpsEncoded * encoded)88   virtual AlpsReturnStatus encode(AlpsEncoded * encoded) const {
89     encoded->writeRep(index_);
90     encoded->writeRep(depth_);
91     return AlpsReturnStatusOk;
92   }
93 
94   /// Decode the given AlpsEncoded object into this.
decodeToSelf(AlpsEncoded & encoded)95   virtual AlpsReturnStatus decodeToSelf(AlpsEncoded & encoded) {
96     encoded.readRep(index_);
97     encoded.readRep(depth_);
98     return AlpsReturnStatusOk;
99   }
100 
101 };
102 
103 #endif
104