11 typedef Graph<NodeData,EdgeData> TestGraph;
18 bfs_node_data<TestGraph> bfs;
27 typedef Graph<NodeData,EdgeData> TestGraph;
31 bool Get(isVis_map p,TestGraph::NodeIterator i) { return i->isVis;}
32 void Set(isVis_map p,TestGraph::NodeIterator i,bool b) { i->isVis=b;}
38 //isVis_map visited; //node->bool (RW)
39 class_element_map<TestGraph::NodeIterator,
42 &NodeData::isVis> visited;
44 typedef TestGraph::EdgeIterator value_type;
45 void Set(const TestGraph::NodeIterator &n,const value_type &t)
47 cout << t.From()->id << "->" << t.To()->id << '\n';
50 do_nothing_map dist; //node->int (W)
51 do_nothing_map priority; //node->int (W)
52 //priority_map priority; //node->int (W)
62 // struct NodeType {bfs_node_data<TestGraph> bfs;};
63 struct NodeType {bool isVis;};
65 vector<NodeType> nodes;
72 NodeIterator &operator ++() { n++; return *this;}
73 NodeType &operator *() const { return G->nodes[n];}
74 NodeType *operator ->() const { return &(G->nodes[n]);}
75 bool isValid() const {return n<=5000;}
76 int Index() {return n;} //csak a kiirashoz kell
79 void GetFirst(NodeIterator &i) {i.G=this;i.n=1;}
86 int gcd() { int a=f;int b=t;int c;while(c=a%b) {a=b;b=c;} ; return b;}
87 OutEdgeIterator &operator ++() {while(++t<=5000&&gcd()==1);return *this;}
88 bool isValid() const {return t<=5000;}
89 NodeIterator From() const {NodeIterator i; i.G=G;i.n=f;return i;}
90 NodeIterator To() const {NodeIterator i; i.G=G;i.n=t;return i;}
91 NodeIterator Anode() const {return From();}
92 NodeIterator Bnode() const {return To();}
95 typedef OutEdgeIterator EdgeIterator;
96 void GetFirst(OutEdgeIterator &i,const NodeIterator &n)
97 {i.G=this;i.f=n.n;i.t=0;++i;}
99 IGraph() : nodes(5000) {}
105 // class_element_map<IGraph::NodeIterator,
108 // &IGraph::NodeType::isVis> visited;
109 struct _visited_map_t {
110 typedef bool value_type;
111 void Set(const IGraph::NodeIterator &n,const value_type &t) { n->isVis=t; }
112 value_type Get(const IGraph::NodeIterator &n) const { return n->isVis; }
115 typedef IGraph::EdgeIterator value_type;
116 void Set(const IGraph::NodeIterator &n,const value_type &t)
117 { cout << t.From().Index() << "->" << t.To().Index() << '\n'; }
119 do_nothing_map dist; //node->int (W)
120 do_nothing_map priority; //node->int (W)
126 TestGraph::NodeIterator n,m,o,p,q;
127 TestGraph::OutEdgeIterator e,f,g,h;
131 //for(i=1;i<=10;i++) G.AddNode().n=i; //Ez nagyon rossz!!!!!!!!
132 for(i=1;i<=10;i++) G.AddNode()->id=i; //Ez a jo!!!!!!!!
136 //for(i=1;i<=10;i++) cout << (G.AddNode()->n=i) << ' ';
140 for(G.GetFirst(n);n.isValid();n++)
141 for(G.GetFirst(m);m.isValid();++m)
142 if(n!=m) G.AddEdge(n,m)->id=++i;
144 cout << "Number of edges: " << i << "\n\n";
146 TestGraph::AllEdgeIterator a;
147 for(G.GetFirst(a);a.isValid();++a)
148 cout << a->id << ":" << a.From()->id << "->" << a.To()->id << " ";
152 for(G.GetFirst(n);n.isValid();++n)
154 cout << n->id << "->";
155 for(G.GetFirst(e,n);e.isValid();++e)
156 cout << e->id << ":" << e.To()->id << ' ';
160 cout << "\n\n\n\nB-verzio:\n\n\n";
164 for(i=1;i<=10;i++) G.AddNode()->id=i;
167 for(n=G.First();n.isValid();n++)
168 for(m=G.First();m.isValid();++m)
169 if(n!=m) G.AddEdge(n,m)->id=++i;
172 for(n=G.First();n.isValid();++n)
176 if((e->id)%2) G.Delete(e++);
180 // cout << "Number of edges: " << i << "\n\n";
182 for(a=G.First();a.isValid();++a)
183 cout << a->id << ": " << a.From()->id << "->" << a.To()->id << " ";
187 for(n=G.First();n.isValid();++n)
189 cout << n->id << "->";
190 for(e=G.First(n);e.isValid();++e)
191 cout << e->id << ":" << e.To()->id << ' ';
200 cout << "\n\n\n BFS \n\n\n";
202 // bfs_static_maps<TestGraph> Maps(&NodeData::bfs);
211 IGraph::NodeIterator in;