Alps  2.0.2
AbcSolution.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  * 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 AbcSolution_h
28 #define AbcSolution_h
29 
30 #include "AlpsSolution.h"
31 
32 #include "AbcModel.h"
33 
34 #include <algorithm>
35 
37 class AbcSolution : public AlpsSolution {
38 private:
39  int size_;
40  double* value_;
41  double objective_;
42 
43 public:
45  :
46  size_(0),
47  value_(0),
48  objective_()
49  {}
50  AbcSolution(const int s, const double* val, const double obj)
51  :
52  size_(s)
53  {
54  if (size_ >= 0) {
55  value_ = new double [size_];
56  memcpy(value_, val, sizeof(double) * size_);
57  }
58  }
59 
61  if (value_ != 0) {
62  delete [] value_;
63  value_ = 0;
64  }
65  }
66 
68  double getObjValue() const { return objective_; }
69 
70  void setObj(double obj) { objective_=obj; }
71 
72  void setValue(int size, double const * value) {
73  if (value_) {
74  delete[] value_;
75  }
76  size_ = size;
77  value_ = new double[size];
78  std::copy(value, value+size, value_);
79  }
80 
81  virtual double getQuality() const { return getObjValue(); }
82 
84  int getSize() const { return size_; }
85 
87  const double* getColSolution() const
88  { return value_; }
89 
91  double getColSolution(int i) const { return value_[i]; }
92 
94  virtual void print(std::ostream& os) const;
95 
98  virtual AlpsReturnStatus encode(AlpsEncoded * encoded) const;
99 
101  std::cerr << "Not implemented!" << std::endl;
102  throw std::exception();
103  }
105  virtual AlpsKnowledge * decode(AlpsEncoded &) const;
106 };
107 
108 #endif
AbcSolution::decodeToSelf
virtual AlpsReturnStatus decodeToSelf(AlpsEncoded &encoded)
Decode the given AlpsEncoded object into this.
Definition: AbcSolution.h:100
AbcSolution
This class holds a MIP feasible primal solution.
Definition: AbcSolution.h:37
AlpsReturnStatus
AlpsReturnStatus
Definition: Alps.h:261
AlpsEncoded
Definition: AlpsEncoded.h:64
AbcSolution::getColSolution
const double * getColSolution() const
Get the column solution.
Definition: AbcSolution.h:87
AbcSolution::setValue
void setValue(int size, double const *value)
Definition: AbcSolution.h:72
AlpsSolution.h
AlpsSolution
Definition: AlpsSolution.h:39
AbcSolution::getSize
int getSize() const
Get the size of the solution.
Definition: AbcSolution.h:84
AbcSolution::decode
virtual AlpsKnowledge * decode(AlpsEncoded &) const
The method that decodes the solution from a encoded object.
AbcSolution::getObjValue
double getObjValue() const
Get the objective value value.
Definition: AbcSolution.h:68
AbcSolution::getColSolution
double getColSolution(int i) const
Get item i in the solution vector.
Definition: AbcSolution.h:91
AbcSolution::objective_
double objective_
Definition: AbcSolution.h:41
AlpsKnowledge
The abstract base class of Alps knowledges generated during the search.
Definition: AlpsKnowledge.h:63
AlpsKnowledge::encode
AlpsEncoded * encode() const
Encode the content of this into an AlpsEncoded object and return a pointer to it.
AbcSolution::print
virtual void print(std::ostream &os) const
Print out the solution.
AbcSolution::getQuality
virtual double getQuality() const
Definition: AbcSolution.h:81
AbcModel.h
AbcSolution::setObj
void setObj(double obj)
Definition: AbcSolution.h:70
AbcSolution::value_
double * value_
Definition: AbcSolution.h:40
AbcSolution::AbcSolution
AbcSolution()
Definition: AbcSolution.h:44
AbcSolution::~AbcSolution
~AbcSolution()
Definition: AbcSolution.h:60
AbcSolution::AbcSolution
AbcSolution(const int s, const double *val, const double obj)
Definition: AbcSolution.h:50
AbcSolution::size_
int size_
Definition: AbcSolution.h:39