-
-
Notifications
You must be signed in to change notification settings - Fork 370
Line Graphs study for TRSP
What is a Line Graph?
Given a graph G
, its line graph L(G)
is a graph such that:-
-
each vertex of
L(G)
represents an edge ofG
. -
two vertices of
L(G)
are adjacent if and only if their corresponding edges share a common endpoint inG
.
The following figures show a graph (left, with blue vertices) and its line graph (right, with green vertices).
-
Cost associated with the nodes
-
Consider the following graph with nodes having costs:- The above graph is taken from the sample data
The transformed Line Graph:-
Each node of the transformed graph is an edge from the original graph. Here
[1,2]
denotes the node in the transformed graph which was an edge from node1
to node2
in the original graph.Each edge of the transformed graph is a tuple of nodes
(n1, n2, n3)
wheren1
,n2
andn3
are nodes from the original graph such that there was an edge fromn1 -> n2
and another edge fromn2 -> n3
.Thus, the connection
[1,4] -> [3, 4]
goes through the vertex4
as it is made up of(1, 4, 3)
tuple which has an associated cost of6
therefore the corresponding edge in the above graph gets a cost of6
.
-
-
Cost associated with the edges
-
Consider the following graph with edges having costs:- The above graph is taken from the sample data
The transformed Line Graph:-
Here, the cost associated with an edge in the original graph moves to the corresponding nodes in the transformed Line Graph.
-
Here is the code that converts a graph into its Line Graph(This graph is limited to very small graphs with nodes <= 10).