# HG changeset patch # User marci # Date 1082995726 0 # Node ID 69e961722628682b4b2f00a03431c43d5c353984 # Parent 32a2a16027e03ed1672091972873473ff838fb8b comparison with leda algorithms, wrapper for leda graphs diff -r 32a2a16027e0 -r 69e961722628 src/work/marci/bipartite_matching_leda.cc --- a/src/work/marci/bipartite_matching_leda.cc Mon Apr 26 16:02:09 2004 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,219 +0,0 @@ -// -*- c++ -*- -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -//#include -//#include -#include -#include -//#include -#include -#include -#include -#include - -/** - * Inicializalja a veletlenszamgeneratort. - * Figyelem, ez nem jo igazi random szamokhoz, - * erre ne bizzad a titkaidat! - */ -void random_init() -{ - unsigned int seed = getpid(); - seed |= seed << 15; - seed ^= time(0); - - srand(seed); -} - -/** - * Egy veletlen int-et ad vissza 0 es m-1 kozott. - */ -int random(int m) -{ - return int( double(m) * rand() / (RAND_MAX + 1.0) ); -} - -using namespace hugo; - -int main() { - //for leda graph - leda::graph lg; - //lg.make_undirected(); - typedef LedaGraphWrapper Graph; - Graph g(lg); - - //for UndirListGraph - //typedef UndirListGraph Graph; - //Graph g; - - typedef Graph::Node Node; - typedef Graph::NodeIt NodeIt; - typedef Graph::Edge Edge; - typedef Graph::EdgeIt EdgeIt; - typedef Graph::OutEdgeIt OutEdgeIt; - - std::vector s_nodes; - std::vector t_nodes; - - int a; - std::cout << "number of nodes in the first color class="; - std::cin >> a; - int b; - std::cout << "number of nodes in the second color class="; - std::cin >> b; - int m; - std::cout << "number of edges="; - std::cin >> m; - - - for (int i=0; i ref_map(g, -1); - - IterableBoolMap< Graph::NodeMap > bipartite_map(ref_map); - for (int i=0; i BGW; - BGW bgw(g, bipartite_map); - -// std::cout << "Nodes by NodeIt:\n"; -// FOR_EACH_LOC(BGW::NodeIt, n, bgw) { -// std::cout << n << " "; -// } -// std::cout << "\n"; -// std::cout << "Nodes in S by ClassNodeIt:\n"; -// FOR_EACH_INC_LOC(BGW::ClassNodeIt, n, bgw, bgw.S_CLASS) { -// std::cout << n << " "; -// } -// std::cout << "\n"; -// std::cout << "Nodes in T by ClassNodeIt:\n"; -// FOR_EACH_INC_LOC(BGW::ClassNodeIt, n, bgw, bgw.T_CLASS) { -// std::cout << n << " "; -// } -// std::cout << "\n"; -// std::cout << "Edges of the bipartite graph:\n"; -// FOR_EACH_LOC(BGW::EdgeIt, e, bgw) { -// std::cout << bgw.tail(e) << "->" << bgw.head(e) << std::endl; -// } - - BGW::NodeMap dbyj(bgw); - BGW::EdgeMap dbyxcj(bgw); - - typedef stGraphWrapper stGW; - stGW stgw(bgw); - ConstMap const1map(1); -// stGW::NodeMap ize(stgw); - -// BfsIterator< BGW, BGW::NodeMap > bfs(bgw); -// Graph::NodeIt si; -// Graph::Node s; -// s=g.first(si); -// bfs.pushAndSetReached(BGW::Node(s)); -// while (!bfs.finished()) { ++bfs; } - -// FOR_EACH_LOC(stGW::NodeIt, n, stgw) { -// std::cout << "out-edges of " << n << ":\n"; -// FOR_EACH_INC_LOC(stGW::OutEdgeIt, e, stgw, n) { -// std::cout << " " << e << "\n"; -// std::cout << " aNode: " << stgw.aNode(e) << "\n"; -// std::cout << " bNode: " << stgw.bNode(e) << "\n"; -// } -// std::cout << "in-edges of " << n << ":\n"; -// FOR_EACH_INC_LOC(stGW::InEdgeIt, e, stgw, n) { -// std::cout << " " << e << "\n"; -// std::cout << " aNode: " << stgw.aNode(e) << "\n"; -// std::cout << " bNode: " << stgw.bNode(e) << "\n"; -// } -// } -// std::cout << "Edges of the stGraphWrapper:\n"; -// FOR_EACH_LOC(stGW::EdgeIt, n, stgw) { -// std::cout << " " << n << "\n"; -// } - -// stGW::NodeMap b(stgw); -// FOR_EACH_LOC(stGW::NodeIt, n, stgw) { -// std::cout << n << ": " << b[n] <<"\n"; -// } - -// std::cout << "Bfs from s: \n"; -// BfsIterator< stGW, stGW::NodeMap > bfs_stgw(stgw); -// bfs_stgw.pushAndSetReached(stgw.S_NODE); -// while (!bfs_stgw.finished()) { -// std::cout << " " << stGW::OutEdgeIt(bfs_stgw) << "\n"; -// ++bfs_stgw; -// } - - - Timer ts; - ts.reset(); - stGW::EdgeMap max_flow(stgw); - MaxFlow, stGW::EdgeMap > - max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, max_flow); -// while (max_flow_test.augmentOnShortestPath()) { } - typedef ListGraph MutableGraph; -// while (max_flow_test.augmentOnBlockingFlow1()) { - while (max_flow_test.augmentOnBlockingFlow2()) { - std::cout << max_flow_test.flowValue() << std::endl; - } - std::cout << "max flow value: " << max_flow_test.flowValue() << std::endl; - std::cout << "elapsed time: " << ts << std::endl; -// FOR_EACH_LOC(stGW::EdgeIt, e, stgw) { -// std::cout << e << ": " << max_flow[e] << "\n"; -// } -// std::cout << "\n"; - - ts.reset(); - stGW::EdgeMap pre_flow(stgw); - Preflow, stGW::EdgeMap > - pre_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, pre_flow, true); - pre_flow_test.run(); - std::cout << "pre flow value: " << max_flow_test.flowValue() << std::endl; - std::cout << "elapsed time: " << ts << std::endl; -// FOR_EACH_LOC(stGW::EdgeIt, e, stgw) { -// std::cout << e << ": " << pre_flow[e] << "\n"; -// } -// std::cout << "\n"; - - ts.reset(); - leda_list ml=MAX_CARD_BIPARTITE_MATCHING(lg); - // stGW::EdgeMap pre_flow(stgw); - //Preflow, stGW::EdgeMap > - // pre_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, pre_flow, true); - //pre_flow_test.run(); - std::cout << "leda matching value: " << ml.size() << std::endl; - std::cout << "elapsed time: " << ts << std::endl; -// FOR_EACH_LOC(stGW::EdgeIt, e, stgw) { -// std::cout << e << ": " << pre_flow[e] << "\n"; -// } -// std::cout << "\n"; - - return 0; -} diff -r 32a2a16027e0 -r 69e961722628 src/work/marci/leda/bipartite_matching_leda.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/work/marci/leda/bipartite_matching_leda.cc Mon Apr 26 16:08:46 2004 +0000 @@ -0,0 +1,219 @@ +// -*- c++ -*- +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +//#include +//#include +#include +#include +//#include +#include +#include +#include +#include + +/** + * Inicializalja a veletlenszamgeneratort. + * Figyelem, ez nem jo igazi random szamokhoz, + * erre ne bizzad a titkaidat! + */ +void random_init() +{ + unsigned int seed = getpid(); + seed |= seed << 15; + seed ^= time(0); + + srand(seed); +} + +/** + * Egy veletlen int-et ad vissza 0 es m-1 kozott. + */ +int random(int m) +{ + return int( double(m) * rand() / (RAND_MAX + 1.0) ); +} + +using namespace hugo; + +int main() { + //for leda graph + leda::graph lg; + //lg.make_undirected(); + typedef LedaGraphWrapper Graph; + Graph g(lg); + + //for UndirListGraph + //typedef UndirListGraph Graph; + //Graph g; + + typedef Graph::Node Node; + typedef Graph::NodeIt NodeIt; + typedef Graph::Edge Edge; + typedef Graph::EdgeIt EdgeIt; + typedef Graph::OutEdgeIt OutEdgeIt; + + std::vector s_nodes; + std::vector t_nodes; + + int a; + std::cout << "number of nodes in the first color class="; + std::cin >> a; + int b; + std::cout << "number of nodes in the second color class="; + std::cin >> b; + int m; + std::cout << "number of edges="; + std::cin >> m; + + + for (int i=0; i ref_map(g, -1); + + IterableBoolMap< Graph::NodeMap > bipartite_map(ref_map); + for (int i=0; i BGW; + BGW bgw(g, bipartite_map); + +// std::cout << "Nodes by NodeIt:\n"; +// FOR_EACH_LOC(BGW::NodeIt, n, bgw) { +// std::cout << n << " "; +// } +// std::cout << "\n"; +// std::cout << "Nodes in S by ClassNodeIt:\n"; +// FOR_EACH_INC_LOC(BGW::ClassNodeIt, n, bgw, bgw.S_CLASS) { +// std::cout << n << " "; +// } +// std::cout << "\n"; +// std::cout << "Nodes in T by ClassNodeIt:\n"; +// FOR_EACH_INC_LOC(BGW::ClassNodeIt, n, bgw, bgw.T_CLASS) { +// std::cout << n << " "; +// } +// std::cout << "\n"; +// std::cout << "Edges of the bipartite graph:\n"; +// FOR_EACH_LOC(BGW::EdgeIt, e, bgw) { +// std::cout << bgw.tail(e) << "->" << bgw.head(e) << std::endl; +// } + + BGW::NodeMap dbyj(bgw); + BGW::EdgeMap dbyxcj(bgw); + + typedef stGraphWrapper stGW; + stGW stgw(bgw); + ConstMap const1map(1); +// stGW::NodeMap ize(stgw); + +// BfsIterator< BGW, BGW::NodeMap > bfs(bgw); +// Graph::NodeIt si; +// Graph::Node s; +// s=g.first(si); +// bfs.pushAndSetReached(BGW::Node(s)); +// while (!bfs.finished()) { ++bfs; } + +// FOR_EACH_LOC(stGW::NodeIt, n, stgw) { +// std::cout << "out-edges of " << n << ":\n"; +// FOR_EACH_INC_LOC(stGW::OutEdgeIt, e, stgw, n) { +// std::cout << " " << e << "\n"; +// std::cout << " aNode: " << stgw.aNode(e) << "\n"; +// std::cout << " bNode: " << stgw.bNode(e) << "\n"; +// } +// std::cout << "in-edges of " << n << ":\n"; +// FOR_EACH_INC_LOC(stGW::InEdgeIt, e, stgw, n) { +// std::cout << " " << e << "\n"; +// std::cout << " aNode: " << stgw.aNode(e) << "\n"; +// std::cout << " bNode: " << stgw.bNode(e) << "\n"; +// } +// } +// std::cout << "Edges of the stGraphWrapper:\n"; +// FOR_EACH_LOC(stGW::EdgeIt, n, stgw) { +// std::cout << " " << n << "\n"; +// } + +// stGW::NodeMap b(stgw); +// FOR_EACH_LOC(stGW::NodeIt, n, stgw) { +// std::cout << n << ": " << b[n] <<"\n"; +// } + +// std::cout << "Bfs from s: \n"; +// BfsIterator< stGW, stGW::NodeMap > bfs_stgw(stgw); +// bfs_stgw.pushAndSetReached(stgw.S_NODE); +// while (!bfs_stgw.finished()) { +// std::cout << " " << stGW::OutEdgeIt(bfs_stgw) << "\n"; +// ++bfs_stgw; +// } + + + Timer ts; + ts.reset(); + stGW::EdgeMap max_flow(stgw); + MaxFlow, stGW::EdgeMap > + max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, max_flow); +// while (max_flow_test.augmentOnShortestPath()) { } + typedef ListGraph MutableGraph; +// while (max_flow_test.augmentOnBlockingFlow1()) { + while (max_flow_test.augmentOnBlockingFlow2()) { + std::cout << max_flow_test.flowValue() << std::endl; + } + std::cout << "max flow value: " << max_flow_test.flowValue() << std::endl; + std::cout << "elapsed time: " << ts << std::endl; +// FOR_EACH_LOC(stGW::EdgeIt, e, stgw) { +// std::cout << e << ": " << max_flow[e] << "\n"; +// } +// std::cout << "\n"; + + ts.reset(); + stGW::EdgeMap pre_flow(stgw); + Preflow, stGW::EdgeMap > + pre_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, pre_flow, true); + pre_flow_test.run(); + std::cout << "pre flow value: " << max_flow_test.flowValue() << std::endl; + std::cout << "elapsed time: " << ts << std::endl; +// FOR_EACH_LOC(stGW::EdgeIt, e, stgw) { +// std::cout << e << ": " << pre_flow[e] << "\n"; +// } +// std::cout << "\n"; + + ts.reset(); + leda_list ml=MAX_CARD_BIPARTITE_MATCHING(lg); + // stGW::EdgeMap pre_flow(stgw); + //Preflow, stGW::EdgeMap > + // pre_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, pre_flow, true); + //pre_flow_test.run(); + std::cout << "leda matching value: " << ml.size() << std::endl; + std::cout << "elapsed time: " << ts << std::endl; +// FOR_EACH_LOC(stGW::EdgeIt, e, stgw) { +// std::cout << e << ": " << pre_flow[e] << "\n"; +// } +// std::cout << "\n"; + + return 0; +} diff -r 32a2a16027e0 -r 69e961722628 src/work/marci/leda/leda_graph_wrapper.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/work/marci/leda/leda_graph_wrapper.h Mon Apr 26 16:08:46 2004 +0000 @@ -0,0 +1,321 @@ +// -*- c++ -*- +#ifndef HUGO_LEDA_GRAPH_WRAPPER_H +#define HUGO_LEDA_GRAPH_WRAPPER_H + +#include +#include +#include +#include +#include +//#include +//#include + +//#if defined(LEDA_NAMESPACE) +//using namespace leda; +//#endif + +#include + +/// The namespace of HugoLib +namespace hugo { + + // @defgroup empty_graph The LedaGraphWrapper class + // @{ + + /// A graph wrapperstructure for wrapping LEDA graphs in HUGO. + + /// This graph wrapper class wraps LEDA graph and LEDA parametrized graph + /// and then the generic algorithms and wrappers of HUGO can be used + /// with LEDA graphs. + /// This class provides all the common features of a grapf structure, + /// however completely without implementations or real data structures + /// behind the interface. + /// All graph algorithms should compile with this class, but it will not + /// run properly, of course. + /// + /// It can be used for checking the interface compatibility, + /// or it can serve as a skeleton of a new graph structure. + /// + /// Also, you will find here the full documentation of a certain graph + /// feature, the documentation of a real graph imlementation + /// like @ref ListGraph or + /// @ref SmartGraph will just refer to this structure. + template + class LedaGraphWrapper + { + Graph* _graph; + public: + + //LedaGraphWrapper() { } + LedaGraphWrapper(Graph& __graph) : _graph(&__graph) { } + LedaGraphWrapper(const LedaGraphWrapper &G) : _graph(G._graph) { } + + template class NodeMap; + template class EdgeMap; + + /// The base type of the node iterators. + class Node { + friend class LedaGraphWrapper; + //friend class Edge; + friend class EdgeIt; + friend class InEdgeIt; + friend class OutEdgeIt; + protected: + template friend class NodeMap; + leda_node _n; + Node(leda_node __n) : _n(__n) { } + public: + /// @warning The default constructor sets the iterator + /// to an undefined value. + Node() {} //FIXME + /// Initialize the iterator to be invalid + Node(Invalid) : _n(0) { } + //Node(const Node &) {} + bool operator==(Node n) const { return _n==n._n; } //FIXME + bool operator!=(Node n) const { return _n!=n._n; } //FIXME + operator leda_node () { return _n; } + }; + + /// This iterator goes through each node. + class NodeIt : public Node { + public: + /// @warning The default constructor sets the iterator + /// to an undefined value. + NodeIt() {} //FIXME + /// Initialize the iterator to be invalid + NodeIt(Invalid i) : Node(i) {} + /// Sets the iterator to the first node of \c G. + NodeIt(const LedaGraphWrapper &G) : Node(G._graph->first_node()) { } + //NodeIt(const NodeIt &) {} //FIXME + }; + + /// The base type of the edge iterators. + class Edge { + friend class LedaGraphWrapper; + protected: + template friend class EdgeMap; + leda_edge _e; + Edge(leda_edge __e) : _e(__e) { } + public: + /// @warning The default constructor sets the iterator + /// to an undefined value. + Edge() {} //FIXME + /// Initialize the iterator to be invalid + Edge(Invalid) : _e(0) {} + //Edge(const Edge &) {} + bool operator==(Edge e) const { return _e==e._e; } //FIXME + bool operator!=(Edge e) const { return _e!=e._e; } //FIXME + operator leda_edge () { return _e; } + }; + + /// This iterator goes trought the outgoing edges of a certain graph. + + class OutEdgeIt : public Edge { + public: + /// @warning The default constructor sets the iterator + /// to an undefined value. + OutEdgeIt() {} + /// Initialize the iterator to be invalid + OutEdgeIt(Invalid i) : Edge(i) {} + /// This constructor sets the iterator to first outgoing edge. + + /// This constructor set the iterator to the first outgoing edge of + /// node + ///@param n the node + ///@param G the graph + OutEdgeIt(const LedaGraphWrapper & G, Node n) : Edge(G._graph->first_adj_edge(n._n)) { } + }; + + class InEdgeIt : public Edge { + public: + /// @warning The default constructor sets the iterator + /// to an undefined value. + InEdgeIt() {} + /// Initialize the iterator to be invalid + InEdgeIt(Invalid i) : Edge(i) {} + InEdgeIt(const LedaGraphWrapper & G, Node n) : Edge(G._graph->first_in_edge(n._n)) { } + }; + + // class SymEdgeIt : public Edge {}; + class EdgeIt : public Edge { + public: + /// @warning The default constructor sets the iterator + /// to an undefined value. + EdgeIt() {} + /// Initialize the iterator to be invalid + EdgeIt(Invalid i) : Edge(i) {} + EdgeIt(const LedaGraphWrapper & G) : Edge(G._graph->first_edge()) { } + }; + + /// First node of the graph. + + /// \post \c i and the return value will be the first node. + /// + NodeIt &first(NodeIt &i) const { i=NodeIt(*this); return i; } + + /// The first outgoing edge. + InEdgeIt &first(InEdgeIt &i, Node n) const { + i=InEdgeIt(*this, n); + return i; + } + /// The first incoming edge. + OutEdgeIt &first(OutEdgeIt &i, Node n) const { + i=OutEdgeIt(*this, n); + return i; + } + // SymEdgeIt &first(SymEdgeIt &, Node) const { return i;} + /// The first edge of the Graph. + EdgeIt &first(EdgeIt &i) const { + i=EdgeIt(*this); + return i; } + +// Node getNext(Node) const {} +// InEdgeIt getNext(InEdgeIt) const {} +// OutEdgeIt getNext(OutEdgeIt) const {} +// //SymEdgeIt getNext(SymEdgeIt) const {} +// EdgeIt getNext(EdgeIt) const {} + + /// Go to the next node. + NodeIt &next(NodeIt &i) const { + i._n=_graph->succ_node(i._n); + return i; + } + /// Go to the next incoming edge. + InEdgeIt &next(InEdgeIt &i) const { + i._e=_graph->in_succ(i._e); + return i; + } + /// Go to the next outgoing edge. + OutEdgeIt &next(OutEdgeIt &i) const { + i._e=_graph->adj_succ(i._e); + return i; + } + //SymEdgeIt &next(SymEdgeIt &) const {} + /// Go to the next edge. + EdgeIt &next(EdgeIt &i) const { + i._e=_graph->succ_edge(i._e); + return i; + } + +// template< typename It > +// It first() const { +// It e; +// first(e); +// return e; +// } + +// template< typename It > +// It first(Node v) const { +// It e; +// first(e, v); +// return e; +// } + + ///Gives back the head node of an edge. + Node head(Edge e) const { + return Node(_graph->target(e._e)); + } + ///Gives back the tail node of an edge. + Node tail(Edge e) const { + return Node(_graph->source(e._e)); + } + + Node aNode(InEdgeIt e) const { return head(e); } + Node aNode(OutEdgeIt e) const { return tail(e); } + // Node aNode(SymEdgeIt) const {} + + Node bNode(InEdgeIt e) const { return tail(e); } + Node bNode(OutEdgeIt e) const { return head(e); } + // Node bNode(SymEdgeIt) const {} + + /// Checks if a node iterator is valid + bool valid(Node n) const { return n._n; } + /// Checks if an edge iterator is valid + bool valid(Edge e) const { return e._e; } + + ///Gives back the \e id of a node. + int id(Node n) const { return n._n->id(); } + ///Gives back the \e id of an edge. + int id(Edge e) const { return e._e->id(); } + + //void setInvalid(Node &) const {}; + //void setInvalid(Edge &) const {}; + + Node addNode() const { return Node(_graph->new_node()); } + Edge addEdge(Node tail, Node head) const { + return Edge(_graph->new_edge(tail._n, head._n)); + } + + void erase(Node n) const { _graph->del_node(n._n); } + void erase(Edge e) const { _graph->del_edge(e._e); } + + void clear() const { _graph->clear(); } + + int nodeNum() const { return _graph->number_of_nodes(); } + int edgeNum() const { return _graph->number_of_edges(); } + + ///Read/write map from the nodes to type \c T. + template class NodeMap + { + leda_node_map leda_stuff; + public: + typedef T ValueType; + typedef Node KeyType; + + NodeMap(const LedaGraphWrapper &G) : leda_stuff(*(G._graph)) {} + NodeMap(const LedaGraphWrapper &G, T t) : leda_stuff(*(G._graph), t) {} + + void set(Node i, T t) { leda_stuff[i._n]=t; } + T get(Node i) const { return leda_stuff[i._n]; } //FIXME: Is it necessary + T &operator[](Node i) { return leda_stuff[i._n]; } + const T &operator[](Node i) const { return leda_stuff[i._n]; } + + void update() { /*leda_stuff.init(leda_stuff.get_graph());*/ } + //void update(T a) { leda_stuff.init(leda_stuff.get_graph()/**(G._graph)*/, a); } //FIXME: Is it necessary + }; + + ///Read/write map from the edges to type \c T. + template class EdgeMap + { + leda_edge_map leda_stuff; + public: + typedef T ValueType; + typedef Edge KeyType; + + EdgeMap(const LedaGraphWrapper &G) : leda_stuff(*(G._graph)) {} + EdgeMap(const LedaGraphWrapper &G, T t) : leda_stuff(*(G._graph), t) {} + + void set(Edge i, T t) { leda_stuff[i._e]=t; } + T get(Edge i) const { return leda_stuff[i._e]; } //FIXME: Is it necessary + T &operator[](Edge i) { return leda_stuff[i._e]; } + const T &operator[](Edge i) const { return leda_stuff[i._e]; } + + void update() { /*leda_stuff.init(leda_stuff.get_graph());*/ } + //void update(T a) { leda_stuff.init(leda_stuff.get_graph()/**(G._graph)*/, a); } //FIXME: Is it necessary + }; + + }; + + // @} + +} //namespace hugo + + + +// class EmptyBipGraph : public EmptyGraph +// { +// class ANode {}; +// class BNode {}; + +// ANode &next(ANode &) {} +// BNode &next(BNode &) {} + +// ANode &getFirst(ANode &) const {} +// BNode &getFirst(BNode &) const {} + +// enum NodeClass { A = 0, B = 1 }; +// NodeClass getClass(Node n) {} + +// } + +#endif // HUGO_LEDA_GRAPH_WRAPPER_H diff -r 32a2a16027e0 -r 69e961722628 src/work/marci/leda/makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/work/marci/leda/makefile Mon Apr 26 16:08:46 2004 +0000 @@ -0,0 +1,86 @@ +CXX2 = g++-2.95 +#CXX3 := $(shell type -p g++-3.3 || type -p g++-3.2 || type -p g++-3.0 || type -p g++-3 || echo g++) +CXX3=$(CXX) +#CXX=$(CXX3) +#CC=$(CXX) +#LEDAROOT ?= /ledasrc/LEDA-4.1 +BOOSTROOT ?= /home/marci/boost +INCLUDEDIRS ?= -I../../include -I.. -I../{marci,jacint,alpar,klao,akos,athos} -I$(BOOSTROOT) +#LEDAINCLUDE ?= -I$(LEDAROOT)/incl +#CXXFLAGS = -g -O3 -W -Wall $(INCLUDEDIRS) -ansi -pedantic -ftemplate-depth-30 + +LEDABINARIES = leda_graph_demo leda_bfs_dfs max_bipartite_matching_demo +BINARIES = edmonds_karp_demo iterator_bfs_demo macro_test lg_vs_sg bfsit_vs_byhand bipartite_graph_wrapper_test bipartite_matching_try +#gw_vs_not preflow_demo_boost edmonds_karp_demo_boost preflow_demo_jacint preflow_demo_athos edmonds_karp_demo_alpar preflow_demo_leda + +include ../makefile +#all: $(BINARIES) + +#.depend dep depend: +# -$(CXX) $(INCLUDEDIRS) -M $(BINARIES:=.cc) > .depend #2>/dev/null +# -g++ $(INCLUDEDIRS) $(LEDAINCLUDE) -M $(LEDABINARIES:=.cc) >> .depend #2>/dev/null + + + +#makefile: .depend +#sinclude .depend + +leda_graph_demo.o: + $(CXX3) -Wall -O -I.. -I../alpar -I$(LEDAROOT)/incl -I. -c leda_graph_demo.cc + +leda_graph_demo: leda_graph_demo.o + $(CXX3) -Wall -O -L$(LEDAROOT) -o leda_graph_demo leda_graph_demo.o -lG -lL -lm + +bipartite_matching_leda.o: + $(CXX3) $(CXXFLAGS) -I$(LEDAROOT)/incl -c bipartite_matching_leda.cc + +bipartite_matching_leda: bipartite_matching_leda.o + $(CXX3) $(CXXFLAGS) -L$(LEDAROOT) -o bipartite_matching_leda bipartite_matching_leda.o -lG -lL -lm + +max_bipartite_matching_demo.o: + $(CXX3) $(CXXFLAGS) -I$(LEDAROOT)/incl -c max_bipartite_matching_demo.cc + +max_bipartite_matching_demo: max_bipartite_matching_demo.o + $(CXX3) $(CXXFLAGS) -L$(LEDAROOT) -o max_bipartite_matching_demo max_bipartite_matching_demo.o -lG -lL -lm + +leda_bfs_dfs.o: + $(CXX3) -Wall -O -I.. -I../alpar -I$(LEDAROOT)/incl -I. -c leda_bfs_dfs.cc + +leda_bfs_dfs: leda_bfs_dfs.o + $(CXX3) -Wall -O -L$(LEDAROOT) -o leda_bfs_dfs leda_bfs_dfs.o -lG -lL -lm + +#edmonds_karp_demo: +# $(CXX3) $(CXXFLAGS) -o edmonds_karp_demo edmonds_karp_demo.cc +# $(CXX3) $(CXXFLAGS) -pg -o edmonds_karp_demo_prof edmonds_karp_demo.cc + +gw_vs_not: + $(CXX3) $(CXXFLAGS) -o gw_vs_not gw_vs_not.cc + +#lg_vs_sg: +# $(CXX3) $(CXXFLAGS) -g -I. -I.. -o lg_vs_sg lg_vs_sg.cc + +edmonds_karp_demo_alpar: + $(CXX3) $(CXXFLAGS) -I. -I.. -I../alpar -o edmonds_karp_demo_alpar edmonds_karp_demo_alpar.cc + +preflow_demo_leda: + $(CXX2) -W -Wall -03 -DLEDA_PREFIX -I. -I$(LEDAROOT)/incl -L$(LEDAROOT) -o preflow_demo_leda preflow_demo_leda.cc -lP -lm -lL -lG + +preflow_demo_leda_uj: + $(CXX3) -Wall -O3 -I$(LEDAROOT)/incl -I. -L$(LEDAROOT) -o preflow_demo_leda_uj preflow_demo_leda_uj.cc -lG -lL -lm + +preflow_demo_boost: + $(CXX2) -ftemplate-depth-30 -O3 -I. -I/home/marci/boost -o preflow_demo_boost preflow_demo_boost.cc + +edmonds_karp_demo_boost: + $(CXX2) -ftemplate-depth-30 -O3 -I. -I/home/marci/boost -o edmonds_karp_demo_boost edmonds_karp_demo_boost.cc + +preflow_demo_jacint: + $(CXX3) $(CXXFLAGS) -I. -I.. -I../jacint -o preflow_demo_jacint preflow_demo_jacint.cc + +preflow_demo_athos: + $(CXX3) $(CXXFLAGS) -I. -I.. -I../athos -o preflow_demo_athos preflow_demo_athos.cc + +#clean: +# $(RM) *.o $(BINARIES) .depend +# +#.PHONY: all clean dep depend diff -r 32a2a16027e0 -r 69e961722628 src/work/marci/leda_graph_wrapper.h --- a/src/work/marci/leda_graph_wrapper.h Mon Apr 26 16:02:09 2004 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,321 +0,0 @@ -// -*- c++ -*- -#ifndef HUGO_LEDA_GRAPH_WRAPPER_H -#define HUGO_LEDA_GRAPH_WRAPPER_H - -#include -#include -#include -#include -#include -//#include -//#include - -//#if defined(LEDA_NAMESPACE) -//using namespace leda; -//#endif - -#include - -/// The namespace of HugoLib -namespace hugo { - - // @defgroup empty_graph The LedaGraphWrapper class - // @{ - - /// A graph wrapperstructure for wrapping LEDA graphs in HUGO. - - /// This graph wrapper class wraps LEDA graph and LEDA parametrized graph - /// and then the generic algorithms and wrappers of HUGO can be used - /// with LEDA graphs. - /// This class provides all the common features of a grapf structure, - /// however completely without implementations or real data structures - /// behind the interface. - /// All graph algorithms should compile with this class, but it will not - /// run properly, of course. - /// - /// It can be used for checking the interface compatibility, - /// or it can serve as a skeleton of a new graph structure. - /// - /// Also, you will find here the full documentation of a certain graph - /// feature, the documentation of a real graph imlementation - /// like @ref ListGraph or - /// @ref SmartGraph will just refer to this structure. - template - class LedaGraphWrapper - { - Graph* _graph; - public: - - //LedaGraphWrapper() { } - LedaGraphWrapper(Graph& __graph) : _graph(&__graph) { } - LedaGraphWrapper(const LedaGraphWrapper &G) : _graph(G._graph) { } - - template class NodeMap; - template class EdgeMap; - - /// The base type of the node iterators. - class Node { - friend class LedaGraphWrapper; - //friend class Edge; - friend class EdgeIt; - friend class InEdgeIt; - friend class OutEdgeIt; - protected: - template friend class NodeMap; - leda_node _n; - Node(leda_node __n) : _n(__n) { } - public: - /// @warning The default constructor sets the iterator - /// to an undefined value. - Node() {} //FIXME - /// Initialize the iterator to be invalid - Node(Invalid) : _n(0) { } - //Node(const Node &) {} - bool operator==(Node n) const { return _n==n._n; } //FIXME - bool operator!=(Node n) const { return _n!=n._n; } //FIXME - operator leda_node () { return _n; } - }; - - /// This iterator goes through each node. - class NodeIt : public Node { - public: - /// @warning The default constructor sets the iterator - /// to an undefined value. - NodeIt() {} //FIXME - /// Initialize the iterator to be invalid - NodeIt(Invalid i) : Node(i) {} - /// Sets the iterator to the first node of \c G. - NodeIt(const LedaGraphWrapper &G) : Node(G._graph->first_node()) { } - //NodeIt(const NodeIt &) {} //FIXME - }; - - /// The base type of the edge iterators. - class Edge { - friend class LedaGraphWrapper; - protected: - template friend class EdgeMap; - leda_edge _e; - Edge(leda_edge __e) : _e(__e) { } - public: - /// @warning The default constructor sets the iterator - /// to an undefined value. - Edge() {} //FIXME - /// Initialize the iterator to be invalid - Edge(Invalid) : _e(0) {} - //Edge(const Edge &) {} - bool operator==(Edge e) const { return _e==e._e; } //FIXME - bool operator!=(Edge e) const { return _e!=e._e; } //FIXME - operator leda_edge () { return _e; } - }; - - /// This iterator goes trought the outgoing edges of a certain graph. - - class OutEdgeIt : public Edge { - public: - /// @warning The default constructor sets the iterator - /// to an undefined value. - OutEdgeIt() {} - /// Initialize the iterator to be invalid - OutEdgeIt(Invalid i) : Edge(i) {} - /// This constructor sets the iterator to first outgoing edge. - - /// This constructor set the iterator to the first outgoing edge of - /// node - ///@param n the node - ///@param G the graph - OutEdgeIt(const LedaGraphWrapper & G, Node n) : Edge(G._graph->first_adj_edge(n._n)) { } - }; - - class InEdgeIt : public Edge { - public: - /// @warning The default constructor sets the iterator - /// to an undefined value. - InEdgeIt() {} - /// Initialize the iterator to be invalid - InEdgeIt(Invalid i) : Edge(i) {} - InEdgeIt(const LedaGraphWrapper & G, Node n) : Edge(G._graph->first_in_edge(n._n)) { } - }; - - // class SymEdgeIt : public Edge {}; - class EdgeIt : public Edge { - public: - /// @warning The default constructor sets the iterator - /// to an undefined value. - EdgeIt() {} - /// Initialize the iterator to be invalid - EdgeIt(Invalid i) : Edge(i) {} - EdgeIt(const LedaGraphWrapper & G) : Edge(G._graph->first_edge()) { } - }; - - /// First node of the graph. - - /// \post \c i and the return value will be the first node. - /// - NodeIt &first(NodeIt &i) const { i=NodeIt(*this); return i; } - - /// The first outgoing edge. - InEdgeIt &first(InEdgeIt &i, Node n) const { - i=InEdgeIt(*this, n); - return i; - } - /// The first incoming edge. - OutEdgeIt &first(OutEdgeIt &i, Node n) const { - i=OutEdgeIt(*this, n); - return i; - } - // SymEdgeIt &first(SymEdgeIt &, Node) const { return i;} - /// The first edge of the Graph. - EdgeIt &first(EdgeIt &i) const { - i=EdgeIt(*this); - return i; } - -// Node getNext(Node) const {} -// InEdgeIt getNext(InEdgeIt) const {} -// OutEdgeIt getNext(OutEdgeIt) const {} -// //SymEdgeIt getNext(SymEdgeIt) const {} -// EdgeIt getNext(EdgeIt) const {} - - /// Go to the next node. - NodeIt &next(NodeIt &i) const { - i._n=_graph->succ_node(i._n); - return i; - } - /// Go to the next incoming edge. - InEdgeIt &next(InEdgeIt &i) const { - i._e=_graph->in_succ(i._e); - return i; - } - /// Go to the next outgoing edge. - OutEdgeIt &next(OutEdgeIt &i) const { - i._e=_graph->adj_succ(i._e); - return i; - } - //SymEdgeIt &next(SymEdgeIt &) const {} - /// Go to the next edge. - EdgeIt &next(EdgeIt &i) const { - i._e=_graph->succ_edge(i._e); - return i; - } - -// template< typename It > -// It first() const { -// It e; -// first(e); -// return e; -// } - -// template< typename It > -// It first(Node v) const { -// It e; -// first(e, v); -// return e; -// } - - ///Gives back the head node of an edge. - Node head(Edge e) const { - return Node(_graph->target(e._e)); - } - ///Gives back the tail node of an edge. - Node tail(Edge e) const { - return Node(_graph->source(e._e)); - } - - Node aNode(InEdgeIt e) const { return head(e); } - Node aNode(OutEdgeIt e) const { return tail(e); } - // Node aNode(SymEdgeIt) const {} - - Node bNode(InEdgeIt e) const { return tail(e); } - Node bNode(OutEdgeIt e) const { return head(e); } - // Node bNode(SymEdgeIt) const {} - - /// Checks if a node iterator is valid - bool valid(Node n) const { return n._n; } - /// Checks if an edge iterator is valid - bool valid(Edge e) const { return e._e; } - - ///Gives back the \e id of a node. - int id(Node n) const { return n._n->id(); } - ///Gives back the \e id of an edge. - int id(Edge e) const { return e._e->id(); } - - //void setInvalid(Node &) const {}; - //void setInvalid(Edge &) const {}; - - Node addNode() const { return Node(_graph->new_node()); } - Edge addEdge(Node tail, Node head) const { - return Edge(_graph->new_edge(tail._n, head._n)); - } - - void erase(Node n) const { _graph->del_node(n._n); } - void erase(Edge e) const { _graph->del_edge(e._e); } - - void clear() const { _graph->clear(); } - - int nodeNum() const { return _graph->number_of_nodes(); } - int edgeNum() const { return _graph->number_of_edges(); } - - ///Read/write map from the nodes to type \c T. - template class NodeMap - { - leda_node_map leda_stuff; - public: - typedef T ValueType; - typedef Node KeyType; - - NodeMap(const LedaGraphWrapper &G) : leda_stuff(*(G._graph)) {} - NodeMap(const LedaGraphWrapper &G, T t) : leda_stuff(*(G._graph), t) {} - - void set(Node i, T t) { leda_stuff[i._n]=t; } - T get(Node i) const { return leda_stuff[i._n]; } //FIXME: Is it necessary - T &operator[](Node i) { return leda_stuff[i._n]; } - const T &operator[](Node i) const { return leda_stuff[i._n]; } - - void update() { /*leda_stuff.init(leda_stuff.get_graph());*/ } - //void update(T a) { leda_stuff.init(leda_stuff.get_graph()/**(G._graph)*/, a); } //FIXME: Is it necessary - }; - - ///Read/write map from the edges to type \c T. - template class EdgeMap - { - leda_edge_map leda_stuff; - public: - typedef T ValueType; - typedef Edge KeyType; - - EdgeMap(const LedaGraphWrapper &G) : leda_stuff(*(G._graph)) {} - EdgeMap(const LedaGraphWrapper &G, T t) : leda_stuff(*(G._graph), t) {} - - void set(Edge i, T t) { leda_stuff[i._e]=t; } - T get(Edge i) const { return leda_stuff[i._e]; } //FIXME: Is it necessary - T &operator[](Edge i) { return leda_stuff[i._e]; } - const T &operator[](Edge i) const { return leda_stuff[i._e]; } - - void update() { /*leda_stuff.init(leda_stuff.get_graph());*/ } - //void update(T a) { leda_stuff.init(leda_stuff.get_graph()/**(G._graph)*/, a); } //FIXME: Is it necessary - }; - - }; - - // @} - -} //namespace hugo - - - -// class EmptyBipGraph : public EmptyGraph -// { -// class ANode {}; -// class BNode {}; - -// ANode &next(ANode &) {} -// BNode &next(BNode &) {} - -// ANode &getFirst(ANode &) const {} -// BNode &getFirst(BNode &) const {} - -// enum NodeClass { A = 0, B = 1 }; -// NodeClass getClass(Node n) {} - -// } - -#endif // HUGO_LEDA_GRAPH_WRAPPER_H