Boost logo

Boost Users :

From: Johan Oudinet (johan.oudinet_at_[hidden])
Date: 2008-03-28 07:13:23


Hi,

I read the csr-example.cpp that explain how to use
compressed_sparse_row_graph and output it in graphviz format (.dot),
and I'd like building a csr graph from a file in DOT format.

So I tried using read_graphviz but actually it doesn't work with CSR
graph (see below for my code).

Does someone successfully build a CSR graph from a DOT file ?

Regards,

//===== csr.cc =====
# include <iostream>
# include <string>
# include <fstream>

# include <boost/graph/compressed_sparse_row_graph.hpp>
# include <boost/graph/iteration_macros.hpp>
# include <boost/graph/graphviz.hpp>

struct Node {
  std::string name;
};

int main ()
{
  typedef boost::compressed_sparse_row_graph<boost::directedS, Node> graph_t;

  // Try to read the CSR graph g from foo.dot
  graph_t g;
  std::ifstream in("foo.dot", std::ios::in);
  boost::dynamic_properties dp;
  dp.property ("node_id", boost::get (&Node::name, g));
  bool status = read_graphviz(in, g, dp, "node_id"); // doesn't work,
see below for the error message

  BGL_FORALL_VERTICES (v, g, graph_t)
    std::cout << g[v].name << std::endl;

  BGL_FORALL_EDGES (e, g, graph_t)
    std::cout << g[source (e, g)].name << " -> "
              << g[target (e, g)].name << std::endl;
}
//================

The error message with g++ 4.1.3:
/usr/include/boost/graph/graphviz.hpp:721: error: conversion from
'boost::csr_edge_descriptor<unsigned int, unsigned int>' to non-scalar
type 'std::pair<boost::csr_edge_descriptor<unsigned int, unsigned
int>, bool>' requested

<8==== foo.dot =====
digraph {
 0 -> 3;
 0 -> 4;
 1 -> 3;
 1 -> 4;
 2 -> 3;
 2 -> 4;
 3 -> 4;
}
=================

-- 
Johan Oudinet

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net