# HG changeset patch # User athos # Date 1120234246 0 # Node ID 1aa71600000c8af23c77ab55be5e3ee561202b56 # Parent 7ceab500e1f65070ac72134668124a054a31fa08 Graph input-output demo, some documentation. diff -r 7ceab500e1f6 -r 1aa71600000c demo/Makefile.am --- a/demo/Makefile.am Fri Jul 01 10:33:27 2005 +0000 +++ b/demo/Makefile.am Fri Jul 01 16:10:46 2005 +0000 @@ -6,6 +6,7 @@ noinst_PROGRAMS = \ dim_to_dot \ dijkstra_demo \ + reader_writer_demo \ dim_to_lgf \ graph_to_eps_demo \ min_route \ @@ -26,6 +27,8 @@ dijkstra_demo_SOURCES = dijkstra_demo.cc +reader_writer_demo_SOURCES = reader_writer_demo.cc + dim_to_lgf_SOURCES = dim_to_lgf.cc coloring_SOURCES = coloring.cc diff -r 7ceab500e1f6 -r 1aa71600000c demo/dijkstra_demo.cc --- a/demo/dijkstra_demo.cc Fri Jul 01 10:33:27 2005 +0000 +++ b/demo/dijkstra_demo.cc Fri Jul 01 16:10:46 2005 +0000 @@ -48,11 +48,6 @@ std::cout << "Dijkstra algorithm test..." << std::endl; -// GraphWriter writer(std::cout, g); -// writer.writeEdgeMap("capacity", len); -// writer.writeNode("source", s); -// writer.writeNode("target", t); -// writer.run(); Dijkstra dijkstra_test(g,len); diff -r 7ceab500e1f6 -r 1aa71600000c demo/reader_writer_demo.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demo/reader_writer_demo.cc Fri Jul 01 16:10:46 2005 +0000 @@ -0,0 +1,83 @@ +#include +#include +#include +#include +#include + + +using namespace lemon; + +int main() { + SmartGraph graph; + + try { + std::string filename="sample.lgf"; + GraphReader reader(filename,graph); + SmartGraph::EdgeMap cap(graph); + reader.readEdgeMap("capacity",cap); +// reader.readNode("source",s).readNode("target",t) +// .readEdgeMap("capacity",cap).run(); + reader.run(); + + std::cout << "Hello! We have read a graph from file " << filename<< + " and some maps on it: now we write this to the standard output!" << + std::endl; + + + GraphWriter writer(std::cout, graph); + writer.writeEdgeMap("multiplicity", cap); +// writer.writeNode("source", s); +// writer.writeNode("target", t); + writer.run(); + +// LemonReader reader(std::cin); + +// NodeSetReader nodeset(reader, graph); +// SmartGraph::NodeMap cost(graph); +// nodeset.readMap("cost", cost); +// SmartGraph::NodeMap mmap(graph); +// nodeset.readMap("mmap", mmap); + +// EdgeSetReader edgeset(reader, graph, nodeset); +// SmartGraph::EdgeMap description(graph); +// edgeset.readMap("description", description); + +// NodeReader nodes(reader, nodeset); +// SmartGraph::Node source; +// nodes.readNode("source", source); +// SmartGraph::Node target; +// nodes.readNode("target", target); + +// AttributeReader<> attribute(reader, "gui"); +// std::string author; +// attribute.readAttribute("author", author); +// int count; +// attribute.readAttribute("count", count); + +// PrintReader print(reader); + +// reader.run(); + + +// for (SmartGraph::NodeIt it(graph); it != INVALID; ++it) { +// std::cout << cost[it] << ' ' << mmap[it] << std::endl; +// } + +// for (SmartGraph::EdgeIt it(graph); it != INVALID; ++it) { +// std::cout << description[it] << std::endl; +// } + +// std::cout << "author: " << author << std::endl; +// std::cout << "count: " << count << std::endl; + +// std::cout << "source cost: " << cost[source] << std::endl; +// std::cout << "target cost: " << cost[target] << std::endl; + +// std::cout.flush(); + } catch (DataFormatError& error) { + std::cerr << error.what() << std::endl; + } + + + return 0; +} diff -r 7ceab500e1f6 -r 1aa71600000c demo/sample.lgf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demo/sample.lgf Fri Jul 01 16:10:46 2005 +0000 @@ -0,0 +1,23 @@ +@nodeset +id +5 +4 +3 +2 +1 +0 +@edgeset + id capacity +4 5 6 8 +3 5 5 8 +2 4 4 5 +1 4 3 8 +1 3 2 5 +0 2 1 10 +0 1 0 10 +@nodes +source 0 +target 5 +@edges +@attributes +@end diff -r 7ceab500e1f6 -r 1aa71600000c doc/getstart.dox --- a/doc/getstart.dox Fri Jul 01 10:33:27 2005 +0000 +++ b/doc/getstart.dox Fri Jul 01 16:10:46 2005 +0000 @@ -27,7 +27,7 @@ \section downloadLEMON How to download LEMON You can download LEMON from the LEMON web site: -http://lemon.cs.elte.hu/dowload.html. +http://lemon.cs.elte.hu/download.html. There you will find released versions in form of .tar.gz files. If you want a developer version (for example you want to contribute in developing the library LEMON) then you might want to use our Subversion @@ -38,7 +38,7 @@ \section installLEMON How to install LEMON -In order to install LEMON you have to do the following +In order to install LEMON you have to do the following steps. Download the tarball (named lemon-x.y.z.tar.gz where \c x,\c y and \c z are numbers indicating the version of the library: in our example @@ -50,15 +50,20 @@ cd lemon-0.3.1 ./configure make -make check #(This is optional, but recomended. It runs a bunch of tests.) +make check #(This is optional, but recommended. It runs a bunch of tests.) make install \endverbatim These commands install LEMON under \c /usr/local (you will need root privileges to be able to install to that directory). If you want to install it to some other place, then -pass the \c --prefix=DIR flag to \c ./configure. In what follows -we will assume that you were able to install to directory +pass the \c --prefix=DIRECTORY flag to \c ./configure, for example: + +\verbatim +./configure --prefix=/home/user1/lemon +\endverbatim + +In what follows we will assume that you were able to install to directory \c /usr/local, otherwise some extra care is to be taken to use the library. diff -r 7ceab500e1f6 -r 1aa71600000c doc/quicktour.dox --- a/doc/quicktour.dox Fri Jul 01 10:33:27 2005 +0000 +++ b/doc/quicktour.dox Fri Jul 01 16:10:46 2005 +0000 @@ -22,7 +22,10 @@ example a length or capacity function defined on the edges. You can do this in LEMON using so called \b maps. You can define a map on the nodes or on the edges of the graph and the value of the map (the range of the function) can be practically almost of any type. Read more about maps \ref maps-page "here". -Some examples are the following (you will find links next to the code fragments that help to download full demo programs: save them on your computer and compile them according to the description in the page about \ref getsart How to start using LEMON): +In this quick tour we want to show you some facilities LEMON library can provide through examples (simple demo programs). The examples will only show part of the functionality, but links will always be given to reach complete details. +You will find links next to the code fragments that help to download full demo programs: save them on your computer and compile them according to the description in the page about \ref getstart "How to start using LEMON". + +Have fun!
  • The first thing to discuss is the way one can create data structures like graphs and maps in a program using LEMON. @@ -79,56 +82,18 @@ (called \c coordinates_x and \c coordinates_y), several edges, an edge map called \c length and two designated nodes (called \c source and \c target). -\todo Maybe another example would be better here. +\todo Maybe a shorter example would be better here. -\code -@nodeset -id coordinates_x coordinates_y -9 447.907 578.328 -8 79.2573 909.464 -7 878.677 960.04 -6 11.5504 938.413 -5 327.398 815.035 -4 427.002 954.002 -3 148.549 753.748 -2 903.889 326.476 -1 408.248 577.327 -0 189.239 92.5316 -@edgeset - length -2 3 901.074 -8 5 270.85 -6 9 601.553 -5 9 285.022 -9 4 408.091 -3 0 719.712 -7 5 612.836 -0 4 933.353 -5 0 778.871 -5 5 0 -7 1 664.049 -5 5 0 -0 9 560.464 -4 8 352.36 -4 9 399.625 -4 1 402.171 -1 2 591.688 -3 8 182.376 -4 5 180.254 -3 1 345.283 -5 4 184.511 -6 2 1112.45 -0 1 556.624 -@nodes -source 1 -target 8 -@end -\endcode +\include route.lgf Finally let us give a simple example that reads a graph from a file and writes -it to another. +it to the standard output. -\todo This is to be done! +\include reader_writer_demo.cc + +See the whole program in file \ref reader_writer_demo.cc. + +\todo This is still under construction!
  • If you want to solve some transportation problems in a network then @@ -139,62 +104,9 @@ \ref lemon::Dijkstra "LEMON Dijkstra class" and it also shows how to define a map on the edges (the length function): -\code - - typedef ListGraph Graph; - typedef Graph::Node Node; - typedef Graph::Edge Edge; - typedef Graph::EdgeMap LengthMap; - - Graph g; - - //An example from Ahuja's book - - Node s=g.addNode(); - Node v2=g.addNode(); - Node v3=g.addNode(); - Node v4=g.addNode(); - Node v5=g.addNode(); - Node t=g.addNode(); - - Edge s_v2=g.addEdge(s, v2); - Edge s_v3=g.addEdge(s, v3); - Edge v2_v4=g.addEdge(v2, v4); - Edge v2_v5=g.addEdge(v2, v5); - Edge v3_v5=g.addEdge(v3, v5); - Edge v4_t=g.addEdge(v4, t); - Edge v5_t=g.addEdge(v5, t); - - LengthMap len(g); - - len.set(s_v2, 10); - len.set(s_v3, 10); - len.set(v2_v4, 5); - len.set(v2_v5, 8); - len.set(v3_v5, 5); - len.set(v4_t, 8); - len.set(v5_t, 8); - - std::cout << "The id of s is " << g.id(s)<< std::endl; - std::cout <<"The id of t is " << g.id(t)<<"."< dijkstra_test(g,len); - - dijkstra_test.run(s); - - - std::cout << "The distance of node t from node s: " << dijkstra_test.dist(t)< If you want to design a network and want to minimize the total length of wires then you might be looking for a minimum spanning tree in an undirected graph. This can be found using the Kruskal algorithm: the -class \ref lemon::Kruskal "LEMON Kruskal class" does this job for you. +function \ref lemon::kruskal "LEMON Kruskal ..." does this job for you. The following code fragment shows an example: Ide Zsuzska fog irni! @@ -336,9 +248,9 @@ The complete program can be found in file \ref lp_maxflow_demo.cc. After compiling run it in the form: -./lp_maxflow_demo < ?????????.lgf +./lp_maxflow_demo < sample.lgf -where ?????????.lgf is a file in the lemon format containing a maxflow instance (designated "source", "target" nodes and "capacity" map on the edges). +where sample.lgf is a file in the lemon format containing a maxflow instance (designated "source", "target" nodes and "capacity" map on the edges).