doc/quicktour.dox
changeset 1514 c9b9bc63db4e
parent 1511 d6b95a59da26
child 1517 b303c1741c9a
equal deleted inserted replaced
6:3b0eab7f096d 7:53a8d40141bb
    16 graphs then you might find it useful to use our library LEMON. LEMON 
    16 graphs then you might find it useful to use our library LEMON. LEMON 
    17 defines various graph concepts depending on what you want to do with the 
    17 defines various graph concepts depending on what you want to do with the 
    18 graph: a very good description can be found in the page
    18 graph: a very good description can be found in the page
    19 about \ref graphs "graphs".
    19 about \ref graphs "graphs".
    20 
    20 
    21 You will also want to assign data to the edges or nodes of the graph, for example a length or capacity function defined on the edges. You can do this in LEMON using so called \ref maps "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".
    21 You will also want to assign data to the edges or nodes of the graph, for
       
    22 example a length or capacity function defined on the edges. You can do this in
       
    23 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".
    22 
    24 
    23 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):
    25 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):
    24 
    26 
    25 - First we give two examples that show how to instantiate a graph. The
    27 <ul>
       
    28 <li> First we give two examples that show how to instantiate a graph. The
    26 first one shows the methods that add nodes and edges, but one will
    29 first one shows the methods that add nodes and edges, but one will
    27 usually use the second way which reads a graph from a stream (file).
    30 usually use the second way which reads a graph from a stream (file).
    28 -# The following code fragment shows how to fill a graph with data. It creates a complete graph on 4 nodes. The type Listgraph is one of the LEMON graph types: the typedefs in the beginning are for convenience and we will suppose them later as well.
    31 <ol>
       
    32 <li>The following code fragment shows how to fill a graph with data. It creates a complete graph on 4 nodes. The type Listgraph is one of the LEMON graph types: the typedefs in the beginning are for convenience and we will suppose them later as well.
    29  \code
    33  \code
    30   typedef ListGraph Graph;
    34   typedef ListGraph Graph;
    31   typedef Graph::NodeIt NodeIt;
    35   typedef Graph::NodeIt NodeIt;
    32 
    36 
    33   Graph g;
    37   Graph g;
    40       if (i != j) g.addEdge(i, j);
    44       if (i != j) g.addEdge(i, j);
    41  \endcode 
    45  \endcode 
    42 
    46 
    43 See the whole program in file \ref helloworld.cc.
    47 See the whole program in file \ref helloworld.cc.
    44 
    48 
    45 If you want to read more on the LEMON graph structures and concepts, read the page about \ref graphs "graphs". 
    49     If you want to read more on the LEMON graph structures and concepts, read the page about \ref graphs "graphs". 
    46 
    50 
    47 -# The following code shows how to read a graph from a stream (e.g. a file). LEMON supports the DIMACS file format: it can read a graph instance from a file 
    51 <li> The following code shows how to read a graph from a stream (e.g. a file). LEMON supports the DIMACS file format: it can read a graph instance from a file 
    48 in that format (find the documentation of the DIMACS file format on the web). 
    52 in that format (find the documentation of the DIMACS file format on the web). 
    49 \code
    53 \code
    50 Graph g;
    54 Graph g;
    51 std::ifstream f("graph.dim");
    55 std::ifstream f("graph.dim");
    52 readDimacs(f, g);
    56 readDimacs(f, g);
    53 \endcode
    57 \endcode
    54 One can also store network (graph+capacity on the edges) instances and other things in DIMACS format and use these in LEMON: to see the details read the documentation of the \ref dimacs.h "Dimacs file format reader".
    58 One can also store network (graph+capacity on the edges) instances and other things in DIMACS format and use these in LEMON: to see the details read the documentation of the \ref dimacs.h "Dimacs file format reader".
    55 
    59 
    56 
    60 </ol>
    57 - If you want to solve some transportation problems in a network then 
    61 <li> If you want to solve some transportation problems in a network then 
    58 you will want to find shortest paths between nodes of a graph. This is 
    62 you will want to find shortest paths between nodes of a graph. This is 
    59 usually solved using Dijkstra's algorithm. A utility
    63 usually solved using Dijkstra's algorithm. A utility
    60 that solves this is  the \ref lemon::Dijkstra "LEMON Dijkstra class".
    64 that solves this is  the \ref lemon::Dijkstra "LEMON Dijkstra class".
    61 The following code is a simple program using the \ref lemon::Dijkstra "LEMON
    65 The following code is a simple program using the \ref lemon::Dijkstra "LEMON
    62 Dijkstra class" and it also shows how to define a map on the edges (the length
    66 Dijkstra class" and it also shows how to define a map on the edges (the length
   127 results. 
   131 results. 
   128 You can do much more with the Dijkstra class, for example you can run it step
   132 You can do much more with the Dijkstra class, for example you can run it step
   129 by step and gain full control of the execution. For a detailed description, see the documentation of the \ref lemon::Dijkstra "LEMON Dijkstra class".
   133 by step and gain full control of the execution. For a detailed description, see the documentation of the \ref lemon::Dijkstra "LEMON Dijkstra class".
   130 
   134 
   131 
   135 
   132 - If you want to design a network and want to minimize the total length
   136 <li> If you want to design a network and want to minimize the total length
   133 of wires then you might be looking for a <b>minimum spanning tree</b> in
   137 of wires then you might be looking for a <b>minimum spanning tree</b> in
   134 an undirected graph. This can be found using the Kruskal algorithm: the 
   138 an undirected graph. This can be found using the Kruskal algorithm: the 
   135 class \ref lemon::Kruskal "LEMON Kruskal class" does this job for you.
   139 class \ref lemon::Kruskal "LEMON Kruskal class" does this job for you.
   136 The following code fragment shows an example:
   140 The following code fragment shows an example:
   137 
   141 
   138 Ide Zsuzska fog irni!
   142 Ide Zsuzska fog irni!
   139 
   143 
   140 - 
   144 <li>Many problems in network optimization can be formalized by means of a
       
   145 linear programming problem (LP problem, for short). In our library we decided
       
   146 not to write an LP solver, since such packages are available in the commercial
       
   147 world just as well as in the open source world, and it is also a difficult
       
   148 task to compete these. Instead we decided to develop an interface that makes
       
   149 it easier to use these solvers together with LEMON. So far we have an
       
   150 interface for the commercial LP solver software \b CLPLEX (developed by ILOG)
       
   151 and for the open source solver \b GLPK (a shorthand for Gnu Linear Programming
       
   152 Toolkit). 
       
   153 
       
   154 We will show two examples, the first one shows how simple it is to formalize
       
   155 and solve an LP problem in LEMON, while the second one shows how LEMON
       
   156 facilitates solving network optimization problems using LP solvers.
       
   157 
       
   158 <ol>
       
   159 <li>The following code shows how to solve an LP problem using the LEMON lp
       
   160 interface. 
   141 
   161 
   142 \code
   162 \code
   143 
   163 
       
   164   //A default solver is taken
       
   165   LpDefault lp;
       
   166   typedef LpDefault::Row Row;
       
   167   typedef LpDefault::Col Col;
       
   168   
       
   169 
       
   170   //This will be a maximization
       
   171   lp.max();
       
   172 
       
   173   //We add coloumns (variables) to our problem
       
   174   Col x1 = lp.addCol();
       
   175   Col x2 = lp.addCol();
       
   176   Col x3 = lp.addCol();
       
   177 
       
   178   //Constraints
       
   179   lp.addRow(x1+x2+x3 <=100);  
       
   180   lp.addRow(10*x1+4*x2+5*x3<=600);  
       
   181   lp.addRow(2*x1+2*x2+6*x3<=300);  
       
   182   //Nonnegativity of the variables
       
   183   lp.colLowerBound(x1, 0);
       
   184   lp.colLowerBound(x2, 0);
       
   185   lp.colLowerBound(x3, 0);
       
   186   //Objective function
       
   187   lp.setObj(10*x1+6*x2+4*x3);
       
   188   
       
   189   //Call the routine of the underlying LP solver
       
   190   lp.solve();
       
   191 
       
   192   //Print results
       
   193   if (lp.primalStatus()==LpSolverBase::OPTIMAL){
       
   194     printf("Z = %g; x1 = %g; x2 = %g; x3 = %g\n", 
       
   195 	   lp.primalValue(), 
       
   196 	   lp.primal(x1), lp.primal(x2), lp.primal(x3));
       
   197   }
       
   198   else{
       
   199     std::cout<<"Optimal solution not found!"<<std::endl;
       
   200   }
       
   201 
       
   202 
   144 \endcode
   203 \endcode
   145 
   204 
       
   205 See the whole code in \ref lp_demo.cc.
       
   206 
       
   207 <li>The second example shows how easy it is to formalize a network
       
   208 optimization problem as an LP problem using the LEMON LP interface.
       
   209 
       
   210 </ol>
       
   211 </ul>
   146 
   212 
   147 */
   213 */