# HG changeset patch # User klao # Date 1082167068 0 # Node ID e4ab32225f1cfddbd2b0434368284987a1fec095 # Parent 538ff3ce9f68ac4d0fdd945c42ca3b73e256c78d A generic map with value type [0, N) where N is a small integer. Can enumerate keys with a given value. diff -r 538ff3ce9f68 -r e4ab32225f1c src/work/klao/Makefile --- a/src/work/klao/Makefile Sat Apr 17 01:50:23 2004 +0000 +++ b/src/work/klao/Makefile Sat Apr 17 01:57:48 2004 +0000 @@ -1,4 +1,4 @@ -BINARIES = path_test map_test minlengthpaths +BINARIES = path_test map_test iter_map_test INCLUDEDIRS= -I. -I.. -I../../include -I../{marci,jacint,alpar,johanna,akos} include ../makefile diff -r 538ff3ce9f68 -r e4ab32225f1c src/work/klao/iter_map.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/work/klao/iter_map.h Sat Apr 17 01:57:48 2004 +0000 @@ -0,0 +1,121 @@ +// -*- c++ -*- // + +#ifndef HUGO_ITER_MAP +#define HUGO_ITER_MAP + +#include +#include +// for uint8_t +#include +// for memset +#include + + +namespace hugo { + + + /// \todo Decide whether we need all the range checkings!!! + + template + class IterableMap { + public: + + typedef typename KeyIntMap::KeyType KeyType; + typedef uint8_t ValueType; + + typedef typename std::vector::const_iterator iterator; + + protected: + KeyIntMap &base; + std::vector data; + size_t bounds[N]; + + uint8_t find(size_t a) const { + uint8_t n=0; + for(; n n) { + --m; + half_swap(a, bounds[m]++); + } + while(m < n) { + half_swap(a, --bounds[m]); + ++m; + } + if(a != orig_a) { + base.set(orig_key, a); + data[a]=orig_key; + } + } + return a; + } + + public: + + IterableMap(KeyIntMap &_base) : base(_base) { + memset(bounds, 0, sizeof(bounds)); + // for(int i=0; i +#include + +#include + +using namespace hugo; +using namespace std; + +const int N = 3; + +typedef StdMap BaseMap; +typedef IterableMap TestMap; + + +void print(TestMap const& m) { + cout << "Size of the map: " << m.size() << endl; + for(int i=0; i -//#include -//#include - -#include -#include - -using namespace hugo; - - -int main() -{ - - - typedef ListGraph::Node Node; - typedef ListGraph::Edge Edge; - - ListGraph graph; - - /* - //Marci példája - - - NodeIt s=graph.addNode(); - NodeIt v1=graph.addNode(); - NodeIt v2=graph.addNode(); - NodeIt v3=graph.addNode(); - NodeIt v4=graph.addNode(); - NodeIt t=graph.addNode(); - - - EdgeIt s_v1=graph.addEdge(s, v1); - EdgeIt s_v2=graph.addEdge(s, v2); - EdgeIt v1_v2=graph.addEdge(v1, v2); - EdgeIt v2_v1=graph.addEdge(v2, v1); - EdgeIt v1_v3=graph.addEdge(v1, v3); - EdgeIt v3_v2=graph.addEdge(v3, v2); - EdgeIt v2_v4=graph.addEdge(v2, v4); - EdgeIt v4_v3=graph.addEdge(v4, v3); - EdgeIt v3_t=graph.addEdge(v3, t); - EdgeIt v4_t=graph.addEdge(v4, t); - - ListGraph::EdgeMap length(graph); - - length.set(s_v1, 16); - length.set(s_v2, 13); - length.set(v1_v2, 10); - length.set(v2_v1, 4); - length.set(v1_v3, 12); - length.set(v3_v2, 9); - length.set(v2_v4, 14); - length.set(v4_v3, 7); - length.set(v3_t, 20); - length.set(v4_t, 4); - */ - - - //Ahuja könyv példája - - Node s=graph.addNode(); - Node v2=graph.addNode(); - Node v3=graph.addNode(); - Node v4=graph.addNode(); - Node v5=graph.addNode(); - Node t=graph.addNode(); - - Edge s_v2=graph.addEdge(s, v2); - Edge s_v3=graph.addEdge(s, v3); - Edge v2_v4=graph.addEdge(v2, v4); - Edge v2_v5=graph.addEdge(v2, v5); - Edge v3_v5=graph.addEdge(v3, v5); - Edge v4_t=graph.addEdge(v4, t); - Edge v5_t=graph.addEdge(v5, t); - - //Kis modositas - //edge_iterator v2_s=graph.add_edge(v2, s); - - ListGraph::EdgeMap length(graph); - - length.set(s_v2, 10); - length.set(s_v3, 10); - length.set(v2_v4, 5); - length.set(v2_v5, 8); - length.set(v3_v5, 5); - length.set(v4_t, 8); - length.set(v5_t, 8); - - //Kis modositas - //length.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 length(flow_test); - - length.put(s_v1, 16); - length.put(v1_v2, 10); - length.put(v2_t, 4); - */ - - std::cout << "Suurballe algorithm test..." << std::endl; - - - int k=3; - MinLengthPaths > - surb_test(graph, length); - std::cout << surb_test.run(s,t,k) << std::endl; - - return 0; -} diff -r 538ff3ce9f68 -r e4ab32225f1c src/work/klao/minlengthpaths.h --- a/src/work/klao/minlengthpaths.h Sat Apr 17 01:50:23 2004 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,134 +0,0 @@ -// -*- c++ -*- -#ifndef HUGO_MINLENGTHPATHS_H -#define HUGO_MINLENGTHPATHS_H - -///\file -///\brief An algorithm for finding k paths of minimal total length. - -#include -#include -#include -#include - -namespace hugo { - - - ///\brief Implementation of an algorithm for finding k paths between 2 nodes - /// of minimal total length - /// - /// The class \ref hugo::MinLengthPaths "MinLengthPaths" implements - /// an algorithm which finds k edge-disjoint paths - /// from a given source node to a given target node in an - /// edge-weighted directed graph having minimal total weigth (length). - - template - class MinLengthPaths { - - typedef typename LengthMap::ValueType Length; - - typedef typename Graph::Node Node; - typedef typename Graph::NodeIt NodeIt; - typedef typename Graph::Edge Edge; - typedef typename Graph::OutEdgeIt OutEdgeIt; - typedef typename Graph::EdgeMap EdgeIntMap; - - typedef ConstMap ConstMap; - - typedef ResGraphWrapper ResGraphType; - - - class ModLengthMap { - typedef typename ResGraphType::NodeMap NodeMap; - const ResGraphType& G; - const EdgeIntMap& rev; - const LengthMap &ol; - const NodeMap &pot; - public : - typedef typename LengthMap::KeyType KeyType; - typedef typename LengthMap::ValueType ValueType; - - ValueType operator[](typename ResGraphType::Edge e) const { - if ( (1-2*rev[e])*ol[e]-(pot[G.head(e)]-pot[G.tail(e)] ) <0 ){ - ///\TODO This has to be removed - std::cout<<"Negative length!!"< dijkstra_dist(res_graph); - ModLengthMap mod_length(res_graph, reversed, length, dijkstra_dist); - - Dijkstra dijkstra(res_graph, mod_length); - - for (int i=0; i