4
$\begingroup$

I have a graph with labels on the edges:

ilGrafo=Graph[{1 <-> 2, 1 <-> 3, 2 <-> 3, 3 <-> 4, 4 <-> 5, 4 <-> 6, 4 <-> 7,  6 <-> 7}, 
 EdgeLabels -> {1 <-> 2 -> "A", 1 <-> 3 -> "B", 2 <-> 3 -> "C", 
   3 <-> 4 -> "E", 4 <-> 5 -> "E", 4 <-> 6 -> "E", 4 <-> 7 -> "G", 6 <-> 7 -> "H"}]

I would like to obtain the LineGraph[ilGrafo] with the corresponding edge name on the vertices, but I am not able to find the way.

$\endgroup$
  • 1
    $\begingroup$ LineGraph[#, EdgeLabels -> PropertyValue[#, EdgeLabels]] &[ilGrafo] $\endgroup$ – Öskå Aug 29 '13 at 14:36
2
$\begingroup$

I guess that somone has to answer it.

ilGrafo=Graph[
  {1 <-> 2, 1 <-> 3, 2 <-> 3, 3 <-> 4, 4 <-> 5, 4 <-> 6, 4 <-> 7, 6 <-> 7},
  EdgeLabels -> {1 <-> 2 -> "A", 1 <-> 3 -> "B", 2 <-> 3 -> "C", 3 <-> 4 -> "E", 
                 4 <-> 5 -> "E", 4 <-> 6 -> "E", 4 <-> 7 -> "G", 6 <-> 7 -> "H"}]

giving

ilGrafo

In order to keep the EdgeLabels while applying LineGraph you can use:

LineGraph[#, EdgeLabels -> PropertyValue[#, EdgeLabels]] &[ilGrafo]

giving

enter image description here

$\endgroup$
  • $\begingroup$ Thanks for the answer, however the ilGrafo edge labels do not correspond to the LineGraph vertex labels. $\endgroup$ – Roberto D'Autilia Sep 1 '13 at 7:18
1
$\begingroup$

I think the function should be like this:

LabeledLineGraph[graph_] :=  
Module[{m = IncidenceMatrix[graph], length = EdgeCount[graph]},  
AdjacencyGraph[(Transpose[m].m - 2 IdentityMatrix[length]),  
VertexLabels -> Thread@Rule[Range@length, EdgeList[graph]/.PropertyValue[graph,EdgeLabels]]]]  

The result of LabeledLineGraph[ilGrafo] is as follows:

enter image description here

$\endgroup$
0
$\begingroup$

Edge names and labels placed above and below the associated vertex in LineGraph:

labelF = SetProperty[VertexReplace[LineGraph[#, VertexLabels->"Name", ImagePadding -> 25],
  Thread[Range[EdgeCount @ #] -> (EdgeList[#])]], VertexLabels -> 
  (# -> Placed[{##}, {Above, Below}] & @@@ PropertyValue[#, EdgeLabels])]&;  

labelF @ ilGrafo

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.