# HG changeset patch # User athos # Date 1080313158 0 # Node ID 81a3d0abe5f3deaa57178853df508408c318554d # Parent 0b0bdf24d00cdca4d10bc1a5c00890337f0f2b22 Hozz?adtam p?r dolgot, miel?tt ?tt?r?nk az svn-re. diff -r 0b0bdf24d00c -r 81a3d0abe5f3 src/work/athos/dijkstra_at.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/work/athos/dijkstra_at.h Fri Mar 26 14:59:18 2004 +0000 @@ -0,0 +1,123 @@ +/* +Egy pontból összes többibe vezető legrövidebb utak irányított gráfban + +Preconditions: +A gráf típus tud: +- pontból kimenő éleket sorban visszaadni +A T számtípus, ami tud összehasonlítást, összedást +A bemenetre: +weight nemnegatív + +*/ +#ifndef DIJKSTRA_AT_H +#define DIJKSTRA_AT_H + + + +//#include +//#include +//#include +//#include "pf_hiba.hh" +//#include +//#include + + +using namespace std; + +namespace hugo { + + template + class dijkstra_at { + + //Hasznos typedef-ek + typedef typename graph_type::NodeIt NodeIt; + typedef typename graph_type::EdgeIt EdgeIt; + typedef typename graph_type::EachNodeIt EachNodeIt; + typedef typename graph_type::EachEdgeIt EachEdgeIt; + typedef typename graph_type::OutEdgeIt OutEdgeIt; + typedef typename graph_type::InEdgeIt InEdgeIt; + typedef typename graph_type::SymEdgeIt SymEdgeIt; + + + + //--------------------------------------------- + //Parameters of the algorithm + //--------------------------------------------- + + //--------------------------------------------- + //Parameters of the algorithm + //--------------------------------------------- + + private: + //input + graph_type& G; + NodeIt s; + typename graph_type::EdgeMap &weight; + //typename graph_type::EdgeMap &capacity; + //output + //typename graph_type::EdgeMap + // typename graph_type::EdgeMap preflow; + + //auxiliary variables for computation + deque next_to_reach; + + + typename graph_type::NodeMap reached; + + //Variables holding output + //Predessors in the shortest paths arborescence + typename graph_type::NodeMap pred; + + + public: + + + dijkstra_at( + graph_type& _G, + NodeIt _s, + typename graph_type::EdgeMap & _weight) + : G(_G), s(_s), + weight(_weight), + next_to_reach(), + reached(_G), + pred(G) + + { + } + /*By Misi.*/ + struct Node_dist_comp + { + NodeMap &d; + Node_dist_comp(NodeMap &_d) : d(_d) {} + + bool operator()(const NodeIt& u, const NodeIt& v) const + { return d.get(u) < d.get(v); } + }; + + + + void run() { + + NodeMap scanned(G, false); + std::priority_queue, Node_dist_comp> + heap(( Node_dist_comp(distance) )); + + heap.push(s); + reached.set(s, true); + + } + + + }; + + + + + + + }; //class dijkstra_at + + +}//namespace hugo + +#endif //DIJKSTRA_AT diff -r 0b0bdf24d00c -r 81a3d0abe5f3 src/work/athos/dijkstra_demo.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/work/athos/dijkstra_demo.cc Fri Mar 26 14:59:18 2004 +0000 @@ -0,0 +1,160 @@ +#include +#include + +#include "list_graph.hh" +//#include "marci_property_vector.hh" +#include + +using namespace hugo; + + +int main (int, char*[]) +{ + + + typedef ListGraph::NodeIt NodeIt; + typedef ListGraph::EdgeIt EdgeIt; + /* + typedef ListGraph::EachNodeIt EachNodeIt; + typedef ListGraph::EachEdgeIt EachEdgeIt; + typedef ListGraph::OutEdgeIt OutEdgeIt; + typedef ListGraph::InEdgeIt InEdgeIt; + typedef ListGraph::SymEdgeIt SymEdgeIt; + */ + ListGraph flowG; + + /* + //Marci példája + + + NodeIt s=flowG.addNode(); + NodeIt v1=flowG.addNode(); + NodeIt v2=flowG.addNode(); + NodeIt v3=flowG.addNode(); + NodeIt v4=flowG.addNode(); + NodeIt t=flowG.addNode(); + + + EdgeIt s_v1=flowG.addEdge(s, v1); + EdgeIt s_v2=flowG.addEdge(s, v2); + EdgeIt v1_v2=flowG.addEdge(v1, v2); + EdgeIt v2_v1=flowG.addEdge(v2, v1); + EdgeIt v1_v3=flowG.addEdge(v1, v3); + EdgeIt v3_v2=flowG.addEdge(v3, v2); + EdgeIt v2_v4=flowG.addEdge(v2, v4); + EdgeIt v4_v3=flowG.addEdge(v4, v3); + EdgeIt v3_t=flowG.addEdge(v3, t); + EdgeIt v4_t=flowG.addEdge(v4, t); + + ListGraph::EdgeMap cap(flowG); + + cap.set(s_v1, 16); + cap.set(s_v2, 13); + cap.set(v1_v2, 10); + cap.set(v2_v1, 4); + cap.set(v1_v3, 12); + cap.set(v3_v2, 9); + cap.set(v2_v4, 14); + cap.set(v4_v3, 7); + cap.set(v3_t, 20); + cap.set(v4_t, 4); + */ + + + //Ahuja könyv példája + + NodeIt s=flowG.addNode(); + NodeIt v2=flowG.addNode(); + NodeIt v3=flowG.addNode(); + NodeIt v4=flowG.addNode(); + NodeIt v5=flowG.addNode(); + NodeIt t=flowG.addNode(); + + EdgeIt s_v2=flowG.addEdge(s, v2); + EdgeIt s_v3=flowG.addEdge(s, v3); + EdgeIt v2_v4=flowG.addEdge(v2, v4); + EdgeIt v2_v5=flowG.addEdge(v2, v5); + EdgeIt v3_v5=flowG.addEdge(v3, v5); + EdgeIt v4_t=flowG.addEdge(v4, t); + EdgeIt v5_t=flowG.addEdge(v5, t); + + //Kis modositas + //edge_iterator v2_s=flowG.add_edge(v2, s); + + ListGraph::EdgeMap cap(flowG); + + cap.set(s_v2, 10); + cap.set(s_v3, 10); + cap.set(v2_v4, 5); + cap.set(v2_v5, 8); + cap.set(v3_v5, 5); + cap.set(v4_t, 8); + cap.set(v5_t, 8); + + //Kis modositas + //cap.put(v2_s, 100); + + + + + /*Egyszerű példa + NodeIt s=flow_test.add_node(); + NodeIt v1=flow_test.add_node(); + NodeIt v2=flow_test.add_node(); + NodeIt t=flow_test.add_node(); + + node_property_vector node_name(flow_test); + node_name.put(s, "s"); + node_name.put(v1, "v1"); + node_name.put(v2, "v2"); + node_name.put(t, "t"); + + edge_iterator s_v1=flow_test.add_edge(s, v1); + edge_iterator v1_v2=flow_test.add_edge(v1, v2); + edge_iterator v2_t=flow_test.add_edge(v2, t); + + edge_property_vector cap(flow_test); + + cap.put(s_v1, 16); + cap.put(v1_v2, 10); + cap.put(v2_t, 4); + */ + + std::cout << "preflow-push algorithm test..." << std::endl; + + /* + std::cout << "on directed graph graph" << std::endl; //<< flow_test; + std::cout << "names and capacity values" << std::endl; + for(EachNodeIt i=flow_test.first_node(); i.valid(); ++i) { + std::cout << node_name.get(i) << ": "; + std::cout << "out edges: "; + for(out_edge_iterator j=flow_test.first_out_edge(i); j.valid(); ++j) + std::cout << node_name.get(flow_test.tail(j)) << "-"<< cap.get(j) << "->" << node_name.get(flow_test.head(j)) << " "; + std::cout << "in edges: "; + for(in_edge_iterator j=flow_test.first_in_edge(i); j.valid(); ++j) + std::cout << node_name.get(flow_test.tail(j)) << "-"<< cap.get(j) << "->" << node_name.get(flow_test.head(j)) << " "; + std::cout << std::endl; + } + */ + + //for(each_NodeIt i=flow_test.first_node(); i.valid(); ++i) { + // std::cout << i << " "; + //} + + dijkstra_at dijkstra_test(flowG, s, cap); + //cout << preflow_push_test.run()< + +namespace hugo { + + template + class Kruskal { + + + //Hasznos typedef-ek + typedef typename graph_type::NodeIt NodeIt; + typedef typename graph_type::EdgeIt EdgeIt; + typedef typename graph_type::EachNodeIt EachNodeIt; + typedef typename graph_type::EachEdgeIt EachEdgeIt; + typedef typename graph_type::SymEdgeIt SymEdgeIt; + + //input + graph_type& G; + typename graph_type::EdgeMap &weight; + + //Auxilliary variables + typename graph_type::NodeMap component(flowG); + + Kruskal( + graph_type& _G, + typename graph_type::EdgeMap & _weight) + : G(_G), + weight(_weight), + component(-1) + { + } + + /*Originally by Misi.*/ + struct Edge_comp + { + NodeMap &d; + Node_dist_comp(NodeMap &_d) : d(_d) {} + + bool operator()(const NodeIt& u, const NodeIt& v) const + { return d.get(u) < d.get(v); } + }; + + + //Runs the algorithm + void run() { + + + + } + + } + +}//namespacc hugo + +#endif diff -r 0b0bdf24d00c -r 81a3d0abe5f3 src/work/athos/uf_demo.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/work/athos/uf_demo.cc Fri Mar 26 14:59:18 2004 +0000 @@ -0,0 +1,48 @@ +//This is just a simple example program to test my union-find structure + +//#include +#include +#include +#include +using namespace hugo; +using namespace std; + +int main (int, char*[]) +{ + typedef ListGraph::NodeIt NodeIt; + typedef ListGraph::EachNodeIt EachNodeIt; + typedef ListGraph::EdgeIt EdgeIt; + + ListGraph flowG; + + + //Marci példája + + + + NodeIt s=flowG.addNode(); + NodeIt v1=flowG.addNode(); + NodeIt v2=flowG.addNode(); + NodeIt v3=flowG.addNode(); + NodeIt v4=flowG.addNode(); + NodeIt t=flowG.addNode(); + + ListGraph::NodeMap component(flowG); + + component.set(s, -1); + component.set(v1, -1); + component.set(v2, -1); + component.set(v3, -1); + component.set(v4, -1); + component.set(t, -1); + + UnionFind< NodeIt, ListGraph::NodeMap > uf(component); + cout<<"Merge s and v1: "<(); i.valid(); ++i) { + + cout<<"Az "< +//#include + + +namespace hugo { + + template + class UnionFind { + KeyIntMap& pointmap; + struct VectorElementType { + int boss; + int count; + VectorElementType(int _boss, int _count){ + boss = _boss; + count = _count; + } + }; + std::vector container; + public: + + UnionFind(KeyIntMap& _pointmap): pointmap(_pointmap){ + + } + + //Give a component of one point to the structure + int addPoint(KeyType u){ + int _index = container.size(); + VectorElementType buf(_index,1); + container.push_back(buf); + return _index; + } + + + //Finds the big boss of u + int find(KeyType u){ + if (pointmap.get(u)==-1){ + int whoami = addPoint(u); + pointmap.set(u, whoami); + return whoami; + } + else{ + int emp = pointmap.get(u); + int boss = container[emp].boss; + while(emp != boss){ + emp = boss; + boss = container[emp].boss; + } + return boss; + } + } + + //Finds u and v in the structures and merges the comopnents, if not equal + bool findAndMerge(KeyType u,KeyType v){ + int bu = find(u); + int bv = find(v); + if (bu != bv){ + unio(bu,bv); + return true; + } + else{ + return false; + } + } + + //Merges a into b + void mergeInto(int a, int b){ + container[a].boss = b; + container[b].count += container[a].count; + } + + //Makes the union + void unio(int b1, int b2){ + if (container[b1].count>container[b2].count){ + mergeInto(b2,b1); + } + else{ + mergeInto(b1,b2); + } + }//unio + }; + +}//namespace hugo +#endif