COIN-OR::LEMON - Graph Library

Changeset 1530:d99c3c84f797 in lemon-0.x for demo


Ignore:
Timestamp:
07/04/05 15:08:31 (19 years ago)
Author:
athos
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2021
Message:

Doc.

Location:
demo
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • demo/dijkstra_demo.cc

    r1528 r1530  
    4545    len.set(v5_t, 8);
    4646
     47    std::cout << "This program is a simple demo of the LEMON Dijkstra class."<<std::endl;
     48    std::cout << "We calculate the shortest path from node s to node t in a graph."<<std::endl;
     49    std::cout <<std::endl;
     50
     51
    4752    std::cout << "The id of s is " << g.id(s)<< ", the id of t is " << g.id(t)<<"."<<std::endl;
    4853
  • demo/hello_lemon.cc

    r1526 r1530  
    66  typedef lemon::ListGraph Graph;
    77  typedef Graph::EdgeIt EdgeIt;
     8  typedef Graph::Edge Edge;
    89  typedef Graph::NodeIt NodeIt;
     10  typedef Graph::Node Node;
     11  typedef Graph::EdgeMap<int> LengthMap;
    912  using lemon::INVALID;
    1013
    1114  Graph g;
    1215 
    13   for (int i = 0; i < 3; i++)
    14     g.addNode();
     16  Node s=g.addNode();
     17  Node v2=g.addNode();
     18  Node v3=g.addNode();
     19  Node v4=g.addNode();
     20  Node v5=g.addNode();
     21  Node t=g.addNode();
     22
     23  Edge s_v2=g.addEdge(s, v2);
     24  Edge s_v3=g.addEdge(s, v3);
     25  Edge v2_v4=g.addEdge(v2, v4);
     26  Edge v2_v5=g.addEdge(v2, v5);
     27  Edge v3_v5=g.addEdge(v3, v5);
     28  Edge v4_t=g.addEdge(v4, t);
     29  Edge v5_t=g.addEdge(v5, t);
    1530 
    16   for (NodeIt i(g); i!=INVALID; ++i)
    17     for (NodeIt j(g); j!=INVALID; ++j)
    18       if (i != j) g.addEdge(i, j);
     31  LengthMap length(g);
     32
     33  length.set(s_v2, 10);
     34  length.set(s_v3, 10);
     35  length.set(v2_v4, 5);
     36  length.set(v2_v5, 8);
     37  length.set(v3_v5, 5);
     38  length.set(v4_t, 8);
     39  length.set(v5_t, 8);
    1940
    2041  std::cout << "Hello World!" << std::endl;
     
    3253    std::cout << " (" << g.id(g.source(i)) << "," << g.id(g.target(i)) << ")";
    3354  std::cout << std::endl;
     55  std::cout <<  std::endl;
     56
     57  std::cout << "There is a map on the edges (length)!" << std::endl;
     58  std::cout <<  std::endl;
     59  for (EdgeIt i(g); i!=INVALID; ++i)
     60    std::cout << "length(" << g.id(g.source(i)) << "," << g.id(g.target(i)) << ")="<<length[i]<<std::endl;
     61
     62  std::cout << std::endl;
     63
    3464}
  • demo/lp_demo.cc

    r1513 r1530  
    2424 //The following example is taken from the documentation of the GLPK library.
    2525 //See it in the GLPK reference manual and among the GLPK sample files (sample.c)
     26
     27  //A default solver is taken
    2628  LpDefault lp;
    2729  typedef LpDefault::Row Row;
     
    3739  Col x3 = lp.addCol();
    3840
    39   //One solution
    40   //   Row p = lp.addRow();
    41   //   Row q = lp.addRow();
    42   //   Row r = lp.addRow();
    43   //   lp.setRow(p,x1+x2+x3 <=100); 
    44   //   lp.setRow(q,10*x1+4*x2+5*x3<=600); 
    45   //   lp.setRow(r,2*x1+2*x2+6*x3<=300); 
    46 
    47   //A more elegant one
    4841  //Constraints
    4942  lp.addRow(x1+x2+x3 <=100); 
     
    7063  }
    7164
     65  //End of LEMON style code
    7266
    7367  //Here comes the same problem written in C using GLPK API routines
  • demo/reader_writer_demo.cc

    r1528 r1530  
    1616    SmartGraph::EdgeMap<int> cap(graph);
    1717    reader.readEdgeMap("capacity",cap);
    18 //     reader.readNode("source",s).readNode("target",t)
    19 //       .readEdgeMap("capacity",cap).run();
    2018    reader.run();
    2119
     
    3129    writer.run();
    3230     
    33 //     LemonReader reader(std::cin);
    34 
    35 //     NodeSetReader<SmartGraph> nodeset(reader, graph);
    36 //     SmartGraph::NodeMap<int> cost(graph);
    37 //     nodeset.readMap("cost", cost);
    38 //     SmartGraph::NodeMap<char> mmap(graph);
    39 //     nodeset.readMap("mmap", mmap);
    40 
    41 //     EdgeSetReader<SmartGraph> edgeset(reader, graph, nodeset);
    42 //     SmartGraph::EdgeMap<std::string> description(graph);
    43 //     edgeset.readMap<QuotedStringReader>("description", description);
    44 
    45 //     NodeReader<SmartGraph> nodes(reader, nodeset);
    46 //     SmartGraph::Node source;
    47 //     nodes.readNode("source", source);
    48 //     SmartGraph::Node target;
    49 //     nodes.readNode("target", target);
    50 
    51 //     AttributeReader<> attribute(reader, "gui");
    52 //     std::string author;
    53 //     attribute.readAttribute<LineReader>("author", author);
    54 //     int count;
    55 //     attribute.readAttribute("count", count);
    56 
    57 //     PrintReader print(reader);
    58 
    59 //     reader.run();
    60 
    61 
    62 //     for (SmartGraph::NodeIt it(graph); it != INVALID; ++it) {
    63 //       std::cout << cost[it] << ' ' << mmap[it] << std::endl;
    64 //     }
    65 
    66 //     for (SmartGraph::EdgeIt it(graph); it != INVALID; ++it) {
    67 //       std::cout << description[it] << std::endl;
    68 //     }
    69 
    70 //     std::cout << "author: " << author << std::endl;
    71 //     std::cout << "count: " << count << std::endl;
    72 
    73 //     std::cout << "source cost: " << cost[source] << std::endl;
    74 //     std::cout << "target cost: " << cost[target] << std::endl;
    75 
    76 //     std::cout.flush();
    7731  } catch (DataFormatError& error) {
    7832    std::cerr << error.what() << std::endl;
  • demo/route.lgf

    r1435 r1530  
    12120       189.239 92.5316
    1313@edgeset
    14                 length 
    15 2       3       901.074
    16 8       5       270.85 
    17 6       9       601.553
    18 5       9       285.022
    19 9       4       408.091
    20 3       0       719.712
    21 7       5       612.836
    22 0       4       933.353
    23 5       0       778.871
    24 5       5       0       
    25 7       1       664.049
    26 5       5       0       
    27 0       9       560.464
    28 4       8       352.36 
    29 4       9       399.625
    30 4       1       402.171
    31 1       2       591.688
    32 3       8       182.376
    33 4       5       180.254
    34 3       1       345.283
    35 5       4       184.511
    36 6       2       1112.45
    37 0       1       556.624
     14                length  id     
     152       3       901.074 0       
     168       5       270.85  1       
     176       9       601.553 2       
     185       9       285.022 3       
     199       4       408.091 4       
     203       0       719.712 5       
     217       5       612.836 6       
     220       4       933.353 7       
     235       0       778.871 8       
     245       5       0       9       
     257       1       664.049 10     
     265       5       0       11     
     270       9       560.464 12     
     284       8       352.36  13     
     294       9       399.625 14     
     304       1       402.171 15     
     311       2       591.688 16     
     323       8       182.376 17     
     334       5       180.254 18     
     343       1       345.283 19     
     355       4       184.511 20     
     366       2       1112.45 21     
     370       1       556.624 22     
    3838@nodes
    3939source  1       
    4040target  8       
     41@edges
     42@attributes
    4143@end
  • demo/sample.lgf

    r1528 r1530  
    1 @nodeset 
    2 id     
    3 5       
    4 4       
    5 3       
    6 2       
    7 1       
    8 0       
    9 @edgeset 
    10                 id      capacity       
    11 4       5       6       8       
    12 3       5       5       8       
    13 2       4       4       5       
    14 1       4       3       8       
    15 1       3       2       5       
    16 0       2       1       10     
    17 0       1       0       10     
    18 @nodes 
     1@nodeset
     2id      coordinates_x   coordinates_y
     35       796.398 208.035
     44       573.002 63.002
     53       568.549 401.748
     62       277.889 68.476
     71       288.248 397.327
     80       102.239 257.532
     9@edgeset
     10                id      capacity
     114       5       6       8
     123       5       5       8
     132       4       4       5
     141       4       3       8
     151       3       2       5
     160       2       1       10
     170       1       0       10
     18@nodes
    1919source 0
    2020target 5
Note: See TracChangeset for help on using the changeset viewer.