File indexing completed on 2025-08-03 08:19:41
0001 #include <iostream>
0002
0003 #include <GTL/graph.h>
0004 #include <GTL/bellman_ford.h>
0005 #include <GTL/edge_map.h>
0006 #include <GTL/node_map.h>
0007 #include <GTL/dfs.h>
0008 #include <GTL/bfs.h>
0009 #include <memory>
0010 #include <list>
0011 #include <vector>
0012 #include "helper.h"
0013
0014 class vertex {
0015
0016 public:
0017 vertex() {};
0018 vertex(int myId) {id=myId;}
0019 virtual ~vertex() {cout<<" Vertex Detructor ..."<<endl;}
0020 int id;
0021 };
0022
0023 class parton {
0024
0025 public:
0026
0027 parton() {};
0028 parton (double mpt, double meta, double mphi, double me, bool mfinal) {pt=mpt;eta=meta;phi=mphi;e=me;final=mfinal;}
0029 virtual ~parton() {cout<<" Parton Destructor ..."<<endl;}
0030
0031 bool isFinal() {return final;}
0032
0033 double pt, eta, phi, e;
0034 bool final;
0035 };
0036
0037 class shower2 : public graph {
0038
0039 public:
0040
0041 shower2() : graph() {cout<<"Shower2 Constrcutor ..."<<endl;}
0042 virtual ~shower2() {cout<<"Shower2 Detrcutor ..."<<endl;}
0043
0044 node new_vertex(shared_ptr<vertex> v) {node n=graph::new_node();XX[n]=v; return n;}
0045
0046 void new_parton(node s, node t, unique_ptr<parton> p) {edge e=graph::new_edge(s,t);PP[e]=std::move(p);}
0047
0048
0049
0050
0051 void save_node_info_handler (ostream *o, node n) const { *o<<"MyID "<<XX[n]->id<<endl;}
0052 void save_edge_info_handler (ostream *o, edge n) const { *o<<"pT "<<PP[n]->pt<<endl;}
0053
0054 void load_edge_info_handler (edge e, GML_pair *read) {
0055 cout<<"Load edge ... "<<e<<endl;
0056 struct GML_pair* tmp = read;
0057
0058 while (tmp) {
0059
0060
0061 if (((string) (tmp->key)).find("pT")<1)
0062 {
0063
0064 PP[e]=make_shared<parton>(tmp->value.floating,0,0,tmp->value.floating,false);
0065 }
0066
0067 tmp = tmp->next;
0068 }
0069 }
0070
0071
0072 void load_node_info_handler (node n, GML_pair *read) {
0073 cout<<"Load node ... "<<n<<endl;
0074
0075 struct GML_pair* tmp = read;
0076 int i;
0077 int level=2;
0078 int nC=0;
0079
0080 while (tmp) {
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117 if (((string) (tmp->key)).find("MyID")<1)
0118 {
0119
0120
0121 XX[n]=make_shared<vertex>(tmp->value.integer);
0122 }
0123
0124
0125
0126 tmp = tmp->next;
0127 }
0128 }
0129
0130 double GetEdgeValue(edge n) const {return PP[n]->pt;}
0131 int GetNodeValue(node n) const {return XX[n]->id;}
0132 bool GetFinal(edge e) const {return PP[e]->final;}
0133
0134
0135 void pre_clear_handler() {
0136 edge_iterator git3, gend3;
0137 for (git3 = edges_begin(), gend3 = edges_end(); git3 != gend3; ++git3)
0138 {
0139
0140 PP[*git3]=nullptr;
0141 }
0142 node_iterator git4, gend4;
0143 for (git4 = nodes_begin(), gend4 = nodes_end(); git4 != gend4; ++git4)
0144 {
0145 XX[*git4]=nullptr;
0146 }
0147 }
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167 vector<weak_ptr<parton>> GetPartons() {
0168 vector<weak_ptr<parton>> myv; list<edge> le=all_edges();
0169
0170
0171 int n=0;
0172
0173 for (list<edge>::iterator it=le.begin(); it!=le.end(); ++it)
0174 {
0175 if (PP[*it]->isFinal())
0176 myv.push_back(PP[*it]);
0177
0178 }
0179 return myv;
0180 }
0181
0182 private:
0183
0184 node_map<shared_ptr<vertex>> XX;
0185 edge_map<shared_ptr<parton>> PP;
0186
0187 };
0188
0189 int main (int argc, char* argv[])
0190 {
0191 auto mS=make_shared<shower2>();
0192 mS->make_directed();
0193
0194 node nnn11=mS->new_vertex(make_shared<vertex>(0));
0195
0196 node nnn22=mS->new_vertex(make_shared<vertex>(1));
0197 node nnn33=mS->new_vertex(make_shared<vertex>(1));
0198 node nnn44=mS->new_vertex(make_shared<vertex>(2));
0199 node nnn55=mS->new_vertex(make_shared<vertex>(2));
0200 node nnn66=mS->new_vertex(make_shared<vertex>(3));
0201 node nnn77=mS->new_vertex(make_shared<vertex>(3));
0202 node nnn88=mS->new_vertex(make_shared<vertex>(4));
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216 mS->new_parton(nnn11,nnn22,unique_ptr<parton>(new parton(100,0,0,100,false)));
0217 mS->new_parton(nnn11,nnn33,unique_ptr<parton>(new parton(200,0,0,200,false)));
0218 mS->new_parton(nnn33,nnn44,unique_ptr<parton>(new parton(50,0,0,50,true)));
0219 mS->new_parton(nnn33,nnn55,unique_ptr<parton>(new parton(150,0,0,150,false)));
0220 mS->new_parton(nnn55,nnn66,unique_ptr<parton>(new parton(80,0,0,80,true)));
0221 mS->new_parton(nnn55,nnn77,unique_ptr<parton>(new parton(70,0,0,70,false)));
0222 mS->new_parton(nnn77,nnn88,unique_ptr<parton>(new parton(60,0,0,60,true)));
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240 shower2::node_iterator git0, gend0;
0241
0242 for (git0 = mS->nodes_begin(), gend0 = mS->nodes_end(); git0 != gend0; ++git0)
0243 {
0244 cout<<*git0<<" "<<mS->GetNodeValue(*git0)<<" "<<git0->indeg()<<" "<<git0->outdeg()<<endl;
0245 }
0246
0247 shower2::edge_iterator git3, gend3;
0248
0249 for (git3 = mS->edges_begin(), gend3 = mS->edges_end(); git3 != gend3; ++git3)
0250 {
0251 cout<<*git3<<" "<<mS->GetEdgeValue(*git3)<<" "<<mS->GetFinal(*git3)<<endl;
0252 }
0253
0254 list<node> ln=mS->all_nodes();
0255 cout<<ln.size()<<endl;
0256
0257 list<edge> le=mS->all_edges();
0258 cout<<le.size()<<endl;
0259
0260
0261 dfs search;
0262 search.start_node(nnn11);
0263 search.run(*mS);
0264 cout<< search.number_of_reached_nodes () <<endl;
0265
0266 dfs::dfs_iterator itt2, endt2;
0267 for (itt2 = search.begin(), endt2=search.end(); itt2 !=endt2; ++itt2)
0268 {
0269 cout<<*itt2<<endl;
0270 }
0271
0272 dfs::tree_edges_iterator itt, endt;
0273 for (itt = search.tree_edges_begin(), endt=search.tree_edges_end(); itt !=endt; ++itt)
0274 {
0275 cout<<*itt<<endl;
0276 }
0277
0278 bfs search2;
0279 search2.start_node(nnn11);
0280 search2.run(*mS);
0281 cout<< search2.number_of_reached_nodes () <<endl;
0282
0283 bfs::bfs_iterator itt22, endt22;
0284 for (itt22 = search2.begin(), endt22=search2.end(); itt22 !=endt22; ++itt22)
0285 {
0286 cout<<*itt22<<endl;
0287 }
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299 vector<weak_ptr<parton>> myv=mS->GetPartons();
0300 cout<<myv.size()<<endl;
0301
0302 for (const auto& v : myv)
0303 cout<<v.lock()->pt<<endl;
0304
0305
0306
0307 mS->save("test.gml");
0308
0309 mS->clear();
0310 cout<<" mS->clear()"<<endl;
0311
0312
0313 mS=0;
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329 }
0330
0331
0332
0333
0334
0335
0336
0337
0338
0339
0340
0341
0342
0343
0344
0345
0346
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378
0379
0380
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400
0401
0402