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 <memory>
0009 #include <list>
0010 #include <vector>
0011 #include "helper.h"
0012
0013 class vertex {
0014
0015 public:
0016 vertex() {};
0017 vertex(int myId) {id=myId;}
0018 virtual ~vertex() {cout<<" Vertex Detructor ..."<<endl;}
0019 int id;
0020 };
0021
0022 class parton {
0023
0024 public:
0025
0026 parton() {};
0027 parton (double mpt, double meta, double mphi, double me, bool mfinal) {pt=mpt;eta=meta;phi=mphi;e=me;final=mfinal;}
0028 virtual ~parton() {cout<<" Parton Destructor ..."<<endl;}
0029
0030 bool isFinal() {return final;}
0031
0032 double pt, eta, phi, e;
0033 bool final;
0034 };
0035
0036 class shower2 : public graph {
0037
0038 public:
0039
0040 shower2() : graph() {cout<<"Shower2 Constrcutor ..."<<endl;}
0041 virtual ~shower2() {cout<<"Shower2 Detrcutor ..."<<endl;}
0042
0043 node new_vertex(shared_ptr<vertex> v) {node n=graph::new_node();XX[n]=v; return n;}
0044
0045 void new_parton(node s, node t, unique_ptr<parton> p) {edge e=graph::new_edge(s,t);PP[e]=std::move(p);}
0046
0047
0048
0049
0050 void save_node_info_handler (ostream *o, node n) const { *o<<"MyID "<<XX[n]->id<<endl;}
0051 void save_edge_info_handler (ostream *o, edge n) const { *o<<"pT = "<<PP[n]->pt<<endl;}
0052
0053 void load_edge_info_handler (edge e, GML_pair *read) {
0054 cout<<"Load edge ... "<<e<<endl;
0055 struct GML_pair* tmp = read;
0056
0057 while (tmp) {
0058
0059
0060 if (((string) (tmp->key)).find("pT")<1)
0061 {
0062
0063 PP[e]=make_shared<parton>(tmp->value.floating,0,0,tmp->value.floating,false);
0064 }
0065
0066 tmp = tmp->next;
0067 }
0068 }
0069
0070
0071 void load_node_info_handler (node n, GML_pair *read) {
0072 cout<<"Load node ... "<<n<<endl;
0073
0074 struct GML_pair* tmp = read;
0075 int i;
0076 int level=2;
0077 int nC=0;
0078
0079 while (tmp) {
0080
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 if (((string) (tmp->key)).find("MyID")<1)
0117 {
0118
0119
0120 XX[n]=make_shared<vertex>(tmp->value.integer);
0121 }
0122
0123
0124
0125 tmp = tmp->next;
0126 }
0127 }
0128
0129 double GetEdgeValue(edge n) const {return PP[n]->pt;}
0130 int GetNodeValue(node n) const {return XX[n]->id;}
0131 bool GetFinal(edge e) const {return PP[e]->final;}
0132
0133
0134 void pre_clear_handler() {
0135 edge_iterator git3, gend3;
0136 for (git3 = edges_begin(), gend3 = edges_end(); git3 != gend3; ++git3)
0137 {
0138
0139 PP[*git3]=nullptr;
0140 }
0141 node_iterator git4, gend4;
0142 for (git4 = nodes_begin(), gend4 = nodes_end(); git4 != gend4; ++git4)
0143 {
0144 XX[*git4]=nullptr;
0145 }
0146 }
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166 vector<weak_ptr<parton>> GetPartons() {
0167 vector<weak_ptr<parton>> myv; list<edge> le=all_edges();
0168
0169
0170 int n=0;
0171
0172 for (list<edge>::iterator it=le.begin(); it!=le.end(); ++it)
0173 {
0174 if (PP[*it]->isFinal())
0175 myv.push_back(PP[*it]);
0176
0177 }
0178 return myv;
0179 }
0180
0181 private:
0182
0183 node_map<shared_ptr<vertex>> XX;
0184 edge_map<shared_ptr<parton>> PP;
0185
0186 };
0187
0188 int main (int argc, char* argv[])
0189 {
0190 cout << "Loading graph and preserving ids" << endl;
0191 auto mS=make_shared<shower2>();
0192
0193
0194
0195 if (mS->load("test.gml", true).err_num != GML_OK) {
0196 cout << "Loading failed" << endl;
0197
0198
0199 }
0200
0201
0202
0203
0204 dfs search;
0205 search.start_node();
0206 search.run(*mS);
0207 cout<< search.number_of_reached_nodes () <<endl;
0208
0209 dfs::dfs_iterator itt2, endt2;
0210 for (itt2 = search.begin(), endt2=search.end(); itt2 !=endt2; ++itt2)
0211 {
0212 cout<<*itt2<<" "<<mS->GetNodeValue(*itt2)<<endl;
0213 }
0214
0215 mS=0;
0216
0217 cout<<"Finished ..."<<endl;
0218 }
0219