Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share
    
LineGraph[#, EdgeLabels -> PropertyValue[#, EdgeLabels]] &[ilGrafo] –  Öskå Aug 29 '13 at 14:36

2 Answers 2

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

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

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

share

This site is currently not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .