coin-Bcp
MC_cut.hpp
Go to the documentation of this file.
1 // Copyright (C) 2000, International Business Machines
2 // Corporation and others. All Rights Reserved.
3 #ifndef _MC_CUT_H
4 #define _MC_CUT_H
5 
6 #include <algorithm>
7 
9 
10 #include "BCP_math.hpp"
11 #include "BCP_mempool.hpp"
12 #include "BCP_cut.hpp"
13 
14 class BCP_buffer;
15 class BCP_row;
16 class MC_problem;
17 class MC_solution;
18 
19 //#############################################################################
20 
21 enum MC_cut_t {
24 };
25 
30 };
31 
32 //#############################################################################
33 
34 class MC_cycle_cut : public BCP_cut_algo {
35 private:
36  MC_cycle_cut(const MC_cycle_cut&);
38 private:
40 public:
41  static inline void * operator new(size_t size) {
42  return memPool.alloc(size);
43  }
44  static inline void operator delete(void *p, size_t size) {
45  memPool.free(p, size);
46  }
47 public:
48  int cycle_len; // length of the cycle
49  int pos_edges; // number of edges with positive coefficient
50  int* edges;
51 public:
52  MC_cycle_cut(const int* ei, const int pos, const int len) :
53  BCP_cut_algo(-BCP_DBL_MAX, pos-1.0),
54  cycle_len(len), pos_edges(pos), edges(0)
55  {
56  if (len > 0) {
57  edges = new int[len];
58  CoinDisjointCopyN(ei, len, edges);
59  }
60  }
63  delete[] edges;
64  }
65 
66  void pack(BCP_buffer& buf) const;
67 };
68 
69 //#############################################################################
70 
72 private:
75 private:
77 public:
78  static inline void * operator new(size_t size) {
79  return memPool.alloc(size);
80  }
81  static inline void operator delete(void *p, size_t size) {
82  memPool.free(p, size);
83  }
84 public:
85  double rhs;
86  double * coeffs;
87  int varnum;
88 public:
89  MC_explicit_dense_cut(const double ub, const int num,
90  const double * elements) :
92  rhs(ub), coeffs(new double[num]), varnum(num)
93  {
94  CoinDisjointCopyN(elements, num, coeffs);
95  }
98  delete[] coeffs;
99  }
100 
101  void pack(BCP_buffer& buf) const;
102 };
103 
104 //#############################################################################
105 
106 inline bool
107 MC_cycle_cut_less(const BCP_cut* bc0, const BCP_cut* bc1) {
108  const MC_cycle_cut* c0 = dynamic_cast<const MC_cycle_cut*>(bc0);
109  const MC_cycle_cut* c1 = dynamic_cast<const MC_cycle_cut*>(bc1);
110  if (c0->cycle_len < c1->cycle_len)
111  return true;
112  if (c1->cycle_len < c0->cycle_len)
113  return false;
114  if (c0->pos_edges < c1->pos_edges)
115  return true;
116  if (c1->pos_edges < c0->pos_edges)
117  return false;
118  return memcmp(c0->edges, c1->edges, c0->cycle_len * sizeof(int)) < 0;
119 }
120 
121 inline bool
122 MC_cycle_cut_equal(const BCP_cut* bc0, const BCP_cut* bc1) {
123  const MC_cycle_cut* c0 = dynamic_cast<const MC_cycle_cut*>(bc0);
124  const MC_cycle_cut* c1 = dynamic_cast<const MC_cycle_cut*>(bc1);
125  return (c0->cycle_len == c1->cycle_len &&
126  c0->pos_edges == c1->pos_edges &&
127  memcmp(c0->edges, c1->edges, c0->cycle_len * sizeof(int)) == 0);
128 }
129 
130 //#############################################################################
131 
133 MC_mst_heur(const MC_problem & mc, const double * x, const double * w,
134  const double alpha, const double beta,
135  const MC_EdgeOrdering edge_ordering,
136  const int heurswitchround,
137  const bool do_edge_switch_heur, const int struct_switch_heur);
138 
139 //#############################################################################
140 
142 MC_mst_cutgen(const MC_problem& mc, const double* x, const double* w,
143  const double alpha, const double beta,
144  const MC_EdgeOrdering edge_ordering,
145  const int heurswitchround,
146  const bool do_edge_switch_heur, const int struct_switch_heur,
147  const double minviol, const int maxnewcuts,
148  BCP_vec<BCP_cut*>& new_cuts, BCP_vec<BCP_row*>& new_rows);
149 
150 //-----------------------------------------------------------------------------
151 
152 void
153 MC_kruskal(const MC_problem& mc, const int * edgeorder, const double* x,
154  int * nodesign, int * edges_in_tree);
155 
156 //-----------------------------------------------------------------------------
157 
158 void
159 MC_kruskal(const MC_problem& mc, const int * edgeorder, const double* x,
160  int * nodesign, int * parentnode, int * parentedge);
161 
162 //#############################################################################
163 
164 void
165 MC_generate_shortest_path_cycles(const MC_problem& mc, const double* x,
166  const bool generate_all_cuts,
167  const double minviol,
168  BCP_vec<BCP_cut*>& new_cuts,
169  BCP_vec<BCP_row*>& new_rows);
170 
171 //#############################################################################
172 
173 void
174 MC_test_ising_four_cycles(const int n, const int* cycles,
175  const double* x, const double minviol,
176  BCP_vec<BCP_cut*>& cuts, BCP_vec<BCP_row*>& rows);
177 
178 void
179 MC_test_ising_triangles(const int n, const int* triangles,
180  const double* x, const double minviol,
181  BCP_vec<BCP_cut*>& cuts, BCP_vec<BCP_row*>& rows);
182 
183 #endif
void MC_test_ising_four_cycles(const int n, const int *cycles, const double *x, const double minviol, BCP_vec< BCP_cut * > &cuts, BCP_vec< BCP_row * > &rows)
MC_cycle_cut(const int *ei, const int pos, const int len)
Definition: MC_cut.hpp:52
~MC_cycle_cut()
Definition: MC_cut.hpp:62
bool MC_cycle_cut_equal(const BCP_cut *bc0, const BCP_cut *bc1)
Definition: MC_cut.hpp:122
Abstract base class that defines members common to all types of cuts.
Definition: BCP_cut.hpp:29
MC_explicit_dense_cut(const MC_explicit_dense_cut &)
This is the class from which the user should derive her own algorithmic cuts.
Definition: BCP_cut.hpp:242
double ub() const
Return the upper bound on the cut.
Definition: BCP_cut.hpp:84
MC_solution * MC_mst_cutgen(const MC_problem &mc, const double *x, const double *w, const double alpha, const double beta, const MC_EdgeOrdering edge_ordering, const int heurswitchround, const bool do_edge_switch_heur, const int struct_switch_heur, const double minviol, const int maxnewcuts, BCP_vec< BCP_cut * > &new_cuts, BCP_vec< BCP_row * > &new_rows)
MC_explicit_dense_cut(const double ub, const int num, const double *elements)
Definition: MC_cut.hpp:89
MC_EdgeOrdering
Definition: MC_cut.hpp:26
void pack(BCP_buffer &buf) const
#define BCP_DBL_MAX
Definition: BCP_math.hpp:6
int cycle_len
Definition: MC_cut.hpp:48
void free(void *p, size_t n)
Definition: BCP_mempool.hpp:68
static BCP_MemPool memPool
Definition: MC_cut.hpp:76
void pack(BCP_buffer &buf) const
int * edges
Definition: MC_cut.hpp:50
MC_cut_t
Definition: MC_cut.hpp:21
void * alloc(size_t n)
Definition: BCP_mempool.hpp:28
static BCP_MemPool memPool
Definition: MC_cut.hpp:39
MC_cycle_cut(const MC_cycle_cut &)
MC_cycle_cut & operator=(const MC_cycle_cut &)
This class describes the message buffer used for all processes of BCP.
Definition: BCP_buffer.hpp:39
int pos_edges
Definition: MC_cut.hpp:49
void MC_test_ising_triangles(const int n, const int *triangles, const double *x, const double minviol, BCP_vec< BCP_cut * > &cuts, BCP_vec< BCP_row * > &rows)
void CoinDisjointCopyN(const T *from, const CoinBigIndex size, T *to)
This helper function copies an array to another location.
bool MC_cycle_cut_less(const BCP_cut *bc0, const BCP_cut *bc1)
Definition: MC_cut.hpp:107
MC_explicit_dense_cut & operator=(const MC_explicit_dense_cut &)
void MC_generate_shortest_path_cycles(const MC_problem &mc, const double *x, const bool generate_all_cuts, const double minviol, BCP_vec< BCP_cut * > &new_cuts, BCP_vec< BCP_row * > &new_rows)
void MC_kruskal(const MC_problem &mc, const int *edgeorder, const double *x, int *nodesign, int *edges_in_tree)
MC_solution * MC_mst_heur(const MC_problem &mc, const double *x, const double *w, const double alpha, const double beta, const MC_EdgeOrdering edge_ordering, const int heurswitchround, const bool do_edge_switch_heur, const int struct_switch_heur)
This class holds a row in a compressed form.
Definition: BCP_matrix.hpp:152