Next Previous Contents

3.3 Finding the first matching between two graphs

In order to start the matching process, you need to call the match function declared in match.h . Actually there are two overloaded match functions; the first stops after a matching is found, while the other iterates over all the possible different matchings between the two graphs.

If you are interested only in the first matching found, you need to declare two arrays of node_id to store the pairs of corresponding nodes; the dimension of each array must be at least equal to the number of nodes in the smallest of the two graphs.

The function to be used has one input parameter, i.e. a pointer to the initial state, described in the previous subsection. The function returns a bool value which is false if no matching has been found, and has three output parameters: the number of matched nodes (which for the matching relations implemented up to now is always equal to the number of nodes of the first graph), and the two arrays of matched node ids. Corresponding elements of the two arrays contain the ids of nodes paired by the matching algorithm.

For example, the following code would invoke the matcher and print the result:


#include <argraph.h>
#include <match.h>

#define MAXNODES 200

int main()
{
//... here the two graphs and the inistial state 
//    should be created ...

  int n;
  node_id ni1[MAXNODES], ni2[MAXNODES];

  if (!match(&s0, &n, ni1, ni2))
    { printf("No matching found!\n");
      return 1;
    }

  printf("Found a matching with %d nodes:\n", n);
  int i;
  for(i=0; i<n; i++)
    printf("\tNode %hd of graph 1 is paired with node %hd of graph 2\n",
               ni1[i], ni2[i]);
  return 0;
}


Next Previous Contents