Exact (Error-Correcting) Graph Matching Algorithm - algorithm

I'm looking for an inexact graph matching algorithm on graphs with labeled vertices and labeled, directed edges. My task is to detect changes to two graphs to display them to the developer (think subversion diff). I've already implemented an optimization algorithm based on tabu search (this), but I can't get the algorithm to consider my edge labels. My graphs have at most 120 vertices and 200 edges, so I might get away with a slower but simpler to implement algorithm.
Here is an example for your viewing pleasure, :

Since no one has proposed an existing algorithm, I'll try to invent one...
For each vertex, you can calculate its "signature" by concatenating its label with the labels of all adjacent edges. For consistency, sort the labels alphabetically. Since the edges are directed, concatenate incoming and outgoing edges separately.
These signatures can be used to detect changes in the set of vertices. First, find corresponding vertices with the same signature in the first and the second graph. Remaining unpaired vertices are added vertices, removed vertices, vertices with changed labels, vertices with changed edge connections, and vertices whose edges' labels were changed. You can associate them by comparing their signatures and selecting best matches using some string matching algorithm. Apparently you will have to introduce some critical degree of similarity to distinguish "it's the same vertex with many changed properties" from "it's a new vertex with some accidental signature similarity".
Arrange all vertices of the first graph in an array, in any order. Create another array of the same size. Put the matching vertices of the second graph into the second array at positions corresponding to the first array; do this for all exactly matched vertices and all modified vertices. For first graph vertices which don't have a match in the second graph (deleted vertices), leave the array cells empty. Then, for second graph vertices which don't have a match in the first graph (new vertices), add these vertices to the end of the second array and expand the first array with the corresponding number of empty cells.
Now, when vertices of a graph are listed in an array, the edges can be represented as a 2-dimensional array. If an edge is going from the i-th vertex to the j-th vertex, put its label into the (i,j) cell of the array.
Do this for both graphs. Since you have constructed two vertex arrays of the same size, you get two 2-dimensional arrays of the same size, with a one-to-one correspondence. Comparing these two arrays in a straightforward way allows you to detect added edges, removed edges and edges with changed labels.

Related

representive Vertex cycle cover

This problem may be related to this post.
This problem also asked here but with a different taste.
Consider an (undirected) square graph with a periodic boundary condition. Then find a complete cycle graph with length equal to 4. now I want to assign a unique representative to each cycle from its elements. Therefore in a square graph with n_v vertex i will find n_f=n_v 4-cycles and n_v representative for the cycles. For the square graph, everything is simple. just assign the bottom left vertex of each plaque(4-cycles).
(i just show first 4-cycle)
Now, I want to generalize it for other structures. consider (undirected) kagome graph with proper boundary condition,
(here I just show 3 distinct cycles)
In this case for assigning a vertex to cycles cover, you need three different length cycles. which show by similar color with the assigned vertex. However, now I want to generalize this to other complicated graphs. I want to know is this problem has a name and about its possibility or algorithm. For example, we cannot do it in a triangular graph:
This problem solved here.
I)Let show all faces and vertices by \alpha_i, where i contain
vertices and faces.
II) make a graph which relates \alpha_i (from i
in face group) to \alpha_j (to j in vertex group), if j(vortex)
belong to i(face).
III) find the independent edge set of this
graph gives for any vortex a face.
Please see here for additional information.

Graph data structure selection

I need to implement an algorithm that works on planar graphs and I want to select an appropriate data structure to represent them.
The vertices are stored in an array, each with an associated pair of coordinates,
An edge has an associated polyline between its end vertices, with an arbitrary number of intermediate points (possibly none), stored in sequence in an auxiliary array.
The edges are undirected (if a=>b exists, then b=>a exists),
The following primitive operations must be supported:
adding an edge between two vertices designated by their indexes,
enumerating all edges originating from a given vertex (and recursively, all paths from a given vertex),
for a given edge, follow the associated polyline until the end vertex.
I am looking for a data structure that is space efficient O(V + E) and avoids data redundancy.
What would you use ? Candidates that I see are adjacency lists, DCEL, winged edges, but I may be missing one. I guess that quad edges is overkill.

Efficient Way to construct triangles from Edges/Lines?

Lets say I have a set of points and I have lines/edges between them. All of these edges create non-overlapping triangles within the convex hull of my points. All points are connected to triangles.
How can I efficiently check which points are part of which triangle? I could check incident points of each edge and gradually construct a triple of points, but that sounds awefully slow (o(n^2)?).
Is there something like linesweep or so to do that?
cheers.
If you have a 2-dimensional set-up like you described, then you have a fully triangulated planar graph (no intersecting edges when you exclude the endpoints) which spans the convex hull of your points. In this case, if you sort the edges around each vertex circularly according to the angle they make with the vertex, then you know for sure that each pair of adjacent edges makes a triangle. Furthermore, every triangle can be found this way if you perform this procedure for each vertex. Each triangle will be found 3 times when you iterate over all vertices. You can either use a hash table to detect duplicates, or sort all your triangles when you are done to identify duplicates. If you use hash table, then the overall complexity if you have V vertices is O(V log d), where d is the maximum degree of a vertex (because the total number of edges is linear in the number of vertices because you have a planar graph). So absolute worst-case is O(V log V), which is the same worst-case if you sort all triangles to find duplicates (because the max number of triangles is also linear in the number of vertices). The only caveat to make this work is that you need to know the neighbor vertices (i.e. the incidental edges) for each vertex.
The edges define an undirected graph G and the triangles are the set of cycles in G with length=3.
Geometric triangulations typically have relatively low nodal degree (degree d is the number of edges adjacent to each node, d<=10 is typical for geometric triangulations) and, as such, here is a reasonably efficient O(n*d^3) algorithm that can be used to construct the set of triangles.
Setup a graph-like data structure, supporting access to the list of edges adjacent to each node.
Iterate over all nodes. Consider all pairs of edges adjacent to a given node i. For a given pair of edges adjacent to i, we have a potential nodal triplet i,j,k. This triplet is a triangle if there is an edge joining nodes j,k, which can be checked by scanning the edge lists of j,k.
Duplicate triangles will be generated by a naive implementation of (2). Maintain a hash table of triangles to reject duplicate triplets as they're considered.
I've assumed that the edges define a valid disjoint triangulation, being non-intersecting, etc.
Hope this helps.

Find minimum vertex Cover for bipartite graph given the maximum matching

I seem to have found an algorithm but am having trouble understanding it, I was wondering if any of you knew the generic outline of the algorithm.
Here is the link to the algorithm I found on page 2
http://www.cse.iitb.ac.in/~sundar/cs435/lecture23.pdf
Algorithm is simple as that:
Find unmatched vertex, mark it as not included in minimum vertex cover.
Mark all matched neighbours of this vertex as included in minimum vertex cover.
Treat all mates of vertexes from previous step as unmatched vertexes and repeat step 1.
If recursion ended, repeat from step 1 (that is case of several connected components of graph).
If there is no unmatched vertexes, take all remaining pairs and mark them any way you like (remember that one vertex in pair has to
be included in minimum vertex cover, and other one has to be not
included).
first you should know bipartite graph, two sets of vertexes, and edges, ok, you know that now.
then you need to choose some vertexes from the two sets, to cover all the edges. As long as one vertex is chosen, all the edges link to it is covered. Now your task is to choose the minimum number of vertexes, to cover all the edges.
the principle means, the minimum number you need equals to the number of max matching pairs.

Perfect matching in a tree

I came across a definition of Perfect matching: a set of edges that touches each node exactly once.
However, i didnt really understand the definition. Can somebody give me an example of any such edge. Or may be point me towards some reference that does.
I tried to google but it didnt give me any example.
A perfect matching set is any set of edges in a graph where every vertex in the graph is touched by exactly one edge in the matching set. If you consider a graph with 4 vertices connected so that the graph resembles a square, there are two perfect matching sets, which are the pairs of parallel edges. Since all the vertices are touched exactly once by either pair. If you think about a graph with 3 vertices connected like a triangle, there is no perfect matching set, because if you take any pair of edges, one vertex is touched twice, but a single edge will always miss a vertex.
http://en.wikipedia.org/wiki/Perfect_matching
Your question mentions a tree, but a tree is just a special type of graph, so it still works the same.
In fact, any graph with odd number of vertices cannot have a perfect matching edge set.
N edges => 2 * N vertices. Since no vertex once touched should not be touched again.

Resources