Next Previous Contents

3.4 Finding all the matchings between two graphs

In case you need to examine all the matching between two graphs, you have to use a different version of the match function.

This version needs a match visitor, that is a callback function which is called everytime a matching is found. The match visitor has four parameters: the number of nodes in the matching, the two arrays of node_id that represent the nodes paired by the algorithm, and an user-provided void pointer which can be used to pass some other useful information to the visitor (for example, a file where the matchings should be stored).

The visitor, after processing the current matching, must return a bool value: if the value is false, the next matching is searched for; else, the search stops.

The match function takes as input parameters a pointer to the initial state, a function pointer to the match visitor, and an optional void * (which defaults to NULL) that will be passed to the visitor. The return value of the match function is the number of examined matchings.

As an example, suppose that you want to save all the matchings on a text file. The code needed to perform this task is:


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

bool my_visitor(int n, node_id ni1[], node_id ni2[], void *usr_data)
  { FILE *f = (FILE *)usr_data;

    // Prints the matched pairs on the file
        int i;
        for(i=0; i<n; i++)
          fprintf(f, "(%hd, %hd) ", ni1[i], ni2[i]);
        fprintf(f, "\n");

        // Return false to search for the next matching
        return false;
  }

int main()
  { // ... here goes the code to build the graphs
    // and to create the initial search state 's0'...

    // Create the output file
        f=fopen("output.txt", "w");

        match(&s0, my_visitor, f);

        fclose(f);
        return 0;
  }


Next Previous Contents