Analysis Software
Documentation for
sPHENIX
simulation software
Home page
Related Pages
Modules
Namespaces
Classes
Files
Examples
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
my_test.cc
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file my_test.cc
1
/* This software is distributed under the GNU Lesser General Public License */
2
//==========================================================================
3
//
4
// bellman_ford_test.cpp
5
//
6
//==========================================================================
7
// $Id: bellman_ford_test.cpp,v 1.2 2002/11/07 13:38:37 raitner Exp $
8
9
#include <iostream>
10
11
#include <
GTL/graph.h
>
12
#include <
GTL/bellman_ford.h
>
13
#include <
GTL/edge_map.h
>
14
#include <
GTL/node_map.h
>
15
16
#ifdef __GTL_MSVCC
17
# ifdef _DEBUG
18
# define new DEBUG_NEW
19
# undef THIS_FILE
20
static
char
THIS_FILE[] = __FILE__;
21
# endif // _DEBUG
22
#endif // __GTL_MSVCC
23
24
class
my_graph
:
public
graph
{
25
26
public
:
27
28
my_graph
() :
graph
() {}
29
30
node
new_vertex
(
int
x
) {
node
n
=
graph::new_node
();
X
[
n
]=
x
;
return
n
;}
31
void
new_parton
(
node
s
,
node
t
,
int
p
) {
edge
e
=
graph::new_edge
(s,t) ;
P
[
e
]=
p
;}
//; return e;}
32
33
void
save_node_info_handler
(ostream *o,
node
n
)
const
{ *o<<
"Value = "
<<
X
[
n
]<<endl;}
34
void
save_edge_info_handler
(ostream *o,
edge
n
)
const
{ *o<<
"Value = "
<<
P
[
n
]<<endl;}
35
36
int
GetNodeValue
(
node
n
)
const
{
return
X
[
n
];}
37
int
GetEdgeValue
(
edge
n
)
const
{
return
P
[
n
];}
38
39
private
:
40
41
node_map<int>
X
;
42
edge_map<int>
P
;
43
44
};
45
46
47
class
parton
{
48
49
public
:
50
51
parton
() {};
52
parton
(
double
mpt,
double
meta,
double
mphi,
double
me,
bool
mfinal) {
pt
=mpt;
eta
=meta;
phi
=mphi;
e
=me;
final
=mfinal;}
53
54
bool
isFinal
() {
return
final
;}
55
56
double
pt
,
eta
,
phi
,
e
;
57
bool
final
;
58
};
59
60
class
shower
:
public
graph
{
61
62
public
:
63
64
shower
() :
graph
() {}
65
66
node
new_vertex
(
int
x
) {
node
n
=
graph::new_node
();
XX
[
n
]=
x
;
return
n
;}
67
void
new_parton
(
node
s
,
node
t
,
parton
p
) {
edge
e
=
graph::new_edge
(s,t) ;
PP
[
e
]=
p
;}
//; return e;}
68
int
GetNodeValue
(
node
n
)
const
{
return
XX
[
n
];}
69
void
save_edge_info_handler
(ostream *o,
edge
n
)
const
{ *o<<
"Value = "
<<
PP
[
n
].pt<<endl;}
70
double
GetEdgeValue
(
edge
n
)
const
{
return
PP
[
n
].pt;}
71
72
private
:
73
74
node_map<int>
XX
;
75
edge_map<parton>
PP
;
76
77
};
78
79
int
main
(
int
argc,
char
* argv[])
80
{
81
graph
G
;
82
G.
make_directed
();
83
node
n1 = G.
new_node
();
84
node
n2 = G.
new_node
();
85
86
edge
e1 = G.
new_edge
(n1,n2);
87
88
89
node_map<int>
n
(G,1);
90
edge_map<int>
e
(G,10);
91
92
//edge_map<int> e1(n1,n2,10);
93
94
//G.save();
95
96
my_graph
S
;
97
98
node
n11=S.
new_vertex
(0);
99
node
n22=S.
new_vertex
(1);
100
node
n33=S.
new_vertex
(2);
101
node
n44=S.
new_vertex
(3);
102
node
n55=S.
new_vertex
(5);
103
104
//edge e11=S.new_parton(n11,n22,10);
105
S.
new_parton
(n11,n22,10);
106
S.
new_parton
(n11,n33,11);
107
S.
new_parton
(n33,n44,20);
108
S.
new_parton
(n33,n55,21);
109
110
//S.save();
111
112
graph::node_iterator
it
,
end
;
113
114
for
(it = S.
nodes_begin
(), end = S.
nodes_end
(); it !=
end
; ++
it
)
115
{
116
cout<<*it<<
" "
<<S.
GetNodeValue
((
node
) *it)<<endl;
117
}
118
119
graph::edge_iterator
it2, end2;
120
121
for
(it2 = S.
edges_begin
(), end2 = S.
edges_end
(); it2 != end2; ++it2)
122
{
123
cout<<*it2<<
" "
<<S.
GetEdgeValue
((
edge
) *it2)<<endl;
124
}
125
126
cout<<endl;
127
128
shower
gS;
129
130
node
nn11=gS.
new_vertex
(0);
131
node
nn22=gS.
new_vertex
(1);
132
node
nn33=gS.
new_vertex
(1);
133
node
nn44=gS.
new_vertex
(2);
134
node
nn55=gS.
new_vertex
(2);
135
136
parton
p
(100,0,0,100,
false
);
137
138
gS.
new_parton
(nn11,nn22,p);
139
gS.
new_parton
(nn11,nn33,
parton
(200,0,0,200,
false
));
140
gS.
new_parton
(nn33,nn44,
parton
(50,0,0,50,
true
));
141
gS.
new_parton
(nn33,nn55,
parton
(150,0,0,150,
true
));
142
143
shower::node_iterator
git
, gend;
144
145
for
(git = gS.
nodes_begin
(), gend = gS.
nodes_end
(); git != gend; ++
git
)
146
{
147
cout<<*git<<
" "
<<gS.
GetNodeValue
(*git)<<endl;
148
}
149
150
shower::edge_iterator
git2, gend2;
151
152
for
(git2 = gS.
edges_begin
(), gend2 = gS.
edges_end
(); git2 != gend2; ++git2)
153
{
154
cout<<*git2<<
" "
<<gS.
GetEdgeValue
(*git2)<<endl;
155
}
156
157
/*
158
node n1 = G.new_node();
159
node n2 = G.new_node();
160
node n3 = G.new_node();
161
node n4 = G.new_node();
162
node n5 = G.new_node();
163
node n6 = G.new_node();
164
165
edge e1_2 = G.new_edge(n1, n2);
166
edge e2_3 = G.new_edge(n2, n3);
167
edge e1_6 = G.new_edge(n1, n6);
168
edge e3_6 = G.new_edge(n3, n6);
169
edge e4_3 = G.new_edge(n4, n3);
170
edge e6_4 = G.new_edge(n6, n4);
171
edge e6_5 = G.new_edge(n6, n5);
172
edge e5_4 = G.new_edge(n5, n4);
173
edge e5_1 = G.new_edge(n5, n1);
174
175
edge_map<double> w(G);
176
w[e1_2] = 1;
177
w[e2_3] = 2;
178
w[e1_6] = 8;
179
w[e3_6] = 3;
180
w[e4_3] = 2;
181
w[e6_4] = 1;
182
w[e6_5] = 3;
183
w[e5_4] = 10;
184
w[e5_1] = 2;
185
186
node_map<double> result(G);
187
result[n1] = 0;
188
result[n2] = 1;
189
result[n3] = 3;
190
result[n4] = 7;
191
result[n5] = 9;
192
result[n6] = 6;
193
194
node_map<node> preds(G);
195
preds[n1] = node();
196
preds[n2] = n1;
197
preds[n3] = n2;
198
preds[n4] = n6;
199
preds[n5] = n6;
200
preds[n6] = n3;
201
202
bellman_ford B;
203
B.store_preds(true);
204
B.source(n1);
205
B.weights(w);
206
207
G.save("test.gml");
208
209
cout << "Bellman Ford with positive edge weights" << endl;
210
211
if (B.check(G) == algorithm::GTL_OK)
212
{
213
cout << "check OK" << endl;
214
}
215
else
216
{
217
cout << "check FAILED" << endl;
218
exit(1);
219
}
220
221
if (B.run(G) == algorithm::GTL_OK)
222
{
223
cout << "run OK" << endl;
224
}
225
else
226
{
227
cout << "run FAILED" << endl;
228
exit(1);
229
}
230
231
graph::node_iterator it, end;
232
233
for (it = G.nodes_begin(), end = G.nodes_end(); it != end; ++it)
234
{
235
if(result[*it] != B.distance(*it))
236
{
237
cout << "Distance for node " << *it << " FAILED" << endl;
238
exit(1);
239
}
240
}
241
242
cout << "Distances OK" << endl;
243
244
for (it = G.nodes_begin(), end = G.nodes_end(); it != end; ++it)
245
{
246
if(preds[*it] != B.predecessor_node(*it))
247
{
248
cout << "Predecessor for node " << *it << " FAILED" << endl;
249
exit(1);
250
}
251
}
252
253
cout << "Predecessors OK" << endl;
254
255
if (B.negative_cycle())
256
{
257
cout << "Negative Cycle FAILED" << endl;
258
}
259
else
260
{
261
cout << "Negative Cycle OK" << endl;
262
}
263
*/
264
}
JETSCAPE
blob
main
external_packages
gtl
tests
my_test.cc
Built by
Jin Huang
. updated:
Sat Feb 17 2024 22:18:23
using
1.8.2 with
sPHENIX GitHub integration