00001 // Copyright (C) 2005, International Business Machines 00002 // Corporation and others. All Rights Reserved. 00003 #ifndef _CSP_VAR_H 00004 #define _CSP_VAR_H 00005 00006 #include <cfloat> 00007 #include "BCP_vector.hpp" 00008 #include "BCP_var.hpp" 00009 #include "BCP_buffer.hpp" 00010 #include "CSP.hpp" 00011 00012 00013 //############################################################################# 00014 00015 // PATTERN defined in CSP.hpp. Csp_var uses multiple inheritance. 00016 class CSP_var : public BCP_var_algo, public PATTERN { 00017 00018 public: 00019 //CSP: 00020 // ToDo: make the ub a computed upper bound "on the fly" 00021 // based on demand using existing lbs on other patterns 00022 // This has to go in two places 00023 // (1) when we start to work on a node (initialize_new_search_tree_node) 00024 // (2) when a new var is created, vars_to_cols routine where you specify 00025 // new upper bound for created var 00026 00027 // Need (i) default constructor, 00028 // (ii) a "real" constructor 00029 // (iii)copy constructor, 00030 // (We won't have a constructor that uses a buffer reference.) 00031 00032 // Default constructor. 00033 // Note: Constructor for BCP_var_algo has 3 arguments: 00034 // BCP_IntegerVar, objCoef, lb, ub) 00035 CSP_var() : BCP_var_algo(BCP_IntegerVar, 0, 0.0, DBL_MAX), PATTERN() {} 00036 00037 // Constructor 00038 CSP_var(const PATTERN& pat) : 00039 BCP_var_algo(BCP_IntegerVar, pat.getCost(), 0.0, pat.getUb()), 00040 PATTERN(pat) {} 00041 00042 // Copy constructor 00043 CSP_var(const CSP_var& x) : 00044 BCP_var_algo(BCP_IntegerVar, x.getCost(), x.lb(), x.ub()), 00045 PATTERN(x) {} 00046 00047 // Destructor 00048 // Does the destructor of the CSP_var automatically call the destructor 00049 // of the PATTERN? Yes. 00050 ~CSP_var() {} 00051 00052 }; 00053 00054 //############################################################################# 00055 00056 // If there were only one type of var, then the pack and unpack 00057 // could be member functions. In the auction code, there were 00058 // two types of vars, so the pack/unpack were chosen to be written 00059 // here so the caller could tell by the function name what was being 00060 // unpacked. This design is a little cleaner than having some 00061 // sort of indicator in the first unpacked bit, or some other scheme. 00062 // Because we are brave and think we may expand the CSP in this 00063 // direction, we will do likewise. 00064 00065 // when "static" not used, the linkers got upset becuase including 00066 // this file multiple places led to the function being 00067 // defined multiple times. 00068 // One solution is to put it in the .cpp file, but 00069 // we'd like to inline this little function, so we 00070 // used the static keyword to work around the linker issue. 00071 00072 static inline BCP_var_algo* CSP_var_unpack(BCP_buffer& buf){ 00073 PATTERN pat(buf); 00074 return new CSP_var(pat); 00075 } 00076 00077 // a CSP_var IS A pattern 00078 static inline void CSP_var_pack(const BCP_var_algo* var, BCP_buffer& buf){ 00079 dynamic_cast<const CSP_var *>(var)->pack(buf); 00080 } 00081 00082 #endif