coin-Bcp
CSP_lp.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_LP_H
4 #define _CSP_LP_H
5 
6 #include <cfloat>
7 #include <map>
8 #include <vector>
9 
11 
12 #include "BCP_parameters.hpp"
13 #include "BCP_lp_user.hpp"
14 
15 #include "CSP_lp_param.hpp"
16 #include "CSP_var.hpp"
17 #include "CSP_colgen.hpp"
18 
19 class CSP_lp : public BCP_lp_user {
20  // private data
21 private:
22  // this is where we store the
23  // columns generated in the compute_lower_bound method
24  // for use elsewhere in our application.
25  std::vector<PATTERN*> improving_patterns_;
26 
27  // public data
28 public:
30 
31  // pointer to the static problem information
32  // there's only one LP module, so no need to declare this "static"
34 
36 
37  // public methods
38 public:
39  // constructor
40  CSP_lp() : csproblem(0), colgen(0) {}
41 
42  // destructor
43  ~CSP_lp() {
44  std::for_each(improving_patterns_.begin(),
46  delete csproblem;
47  delete colgen;
48  }
49 
50  //==========================================================================
56  // inherited methods
57  virtual void
59 
61  virtual void
63  CSP_var_pack(var, buf);
64  }
65 
67  virtual BCP_var_algo*
69  return CSP_var_unpack(buf);
70  }
71 
72  //==========================================================================
82  virtual OsiSolverInterface *
84 
85  //==========================================================================
102  // *LL* : needs to be written if when we'll do real column generation. Then
103  // *LL* : we'll need to figure out the previous branching decisions. For
104  // *LL* : now we just do B&B, so we don't need this.
105 
106  virtual void
108  const BCP_vec<BCP_cut*>& cuts,
109  const BCP_vec<BCP_obj_status>& var_status,
110  const BCP_vec<BCP_obj_status>& cut_status,
111  BCP_vec<int>& var_changed_pos,
112  BCP_vec<double>& var_new_bd,
113  BCP_vec<int>& cut_changed_pos,
114  BCP_vec<double>& cut_new_bd);
115 
116  //==========================================================================
123  virtual void
124  modify_lp_parameters(OsiSolverInterface* lp, bool in_strong_branching);
125 
126  //==========================================================================
136  virtual double
137  compute_lower_bound(const double old_lower_bound,
138  const BCP_lp_result& lpres,
139  const BCP_vec<BCP_var*>& vars,
140  const BCP_vec<BCP_cut*>& cuts);
141  //==========================================================================
142 
158  // *LL* : sufficient to test binary-ness,
159 #if 0
160  virtual BCP_solution*
161  test_feasibility(const BCP_lp_result& lpres,
162  const BCP_vec<BCP_var*>& vars,
163  const BCP_vec<BCP_cut*>& cuts);
164 #endif
165  //==========================================================================
170  // *LL* : should be written even for B&B (to find good soln's quickly) and
171  // *LL* : definitely for column generation, but for now it's not an
172  // *LL* : absolute necessity.
173 
174  // This code invokes the default (do nothing) function in BCP
175  // virtual BCP_solution*
176  // generate_heuristic_solution(const BCP_lp_result& lpres,
177  // const BCP_vec<BCP_var*>& vars,
178  // const BCP_vec<BCP_cut*>& cuts) {
179  // return BCP_lp_user::generate_heuristic_solution(lpres, vars, cuts);
180  // }
181 
182 
183  virtual BCP_solution*
185  const BCP_vec<BCP_var*>& vars,
186  const BCP_vec<BCP_cut*>& cuts);
187 
188  //==========================================================================
195  // get one dual ray from the solver, and try to generate columns that cut
196  // off the dual ray.
197  // RLH: need to write.
198  virtual void
199  restore_feasibility(const BCP_lp_result& lpres,
200  const std::vector<double*> dual_rays,
201  const BCP_vec<BCP_var*>& vars,
202  const BCP_vec<BCP_cut*>& cuts,
203  BCP_vec<BCP_var*>& vars_to_add,
204  BCP_vec<BCP_col*>& cols_to_add);
205 
206  //==========================================================================
227  virtual void
228  vars_to_cols(const BCP_vec<BCP_cut*>& cuts, // on what to expand
229  BCP_vec<BCP_var*>& vars, // what to expand
230  BCP_vec<BCP_col*>& cols, // the expanded cols
231  // things that the user can use for lifting vars if allowed
232  const BCP_lp_result& lpres,
233  BCP_object_origin origin, bool allow_multiple);
234 
235  void
237  BCP_vec<BCP_col*>& cols);
238 
239  //==========================================================================
253  // *LL* : for now we don't have cuts, so the default is fine.
254  virtual void
256  const BCP_vec<BCP_var*>& vars,
257  const BCP_vec<BCP_cut*>& cuts,
258  BCP_vec<BCP_cut*>& new_cuts,
259  BCP_vec<BCP_row*>& new_rows) {
260  BCP_lp_user::generate_cuts_in_lp(lpres, vars, cuts, new_cuts, new_rows);
261  }
262 
263  //==========================================================================
280  virtual void
281  generate_vars_in_lp(const BCP_lp_result& lpres,
282  const BCP_vec<BCP_var*>& vars,
283  const BCP_vec<BCP_cut*>& cuts,
284  const bool before_fathom,
285  BCP_vec<BCP_var*>& new_vars,
286  BCP_vec<BCP_col*>& new_cols);
287 
288  //==========================================================================
296  // *LL* : for now we don't have cuts, so the default is fine.
298  compare_cuts(const BCP_cut* c0, const BCP_cut* c1) {
299  return BCP_lp_user::compare_cuts(c0, c1);
300  }
301 
302  //==========================================================================
311  // *LL* : for now we have included every var in the formulation at the root
312  // *LL* : node, so default is fine. Later we need to write this one.
314  compare_vars(const BCP_var* v0, const BCP_var* v1) {
315  return BCP_lp_user::compare_vars(v0, v1);
316  }
317 
318  //==========================================================================
334  // *LL* : This is not a must, but would be nice to add setpacking matrix
335  // *LL* : reduction techniques eventually. For now use the default.
336  virtual void
338  const BCP_vec<BCP_var*>& vars,
339  const BCP_vec<BCP_cut*>& cuts,
340  const BCP_vec<BCP_obj_status>& var_status,
341  const BCP_vec<BCP_obj_status>& cut_status,
342  const int var_bound_changes_since_logical_fixing,
343  BCP_vec<int>& changed_pos, BCP_vec<double>& new_bd) {
344  BCP_lp_user::logical_fixing(lpres, vars, cuts, var_status, cut_status,
345  var_bound_changes_since_logical_fixing,
346  changed_pos, new_bd);
347  }
348 
349  //==========================================================================
352  virtual BCP_branching_decision
354  const BCP_vec<BCP_var*>& vars,
355  const BCP_vec<BCP_cut*>& cuts,
356  const BCP_lp_var_pool& local_var_pool,
357  const BCP_lp_cut_pool& local_cut_pool,
360  branch_on_half(const BCP_lp_result& lpres,
361  const BCP_vec<BCP_var*>& vars);
362 
363  //==========================================================================
377  // *LL* : Use default for now
378  // *LL* : Later we can play with integrality based branching
381  BCP_presolved_lp_brobj* old_solved) {
382  return BCP_lp_user::compare_branching_candidates(new_solved, old_solved);
383  }
384 
385 
386  //==========================================================================
406  // *LL* : The THINK comment above will definitely
407  // *LL* : apply when we'll do column generation
408  virtual void
410 
411  //==========================================================================
429  // *LL* : Used only when branching on dynamically generated cuts is
430  // *LL* : allowed, but we don't generate cuts...
431  virtual void
433  BCP_vec<int>& to_be_purged) {
434  BCP_lp_user::purge_slack_pool(slack_pool, to_be_purged);
435  }
436 
437 
438  //==========================================================================
439 
440 };
441 #endif
BCP_object_origin
This enumerative constant describes the origin (originating process) of an object (variable or cut)...
Definition: BCP_enum.hpp:249
virtual BCP_branching_decision select_branching_candidates(const BCP_lp_result &lpres, const BCP_vec< BCP_var * > &vars, const BCP_vec< BCP_cut * > &cuts, const BCP_lp_var_pool &local_var_pool, const BCP_lp_cut_pool &local_cut_pool, BCP_vec< BCP_lp_branching_object * > &cands)
Decide whether to branch or not and select a set of branching candidates if branching is decided upon...
virtual void unpack_module_data(BCP_buffer &buf)
Unpack the initial information sent to the LP process by the Tree Manager.
virtual BCP_solution * generate_heuristic_solution(const BCP_lp_result &lpres, const BCP_vec< BCP_var * > &vars, const BCP_vec< BCP_cut * > &cuts)
Evaluate and return MIP feasibility of the current solution.
Abstract base class that defines members common to all types of cuts.
Definition: BCP_cut.hpp:29
virtual BCP_solution * test_feasibility(const BCP_lp_result &lp_result, const BCP_vec< BCP_var * > &vars, const BCP_vec< BCP_cut * > &cuts)
Evaluate and return MIP feasibility of the current solution.
virtual BCP_var_algo * unpack_var_algo(BCP_buffer &buf)
Unpack an algorithmic variable.
Definition: CSP_lp.hpp:68
virtual void logical_fixing(const BCP_lp_result &lpres, const BCP_vec< BCP_var * > &vars, const BCP_vec< BCP_cut * > &cuts, const BCP_vec< BCP_obj_status > &var_status, const BCP_vec< BCP_obj_status > &cut_status, const int var_bound_changes_since_logical_fixing, BCP_vec< int > &changed_pos, BCP_vec< double > &new_bd)
This method provides an opportunity for the user to tighten the bounds of variables.
Definition: CSP_lp.hpp:337
virtual void modify_lp_parameters(OsiSolverInterface *lp, bool in_strong_branching)
This method provides an opportunity for the user to change parameters of the LP solver before optimiz...
virtual double compute_lower_bound(const double old_lower_bound, const BCP_lp_result &lpres, const BCP_vec< BCP_var * > &vars, const BCP_vec< BCP_cut * > &cuts)
Compute a true lower bound for the subproblem.
CSPROBLEM * csproblem
Definition: CSP_lp.hpp:33
CSP_colgen * colgen
Definition: CSP_lp.hpp:35
virtual BCP_object_compare_result compare_vars(const BCP_var *v0, const BCP_var *v1)
Compare two generated variables.
Definition: CSP_lp.hpp:314
virtual void purge_slack_pool(const BCP_vec< BCP_cut * > &slack_pool, BCP_vec< int > &to_be_purged)
Selectively purge the list of slack cuts.
The BCP_lp_user class is the base class from which the user can derive a problem specific class to be...
Definition: BCP_lp_user.hpp:75
virtual BCP_branching_object_relation compare_branching_candidates(BCP_presolved_lp_brobj *new_solved, BCP_presolved_lp_brobj *old_solved)
Decide which branching object is preferred for branching.
virtual void logical_fixing(const BCP_lp_result &lpres, const BCP_vec< BCP_var * > &vars, const BCP_vec< BCP_cut * > &cuts, const BCP_vec< BCP_obj_status > &var_status, const BCP_vec< BCP_obj_status > &cut_status, const int var_bound_changes_since_logical_fixing, BCP_vec< int > &changed_pos, BCP_vec< double > &new_bd)
This method provides an opportunity for the user to tighten the bounds of variables.
virtual void generate_cuts_in_lp(const BCP_lp_result &lpres, const BCP_vec< BCP_var * > &vars, const BCP_vec< BCP_cut * > &cuts, BCP_vec< BCP_cut * > &new_cuts, BCP_vec< BCP_row * > &new_rows)
Generate cuts within the LP process.
virtual OsiSolverInterface * initialize_solver_interface()
Create a ptr to an OsiSolverInterface object that will be used for solving the LP relaxations...
virtual BCP_object_compare_result compare_cuts(const BCP_cut *c0, const BCP_cut *c1)
Compare two generated cuts.
virtual void generate_vars_in_lp(const BCP_lp_result &lpres, const BCP_vec< BCP_var * > &vars, const BCP_vec< BCP_cut * > &cuts, const bool before_fathom, BCP_vec< BCP_var * > &new_vars, BCP_vec< BCP_col * > &new_cols)
Generate variables within the LP process.
virtual BCP_object_compare_result compare_vars(const BCP_var *v0, const BCP_var *v1)
Compare two generated variables.
virtual void restore_feasibility(const BCP_lp_result &lpres, const std::vector< double * > dual_rays, const BCP_vec< BCP_var * > &vars, const BCP_vec< BCP_cut * > &cuts, BCP_vec< BCP_var * > &vars_to_add, BCP_vec< BCP_col * > &cols_to_add)
Restoring feasibility.
virtual BCP_object_compare_result compare_cuts(const BCP_cut *c0, const BCP_cut *c1)
Compare two generated cuts.
Definition: CSP_lp.hpp:298
This class describes a generic branching object.
BCP_branching_decision
This enumerative constant is the return value of the select_branching_candidates() method in [BCP_lp_...
std::vector< PATTERN * > improving_patterns_
Definition: CSP_lp.hpp:25
Abstract Base Class for describing an interface to a solver.
~CSP_lp()
Definition: CSP_lp.hpp:43
Abstract base class that defines members common to all types of variables.
Definition: BCP_var.hpp:28
A presolved branching object candidate.
This is the class from which the user should derive her own algorithmic variables.
Definition: BCP_var.hpp:277
virtual BCP_branching_object_relation compare_branching_candidates(BCP_presolved_lp_brobj *new_solved, BCP_presolved_lp_brobj *old_solved)
Decide which branching object is preferred for branching.
Definition: CSP_lp.hpp:380
CSP_lp()
Definition: CSP_lp.hpp:40
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
virtual void generate_cuts_in_lp(const BCP_lp_result &lpres, const BCP_vec< BCP_var * > &vars, const BCP_vec< BCP_cut * > &cuts, BCP_vec< BCP_cut * > &new_cuts, BCP_vec< BCP_row * > &new_rows)
Generate cuts within the LP process.
Definition: CSP_lp.hpp:255
virtual void purge_slack_pool(const BCP_vec< BCP_cut * > &slack_pool, BCP_vec< int > &to_be_purged)
Selectively purge the list of slack cuts.
Definition: CSP_lp.hpp:432
static void CSP_var_pack(const BCP_var_algo *var, BCP_buffer &buf)
Definition: CSP_var.hpp:78
BCP_branching_object_relation
This enumerative constant is the return value of the compare_presolved_branching_objects() method in ...
This class holds the results after solving an LP relaxation.
virtual void vars_to_cols(const BCP_vec< BCP_cut * > &cuts, BCP_vec< BCP_var * > &vars, BCP_vec< BCP_col * > &cols, const BCP_lp_result &lpres, BCP_object_origin origin, bool allow_multiple)
Convert a set of variables into corresponding columns for the current LP relaxation.
virtual void set_actions_for_children(BCP_presolved_lp_brobj *best)
Decide what to do with the children of the selected branching object.
virtual void initialize_new_search_tree_node(const BCP_vec< BCP_var * > &vars, const BCP_vec< BCP_cut * > &cuts, const BCP_vec< BCP_obj_status > &var_status, const BCP_vec< BCP_obj_status > &cut_status, BCP_vec< int > &var_changed_pos, BCP_vec< double > &var_new_bd, BCP_vec< int > &cut_changed_pos, BCP_vec< double > &cut_new_bd)
This method serves as hook for the user to do some preprocessing on a search tree node before the nod...
BCP_lp_branching_object * branch_on_half(const BCP_lp_result &lpres, const BCP_vec< BCP_var * > &vars)
BCP_object_compare_result
This enumerative constant describes the possible outcomes when comparing two objects (variables or cu...
Definition: BCP_enum.hpp:276
BCP_parameter_set< CSP_lp_par > par
Definition: CSP_lp.hpp:29
This is the abstract base class for a solution to a Mixed Integer Programming problem.
virtual void pack_var_algo(const BCP_var_algo *var, BCP_buffer &buf)
Pack an algorithmic variable.
Definition: CSP_lp.hpp:62