Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
tmp
OS-2.10.2
Bcp
examples
MaxCut
include
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
10
class
MC_adjacency_entry
{
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
19
class
MC_graph_node
{
20
public
:
21
int
degree
;
22
MC_adjacency_entry
*
adj_list
;
23
MC_graph_node
() :
degree
(-1),
adj_list
(0) {}
24
MC_graph_node
(
int
d,
MC_adjacency_entry
* l) :
degree
(d),
adj_list
(l) {}
25
};
26
27
class
MC_graph_edge
{
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
37
class
MC_switch_structure
{
38
private
:
39
MC_switch_structure
(
const
MC_switch_structure
&);
40
MC_switch_structure
&
operator=
(
const
MC_switch_structure
&);
41
public
:
42
int
num_nodes
;
43
int
num_neighbors
;
44
int
*
nodes
;
45
int
*
neighbors
;
46
MC_switch_structure
() :
47
num_nodes
(0),
num_neighbors
(0),
nodes
(0),
neighbors
(0) {}
48
~MC_switch_structure
() {
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
}
82
~MC_feas_sol
() {
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
95
MC_graph_edge
*
edges
;
96
MC_graph_node
*
nodes
;
97
MC_adjacency_entry
*
all_adj_list
;
98
99
bool
ising_problem
;
100
// These data members are used only if an Ising problem is solved
101
double
sum_edge_weight
;
102
double
scaling_factor
;
103
104
// the squares of the grid
105
int
*
ising_four_cycles
;
106
// the triangles if there is an external magnetic point
107
int
*
ising_triangles
;
108
109
int
num_structure_type
;
110
int
*
num_switch_structures
;
111
MC_switch_structure
**
switch_structures
;
112
113
// for testing we can read in a feas soln
114
MC_feas_sol
*
feas_sol
;
115
116
public
:
117
MC_problem
() :
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),
120
ising_four_cycles
(0),
ising_triangles
(0),
121
num_structure_type
(0),
num_switch_structures
(0),
switch_structures
(0),
122
feas_sol
(0)
123
{}
124
~MC_problem
() {
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);
140
BCP_buffer
&
unpack
(
BCP_buffer
& buf);
141
};
142
143
//#############################################################################
144
145
// A class to hold adjacency entries during shortest path computation
146
147
class
MC_path_adj_entry
{
148
public
:
149
int
neighbor
;
150
int
orig_edge
;
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
157
class
MC_path_node
{
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
164
int
edge_to_parent
;
165
// distance from the root node
166
double
distance
;
167
MC_path_adj_entry
*
adj_list
;
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
175
struct
MC_path_node_ptr_compare
{
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
MC_path_adj_entry::orig_edge
int orig_edge
Definition:
MC.hpp:150
BCP_vector.hpp
MC_problem::ising_four_cycles
int * ising_four_cycles
Definition:
MC.hpp:105
MC_graph_edge::cost
double cost
Definition:
MC.hpp:31
MC_switch_structure
Definition:
MC.hpp:37
MC_problem::~MC_problem
~MC_problem()
Definition:
MC.hpp:124
MC_path_node
Definition:
MC.hpp:157
MC_problem::num_edges
int num_edges
Definition:
MC.hpp:92
MC_problem::create_adj_lists
void create_adj_lists()
Definition:
MC.cpp:115
MC_graph_edge::head
int head
Definition:
MC.hpp:30
MC_adjacency_entry::neighbor
int neighbor
Definition:
MC.hpp:12
MC_path_adj_entry::MC_path_adj_entry
MC_path_adj_entry()
Definition:
MC.hpp:152
MC_path_node_ptr_compare::operator()
bool operator()(const MC_path_node *node0, const MC_path_node *node1)
Definition:
MC.hpp:176
MC_problem::num_nodes
int num_nodes
Definition:
MC.hpp:91
MC_path_node::degree
int degree
Definition:
MC.hpp:160
MC_problem::edges
MC_graph_edge * edges
Definition:
MC.hpp:95
MC_switch_structure::nodes
int * nodes
Definition:
MC.hpp:44
MC_problem::all_adj_list
MC_adjacency_entry * all_adj_list
Definition:
MC.hpp:97
MC_feas_sol::sign
int * sign
Definition:
MC.hpp:58
MC_adjacency_entry::MC_adjacency_entry
MC_adjacency_entry(int n, double c)
Definition:
MC.hpp:16
MC_problem::unpack
BCP_buffer & unpack(BCP_buffer &buf)
Definition:
MC.cpp:58
MC_problem::ising_triangles
int * ising_triangles
Definition:
MC.hpp:107
MC_feas_sol::num_edges
int num_edges
Definition:
MC.hpp:59
MC_feas_sol::~MC_feas_sol
~MC_feas_sol()
Definition:
MC.hpp:82
MC_path_adj_entry::neighbor
int neighbor
Definition:
MC.hpp:149
MC_graph_edge::tail
int tail
Definition:
MC.hpp:29
MC_path_node::processed
bool processed
Definition:
MC.hpp:159
MC_graph_edge::MC_graph_edge
MC_graph_edge(int t, int h, double c)
Definition:
MC.hpp:34
MC_problem::switch_structures
MC_switch_structure ** switch_structures
Definition:
MC.hpp:111
MC_problem::ising_problem
bool ising_problem
Definition:
MC.hpp:99
MC_problem::scaling_factor
double scaling_factor
Definition:
MC.hpp:102
MC_graph_node::degree
int degree
Definition:
MC.hpp:21
MC_path_node_ptr_compare
Definition:
MC.hpp:175
MC_switch_structure::MC_switch_structure
MC_switch_structure()
Definition:
MC.hpp:46
MC_feas_sol::cost
double cost
Definition:
MC.hpp:56
MC_problem::nodes
MC_graph_node * nodes
Definition:
MC.hpp:96
MC_graph_node::MC_graph_node
MC_graph_node(int d, MC_adjacency_entry *l)
Definition:
MC.hpp:24
MC_problem
Definition:
MC.hpp:88
MC_feas_sol::MC_feas_sol
MC_feas_sol(const double c, const int nnodes, int *&s, const int nedges, double *&v)
Definition:
MC.hpp:75
MC_feas_sol::value
double * value
Definition:
MC.hpp:60
MC_problem::feas_sol
MC_feas_sol * feas_sol
Definition:
MC.hpp:114
s
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real * s
Definition:
BonFilterSolver.cpp:29
MC_feas_sol::MC_feas_sol
MC_feas_sol(const int nnodes, int *&s, const int nedges, const MC_graph_edge *edges)
Definition:
MC.hpp:61
MC_path_adj_entry::cost
double cost
Definition:
MC.hpp:151
MC_path_node::edge_to_parent
int edge_to_parent
Definition:
MC.hpp:164
MC_path_adj_entry
Definition:
MC.hpp:147
MC_path_node::parent
int parent
Definition:
MC.hpp:162
MC_problem::MC_problem
MC_problem()
Definition:
MC.hpp:117
MC_feas_sol
Definition:
MC.hpp:54
MC_path_node::distance
double distance
Definition:
MC.hpp:166
MC_adjacency_entry
Definition:
MC.hpp:10
MC_graph_node
Definition:
MC.hpp:19
MC_switch_structure::num_neighbors
int num_neighbors
Definition:
MC.hpp:43
MC_adjacency_entry::index
int index
Definition:
MC.hpp:13
BCP_buffer
This class describes the message buffer used for all processes of BCP.
Definition:
BCP_buffer.hpp:39
MC_problem::num_structure_type
int num_structure_type
Definition:
MC.hpp:109
MC_graph_node::MC_graph_node
MC_graph_node()
Definition:
MC.hpp:23
MC_graph_node::adj_list
MC_adjacency_entry * adj_list
Definition:
MC.hpp:22
MC_graph_edge::MC_graph_edge
MC_graph_edge()
Definition:
MC.hpp:33
MC_switch_structure::~MC_switch_structure
~MC_switch_structure()
Definition:
MC.hpp:48
MC_problem::num_switch_structures
int * num_switch_structures
Definition:
MC.hpp:110
MC_path_node::adj_list
MC_path_adj_entry * adj_list
Definition:
MC.hpp:167
MC_problem::sum_edge_weight
double sum_edge_weight
Definition:
MC.hpp:101
MC_switch_structure::operator=
MC_switch_structure & operator=(const MC_switch_structure &)
t
static char * t
Definition:
OSdtoa.cpp:3645
n
void fint * n
Definition:
BonFilterSolver.cpp:96
MC_switch_structure::num_nodes
int num_nodes
Definition:
MC.hpp:42
MC_adjacency_entry::MC_adjacency_entry
MC_adjacency_entry()
Definition:
MC.hpp:15
MC_adjacency_entry::cost
double cost
Definition:
MC.hpp:14
c
real c
Definition:
BonBqpdSolver.cpp:98
MC_graph_edge
Definition:
MC.hpp:27
MC_path_node::MC_path_node
MC_path_node()
Definition:
MC.hpp:169
MC_problem::pack
BCP_buffer & pack(BCP_buffer &buf)
Definition:
MC.cpp:10
MC_switch_structure::neighbors
int * neighbors
Definition:
MC.hpp:45
MC_feas_sol::num_nodes
int num_nodes
Definition:
MC.hpp:57
Generated by
1.8.5