00001 // Copyright (C) 2000, International Business Machines 00002 // Corporation and others. All Rights Reserved. 00003 #ifndef _BCP_LP_H 00004 #define _BCP_LP_H 00005 00006 #include <cfloat> 00007 00008 #include "BCP_math.hpp" 00009 #include "BCP_enum.hpp" 00010 #include "BCP_enum_process_t.hpp" 00011 #include "BCP_vector.hpp" 00012 00013 #include "BCP_lp_param.hpp" 00014 #include "BCP_parameters.hpp" 00015 00016 #include "BCP_buffer.hpp" 00017 #include "BCP_process.hpp" 00018 00019 //############################################################################# 00020 class BCP_lp_user; 00021 class OsiSolverInterface; 00022 class BCP_message_environment; 00023 00024 class BCP_lp_result; 00025 00026 class BCP_problem_core; 00027 class BCP_problem_core_change; 00028 00029 class BCP_var; 00030 class BCP_cut; 00031 class BCP_var_indexed; 00032 00033 class BCP_col; 00034 class BCP_row; 00035 00036 class BCP_solution; 00037 00038 class BCP_var_set_change; 00039 class BCP_cut_set_change; 00040 00041 class BCP_lp_var_pool; 00042 class BCP_lp_cut_pool; 00043 00044 class BCP_lp_node; 00045 class BCP_lp_parent; 00046 00047 //############################################################################# 00048 00049 // Everything in BCP_lp_prob is public. If the user wants to shoot herself in 00050 // the leg she can do it. 00051 00056 class BCP_lp_statistics { 00057 public: 00059 double time_feas_testing; 00061 double time_cut_generation; 00063 double time_var_generation; 00065 double time_heuristics; 00067 double time_lp_solving; 00069 double time_branching; 00070 00071 public: 00073 BCP_lp_statistics() : 00074 time_feas_testing(0), 00075 time_cut_generation(0), 00076 time_var_generation(0), 00077 time_heuristics(0), 00078 time_lp_solving(0), 00079 time_branching(0) 00080 {} 00081 00085 void pack(BCP_buffer& buf); 00087 void unpack(BCP_buffer& buf); 00091 void display() const; 00092 00095 void add(const BCP_lp_statistics& stat); 00096 }; 00097 00102 class BCP_lp_prob : public BCP_process { 00103 private: 00107 BCP_lp_prob(const BCP_lp_prob&); 00109 BCP_lp_prob& operator=(const BCP_lp_prob&); 00112 public: 00116 BCP_lp_prob(BCP_proc_id* my_id, BCP_proc_id* parent); 00118 virtual ~BCP_lp_prob(); 00121 public: 00122 //------------------------------------------------------------------------- 00123 // The unpacking classes 00126 //------------------------------------------------------------------------ 00127 // User provided members 00131 BCP_lp_user* user; 00133 OsiSolverInterface* master_lp; 00135 OsiSolverInterface* lp_solver; 00137 BCP_message_environment* msg_env; 00143 BCP_parameter_set<BCP_lp_par> par; 00146 //------------------------------------------------------------------------ 00147 // the description of the core 00151 BCP_problem_core* core; 00153 BCP_problem_core_change* core_as_change; 00156 //------------------------------------------------------------------------ 00157 // the search tree node we are working on and its parent 00161 BCP_lp_node* node; 00163 BCP_lp_parent* parent; 00166 //------------------------------------------------------------------------ 00167 // Info while processing a particular node. Need to be updated when 00168 // starting a new node. 00174 BCP_lp_result* lp_result; 00176 int var_bound_changes_since_logical_fixing; 00178 BCP_vec<BCP_cut*> slack_pool; 00180 BCP_lp_var_pool* local_var_pool; 00182 BCP_lp_cut_pool* local_cut_pool; 00183 00184 // The next/last index we can assign to a newly generated var/cut 00186 int next_var_index; 00188 int last_var_index; 00190 int next_cut_index; 00192 int last_cut_index; 00195 //------------------------------------------------------------------------ 00196 // time measurements 00200 BCP_lp_statistics stat; 00203 //------------------------------------------------------------------------ 00204 // Internal members 00205 //------------------------------------------------------------------------ 00209 double upper_bound; 00211 int phase; 00213 int no_more_cuts_cnt; // a counter for how many places we got to get 00214 // NO_MORE_CUTS message to know for sure not to 00215 // expect more. 00217 int no_more_vars_cnt; // similar for vars 00220 // message passing related fields 00224 // BCP_proc_id* tree_manager; 00226 BCP_buffer msg_buf; 00228 //------------------------------------------------------------------------ 00229 // Results of BCP_lp_user::process_lp_result() are stored here 00230 //------------------------------------------------------------------------ 00231 bool user_has_lp_result_processing; 00232 BCP_vec<BCP_cut*> new_cuts; 00233 BCP_vec<BCP_row*> new_rows; 00234 BCP_vec<BCP_var*> new_vars; 00235 BCP_vec<BCP_col*> new_cols; 00236 BCP_solution* sol; 00237 double new_true_lower_bound; 00238 00239 //------------------------------------------------------------------------ // end of data members 00241 00242 public: 00246 void pack_var(BCP_process_t target_proc, const BCP_var& var); 00248 BCP_var* unpack_var(); 00250 void pack_cut(BCP_process_t target_proc, const BCP_cut& cut); 00252 BCP_cut* unpack_cut(); 00254 void pack_var_set_change(const BCP_var_set_change& ch); 00256 void unpack_var_set_change(BCP_var_set_change& ch); 00258 void pack_cut_set_change(const BCP_cut_set_change& ch); 00260 void unpack_cut_set_change(BCP_cut_set_change& ch); 00262 //------------------------------------------------------------------------- 00265 // member functions related to accessing the parameters 00269 inline char 00270 param(BCP_lp_par::chr_params key) const { return par.entry(key); } 00272 inline int 00273 param(BCP_lp_par::int_params key) const { return par.entry(key); } 00275 inline double 00276 param(BCP_lp_par::dbl_params key) const { return par.entry(key); } 00278 inline const BCP_string& 00279 param(BCP_lp_par::str_params key) const { return par.entry(key); } 00281 inline const BCP_vec<BCP_string>& 00282 param(BCP_lp_par::str_array_params key) const { return par.entry(key); } 00284 inline double granularity() const { 00285 return param(BCP_lp_par::Granularity); 00286 } 00289 //------------------------------------------------------------------------- 00293 inline bool has_ub() const { return upper_bound < BCP_DBL_MAX / 10; } 00295 inline double ub() const { return upper_bound; } 00297 inline bool ub(double new_ub) { 00298 if (new_ub < upper_bound){ 00299 upper_bound = new_ub; 00300 return true; 00301 } 00302 return false; 00303 } 00305 inline bool over_ub(double lb) const { 00306 return has_ub() && lb >= upper_bound - granularity(); 00307 } 00309 // end of query methods 00310 //------------------------------------------------------------------------- 00311 virtual BCP_buffer& get_message_buffer() { return msg_buf; } 00312 virtual void process_message(); 00313 }; 00314 00315 #endif