coin-Bcp
CSP_var.hpp
Go to the documentation of this file.
1 // Copyright (C) 2005, International Business Machines
2 // Corporation and others. All Rights Reserved.
3 #ifndef _CSP_VAR_H
4 #define _CSP_VAR_H
5 
6 #include <cfloat>
7 #include "BCP_vector.hpp"
8 #include "BCP_var.hpp"
9 #include "BCP_buffer.hpp"
10 #include "CSP.hpp"
11 
12 
13 //#############################################################################
14 
15 // PATTERN defined in CSP.hpp. Csp_var uses multiple inheritance.
16 class CSP_var : public BCP_var_algo, public PATTERN {
17 
18 public:
19  //CSP:
20  // ToDo: make the ub a computed upper bound "on the fly"
21  // based on demand using existing lbs on other patterns
22  // This has to go in two places
23  // (1) when we start to work on a node (initialize_new_search_tree_node)
24  // (2) when a new var is created, vars_to_cols routine where you specify
25  // new upper bound for created var
26 
27  // Need (i) default constructor,
28  // (ii) a "real" constructor
29  // (iii)copy constructor,
30  // (We won't have a constructor that uses a buffer reference.)
31 
32  // Default constructor.
33  // Note: Constructor for BCP_var_algo has 3 arguments:
34  // BCP_IntegerVar, objCoef, lb, ub)
35  CSP_var() : BCP_var_algo(BCP_IntegerVar, 0, 0.0, DBL_MAX), PATTERN() {}
36 
37  // Constructor
38  CSP_var(const PATTERN& pat) :
39  BCP_var_algo(BCP_IntegerVar, pat.getCost(), 0.0, pat.getUb()),
40  PATTERN(pat) {}
41 
42  // Copy constructor
43  CSP_var(const CSP_var& x) :
44  BCP_var_algo(BCP_IntegerVar, x.getCost(), x.lb(), x.ub()),
45  PATTERN(x) {}
46 
47  // Destructor
48  // Does the destructor of the CSP_var automatically call the destructor
49  // of the PATTERN? Yes.
50  ~CSP_var() {}
51 
52 };
53 
54 //#############################################################################
55 
56 // If there were only one type of var, then the pack and unpack
57 // could be member functions. In the auction code, there were
58 // two types of vars, so the pack/unpack were chosen to be written
59 // here so the caller could tell by the function name what was being
60 // unpacked. This design is a little cleaner than having some
61 // sort of indicator in the first unpacked bit, or some other scheme.
62 // Because we are brave and think we may expand the CSP in this
63 // direction, we will do likewise.
64 
65 // when "static" not used, the linkers got upset becuase including
66 // this file multiple places led to the function being
67 // defined multiple times.
68 // One solution is to put it in the .cpp file, but
69 // we'd like to inline this little function, so we
70 // used the static keyword to work around the linker issue.
71 
72 static inline BCP_var_algo* CSP_var_unpack(BCP_buffer& buf){
73  PATTERN pat(buf);
74  return new CSP_var(pat);
75 }
76 
77  // a CSP_var IS A pattern
78 static inline void CSP_var_pack(const BCP_var_algo* var, BCP_buffer& buf){
79  dynamic_cast<const CSP_var *>(var)->pack(buf);
80 }
81 
82 #endif
double getUb() const
Definition: CSP.hpp:223
CSP_var(const CSP_var &x)
Definition: CSP_var.hpp:43
Definition: CSP.hpp:177
~CSP_var()
Definition: CSP_var.hpp:50
CSP_var(const PATTERN &pat)
Definition: CSP_var.hpp:38
double ub() const
Return the upper bound.
Definition: BCP_var.hpp:91
CSP_var()
Definition: CSP_var.hpp:35
This is the class from which the user should derive her own algorithmic variables.
Definition: BCP_var.hpp:277
This class describes the message buffer used for all processes of BCP.
Definition: BCP_buffer.hpp:39
static BCP_var_algo * CSP_var_unpack(BCP_buffer &buf)
Definition: CSP_var.hpp:72
double getCost() const
Definition: CSP.hpp:222
static void CSP_var_pack(const BCP_var_algo *var, BCP_buffer &buf)
Definition: CSP_var.hpp:78
double lb() const
Return the lower bound.
Definition: BCP_var.hpp:89
General integer variable.
Definition: BCP_enum.hpp:165