KnapSolution.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: Yan Xu, Lehigh University *
8  * Ted Ralphs, Lehigh University *
9  * Laszlo Ladanyi, IBM T.J. Watson Research Center *
10  * Matthew Saltzman, Clemson University *
11  * *
12  * *
13  * Copyright (C) 2001-2013, Lehigh University, Yan Xu, and Ted Ralphs. *
14  *===========================================================================*/
15 
16 #ifndef KnapSolution_h
17 #define KnapSolution_h
18 
19 #include "AlpsSolution.h"
20 
21 #include "KnapModel.h"
22 
23 
24 class KnapSolution : public AlpsSolution {
25  private:
27  int size_;
28  int* solution_;
29  int value_;
31  // I guess it is necessary to add a pointer to model (origin, prosolved)
32  const KnapModel* model_;
33 
34  public:
36  :
37  size_(0),
38  solution_(0),
39  value_(0),
40  model_(m)
41  {}
42  KnapSolution(int s, int*& sol, int v, const KnapModel* m)
43  :
44  size_(s),
45  solution_(sol),
46  value_(v),
47  model_(m)
48  { sol = 0; }
50  if (solution_ != 0) {
51  delete [] solution_;
52  solution_ = 0;
53  }
54  }
55 
57  double getObjValue() const { return value_; }
58 
59  virtual double getQuality() const { return getObjValue(); }
60 
62  int getSize() const { return size_; }
63 
65  int getSolution(int i) const { return solution_[i]; }
66 
68  const KnapModel* getModel() const { return model_; }
69 
71  virtual void print(std::ostream& os) const;
72 
74  virtual AlpsEncoded* encode() const;
75 
77  // virtual AlpsKnowledge* decode(const AlpsEncoded&) const;
78  virtual AlpsKnowledge* decode(AlpsEncoded&) const;
79 };
80 
81 #endif
int * solution_
Definition: KnapSolution.h:28
KnapSolution(const KnapModel *m)
Definition: KnapSolution.h:35
virtual AlpsKnowledge * decode(AlpsEncoded &) const
The method that decodes the node from a encoded object.
int size_
The solution (indicator vector for the items) and its value.
Definition: KnapSolution.h:27
This data structure is to contain the packed form of an encodable knowledge.
Definition: AlpsEncoded.h:25
int getSize() const
Get the size of the solution.
Definition: KnapSolution.h:62
const KnapModel * model_
To access model data.
Definition: KnapSolution.h:32
KnapSolution(int s, int *&sol, int v, const KnapModel *m)
Definition: KnapSolution.h:42
virtual void print(std::ostream &os) const
Print out the solution.
virtual AlpsEncoded * encode() const
The method that encodes the node into a encoded object.
The abstract base class of any user-defined class that Alps has to know about in order to encode/deco...
Definition: AlpsKnowledge.h:51
int getSolution(int i) const
Get item i in the solution vector.
Definition: KnapSolution.h:65
const KnapModel * getModel() const
Get model data.
Definition: KnapSolution.h:68
double getObjValue() const
Get the best solution value.
Definition: KnapSolution.h:57
virtual double getQuality() const
Definition: KnapSolution.h:59