src/work/deba/dijkstra_test_generator.cpp
author hegyi
Fri, 01 Apr 2005 09:43:52 +0000
changeset 1288 6cc7b573b7b5
permissions -rw-r--r--
Graph displayer is now displaying nodes. Edges remain still undisplayed yet.
deba@1210
     1
#include <iostream>
deba@1210
     2
#include <vector>
deba@1210
     3
deba@1210
     4
#include <cmath>
deba@1210
     5
#include <cstdlib>
deba@1210
     6
deba@1210
     7
#include <lemon/smart_graph.h>
deba@1210
     8
#include <lemon/graph_writer.h>
deba@1210
     9
deba@1210
    10
using namespace lemon;
deba@1210
    11
using namespace std;
deba@1210
    12
deba@1210
    13
int main(int argc, const char *argv[]) {
deba@1210
    14
  typedef SmartGraph Graph;
deba@1210
    15
  typedef Graph::Node Node;
deba@1210
    16
  typedef Graph::Edge Edge;
deba@1210
    17
deba@1210
    18
  typedef Graph::EdgeMap<int> CapacityMap;
deba@1210
    19
deba@1210
    20
  const int n = argc > 1 ? atoi(argv[1]) : 1000;
deba@1210
    21
  const int e = argc > 2 ? atoi(argv[2]) : (int)(n * log(n));
deba@1210
    22
  const int m = argc > 3 ? atoi(argv[3]) : 100;
deba@1210
    23
deba@1210
    24
  Graph graph;
deba@1210
    25
  CapacityMap capacity(graph);
deba@1210
    26
  vector<Node> nodes;
deba@1210
    27
deba@1210
    28
  for (int i = 0; i < n; ++i) {
deba@1210
    29
    nodes.push_back(graph.addNode());
deba@1210
    30
  }
deba@1210
    31
  for (int i = 0; i < e; ++i) {
deba@1210
    32
    int s = (int)(n * (double)rand() / (RAND_MAX + 1.0));
deba@1210
    33
    int t = (int)(n * (double)rand() / (RAND_MAX + 1.0));
deba@1210
    34
    int c = (int)(m * (double)rand() / (RAND_MAX + 1.0));
deba@1210
    35
    Edge edge = graph.addEdge(nodes[s], nodes[t]);
deba@1210
    36
    capacity[edge] = c;
deba@1210
    37
  }
deba@1210
    38
  int start = (int)(n * (double)rand() / (RAND_MAX + 1.0));
deba@1210
    39
  writeGraph(cout, graph, capacity, nodes[start]);
deba@1210
    40
  return 0;
deba@1210
    41
}