coin-Bcp
MC.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_H
4 #define _MC_H
5 
6 #include "BCP_vector.hpp"
7 
8 class BCP_buffer;
9 
11 public:
12  int neighbor;
13  int index;
14  double cost;
15  MC_adjacency_entry() : neighbor(-1), cost(0.0) {}
16  MC_adjacency_entry(int n, double c) : neighbor(n), cost(c) {}
17 };
18 
20 public:
21  int degree;
23  MC_graph_node() : degree(-1), adj_list(0) {}
25 };
26 
28 public:
29  int tail;
30  int head;
31  double cost;
32 public:
33  MC_graph_edge() : tail(-1), head(-1), cost(0.0) {}
34  MC_graph_edge(int t, int h, double c) : tail(t), head(h), cost(c) {}
35 };
36 
38 private:
41 public:
42  int num_nodes;
44  int * nodes;
45  int * neighbors;
47  num_nodes(0), num_neighbors(0), nodes(0), neighbors(0) {}
49  delete[] nodes;
50  // neighbors is the second part of the nodes array
51  }
52 };
53 
54 class MC_feas_sol {
55 public:
56  double cost;
57  int num_nodes;
58  int* sign;
59  int num_edges;
60  double* value;
61  MC_feas_sol(const int nnodes, int*& s,
62  const int nedges, const MC_graph_edge* edges) :
63  num_nodes(nnodes),
64  sign(s),
65  num_edges(nedges),
66  value(new double[nedges])
67  {
68  cost = 0;
69  for (int i = 0; i < nedges; ++i) {
70  value[i] = sign[edges[i].tail] == sign[edges[i].head] ? 0 : 1;
71  cost += value[i] * edges[i].cost;
72  }
73  s = 0;
74  }
75  MC_feas_sol(const double c,
76  const int nnodes, int*& s,
77  const int nedges, double*& v) :
78  cost(c), num_nodes(nnodes), sign(s), num_edges(nedges), value(v) {
79  s = 0;
80  v = 0;
81  }
83  delete[] value;
84  delete[] sign;
85  }
86 };
87 
88 class MC_problem {
89 public:
90  // This data relates to the regular graph
91  int num_nodes;
92  int num_edges;
93  // These arrays are constant arrays, better have them as real arrays
94  // instead of BCP_vec's
98 
100  // These data members are used only if an Ising problem is solved
103 
104  // the squares of the grid
106  // the triangles if there is an external magnetic point
108 
112 
113  // for testing we can read in a feas soln
115 
116 public:
118  num_nodes(0), num_edges(0), edges(0), nodes(0), all_adj_list(0),
119  ising_problem(false), sum_edge_weight(0.0), scaling_factor(1.0),
122  feas_sol(0)
123  {}
125  delete[] edges;
126  delete[] nodes;
127  delete[] all_adj_list;
128  delete[] ising_four_cycles;
129  delete[] ising_triangles;
130  for (int i = 0; i < num_structure_type; ++i) {
131  delete[] switch_structures[i];
132  }
133  delete[] switch_structures;
134  delete[] num_switch_structures;
135  delete feas_sol;
136  }
137 
138  void create_adj_lists();
139  BCP_buffer& pack(BCP_buffer& buf);
141 };
142 
143 //#############################################################################
144 
145 // A class to hold adjacency entries during shortest path computation
146 
148 public:
149  int neighbor;
151  double cost;
152  MC_path_adj_entry() : neighbor(-1), orig_edge(-1), cost(0.0) {}
153 };
154 
155 // A class to hold nodes during shortest path computation
156 
158 public:
159  bool processed;
160  int degree;
161  // the predecessor node in the shortest path tree
162  int parent;
163  // the edge (in the original edge list!) to the parent node
165  // distance from the root node
166  double distance;
168 
169  MC_path_node() : processed(false), degree(-1), parent(-1),
170  edge_to_parent(-1), distance(-1.0), adj_list(0) {}
171 };
172 
173 //#############################################################################
174 
176  inline bool operator() (const MC_path_node* node0,
177  const MC_path_node* node1) {
178  return node0->distance < node1->distance;
179  }
180 };
181 
182 #endif
int orig_edge
Definition: MC.hpp:150
MC_adjacency_entry * adj_list
Definition: MC.hpp:22
double cost
Definition: MC.hpp:31
~MC_problem()
Definition: MC.hpp:124
int num_edges
Definition: MC.hpp:92
int * num_switch_structures
Definition: MC.hpp:110
BCP_buffer & pack(BCP_buffer &buf)
void create_adj_lists()
int head
Definition: MC.hpp:30
int neighbor
Definition: MC.hpp:12
MC_path_adj_entry()
Definition: MC.hpp:152
bool operator()(const MC_path_node *node0, const MC_path_node *node1)
Definition: MC.hpp:176
MC_graph_node * nodes
Definition: MC.hpp:96
MC_switch_structure ** switch_structures
Definition: MC.hpp:111
int num_nodes
Definition: MC.hpp:91
int degree
Definition: MC.hpp:160
MC_graph_edge * edges
Definition: MC.hpp:95
MC_path_adj_entry * adj_list
Definition: MC.hpp:167
MC_adjacency_entry(int n, double c)
Definition: MC.hpp:16
int num_edges
Definition: MC.hpp:59
BCP_buffer & unpack(BCP_buffer &buf)
~MC_feas_sol()
Definition: MC.hpp:82
int neighbor
Definition: MC.hpp:149
int tail
Definition: MC.hpp:29
bool processed
Definition: MC.hpp:159
MC_graph_edge(int t, int h, double c)
Definition: MC.hpp:34
bool ising_problem
Definition: MC.hpp:99
double scaling_factor
Definition: MC.hpp:102
int degree
Definition: MC.hpp:21
int * neighbors
Definition: MC.hpp:45
MC_switch_structure()
Definition: MC.hpp:46
double cost
Definition: MC.hpp:56
MC_graph_node(int d, MC_adjacency_entry *l)
Definition: MC.hpp:24
MC_feas_sol(const double c, const int nnodes, int *&s, const int nedges, double *&v)
Definition: MC.hpp:75
MC_feas_sol(const int nnodes, int *&s, const int nedges, const MC_graph_edge *edges)
Definition: MC.hpp:61
double cost
Definition: MC.hpp:151
int edge_to_parent
Definition: MC.hpp:164
Definition: MC.hpp:147
int parent
Definition: MC.hpp:162
int * sign
Definition: MC.hpp:58
MC_problem()
Definition: MC.hpp:117
MC_feas_sol * feas_sol
Definition: MC.hpp:114
double distance
Definition: MC.hpp:166
Definition: MC.hpp:10
int num_neighbors
Definition: MC.hpp:43
int index
Definition: MC.hpp:13
This class describes the message buffer used for all processes of BCP.
Definition: BCP_buffer.hpp:39
int num_structure_type
Definition: MC.hpp:109
int * ising_four_cycles
Definition: MC.hpp:105
MC_graph_node()
Definition: MC.hpp:23
MC_graph_edge()
Definition: MC.hpp:33
~MC_switch_structure()
Definition: MC.hpp:48
int * ising_triangles
Definition: MC.hpp:107
MC_adjacency_entry * all_adj_list
Definition: MC.hpp:97
double sum_edge_weight
Definition: MC.hpp:101
MC_switch_structure & operator=(const MC_switch_structure &)
MC_adjacency_entry()
Definition: MC.hpp:15
double cost
Definition: MC.hpp:14
MC_path_node()
Definition: MC.hpp:169
double * value
Definition: MC.hpp:60
int num_nodes
Definition: MC.hpp:57