

%
% NOTE -- ONLY EDIT THE .Rnw FILE!!!  The .tex file is
% likely to be overwritten.
%
\documentclass[12pt]{article}

\usepackage{amsmath}
\usepackage[authoryear,round]{natbib}
\usepackage{hyperref}


\textwidth=6.2in
\textheight=8.5in
%\parskip=.3cm
\oddsidemargin=.1in
\evensidemargin=.1in
\headheight=-.3in

\newcommand{\scscst}{\scriptscriptstyle}
\newcommand{\scst}{\scriptstyle}

\bibliographystyle{plainnat} 
 
\begin{document}
%\setkeys{Gin}{width=0.55\textwidth}

\section*{Issues with edge labeling in Rgraphviz}

Here's a network diagram from the boost book

\setkeys{Gin}{width=.83\textwidth}
\includegraphics{ospf}
@

Note that there are many double edges with distinct
weights depending on direction of edge.

The dot file can be transformed to gxl by graphviz dot2gxl,
and the gxl has to be edited (changing {\tt label} to {\tt weights})
for a successful read by fromGXL.
<<>>=
library(graph)
ospf <- fromGXL(file("ospf.gxl"))
print(edgeWeights(ospf)[1:6])
@
It seems to me that this graph object has the right contents.


The wlabs function will obtain a suitable edgeLabels argument
for Rgraphviz::plot:
<<>>=
wlabs <- function (g) 
{
    ee <- edges(g)
    ww <- edgeWeights(g)
    ans <- ee
    for (i in 1:length(ee)) {
        ans[[i]] <- as.character(round(ww[[i]], 2))
        names(ans[[i]]) <- ee[[i]]
    }
    ans
}
print(wlabs(ospf)[1:6])
@
The plot that we get from Rgraphviz shows the bidirectional
edges as doubleheaded arrows and gives only one of the
relevant weights.
\setkeys{Gin}{width=.83\textwidth}
<<fig=TRUE>>=
library(Rgraphviz)
plot(ospf,edgeLabels=wlabs(ospf))
@

It seems to me we may need to add an option to give
rendering of separate edges for bidirectional connections,
allowing separate edgelabels for such connections.  The
graphNEL representation contains the necessary information.
\end{document}
