BlisSolution.h
Go to the documentation of this file.
1 /*===========================================================================*
2  * This file is part of the BiCePS Linear Integer Solver (BLIS). *
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-2013, Lehigh University, Yan Xu, and Ted Ralphs. *
21  * All Rights Reserved. *
22  *===========================================================================*/
23 
24 #ifndef BlisSolution_h_
25 #define BlisSolution_h_
26 
27 #include "Alps.h"
28 #include "BcpsSolution.h"
29 
30 //#############################################################################
34 //#############################################################################
35 
36 class BlisSolution : public BcpsSolution {
37 
38  protected:
39 
40  public:
41 
44  :
45  BcpsSolution()
46  {}
47 
49  BlisSolution(int s, const double *values, double objValue)
50  :
51  BcpsSolution(s, values, objValue)
52  {}
53 
55  virtual ~BlisSolution() { }
56 
59  virtual void print(std::ostream& os) const {
60  double nearInt = 0.0;
61  for (int j = 0; j < size_; ++j) {
62  if (values_[j] > 1.0e-15 || values_[j] < -1.0e-15) {
63  nearInt = floor(values_[j] + 0.5);
64  if (ALPS_FABS(nearInt - values_[j]) < 1.0e-6) {
65  os << "x[" << j << "] = " << nearInt << std::endl;
66  }
67  else {
68  os << "x[" << j << "] = " << values_[j] << std::endl;
69  }
70  }
71  }
72  }
73 
76  // BlisIpSolution* testIntegrality(const double etol = 1e-5) const;
77 
78  using AlpsKnowledge::encode ;
80  virtual AlpsEncoded* encode() const {
82  encodeBcps(encoded);
83  // Nothing to do for Blis part.
84  return encoded;
85  }
86 
88  virtual AlpsKnowledge* decode(AlpsEncoded& encoded) const {
89  BlisSolution * sol = new BlisSolution();
90  sol->decodeBcps(encoded);
91  return sol;
92  }
93 
94 };
95 
96 //#############################################################################
97 //#############################################################################
98 
99 #endif
#define ALPS_FABS(x)
Definition: Alps.h:174
virtual AlpsKnowledge * decode(AlpsEncoded &encoded) const
The method that decodes the solution from a encoded object.
Definition: BlisSolution.h:88
AlpsReturnStatus decodeBcps(AlpsEncoded &encoded)
Unpack Bcps part of solution from an encoded objects.
This class holds the solution objects.
Definition: BcpsSolution.h:34
This data structure is to contain the packed form of an encodable knowledge.
Definition: AlpsEncoded.h:25
virtual ~BlisSolution()
Destructor.
Definition: BlisSolution.h:55
virtual AlpsEncoded * encode() const
The method that encodes the solution into a encoded object.
Definition: BlisSolution.h:80
AlpsReturnStatus encodeBcps(AlpsEncoded *encoded) const
Pack Bcps part of solution into an encoded objects.
This class contains the solutions generated by the LP solver (either primal or dual.
Definition: BlisSolution.h:36
The abstract base class of any user-defined class that Alps has to know about in order to encode/deco...
Definition: AlpsKnowledge.h:51
double * values_
Solution values.
Definition: BcpsSolution.h:50
BlisSolution(int s, const double *values, double objValue)
Useful constructor.
Definition: BlisSolution.h:49
virtual void print(std::ostream &os) const
Print out the solution.
Definition: BlisSolution.h:59
BlisSolution()
Default constructor.
Definition: BlisSolution.h:43
virtual AlpsEncoded * encode() const
This method should encode the content of the object and return a pointer to the encoded form...
int size_
Size of values_.
Definition: BcpsSolution.h:44