Package graphmatcher.matcher.komatcher

Source Code of graphmatcher.matcher.komatcher.KOSystemGraphMatcher

package graphmatcher.matcher.komatcher;

import graphmatcher.graph.Edge;
import graphmatcher.graph.Graph;
import graphmatcher.matcher.AbstractMatcher;

import java.util.Arrays;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

public class KOSystemGraphMatcher extends AbstractMatcher {
  public static final String matcherID = "KO_MATCHER";
  private static Logger logger = Logger.getLogger(KOSystemGraphMatcher.class);

  private int[] edgeMatching;

  static {
    logger.setLevel(Level.OFF);
  }

  public KOSystemGraphMatcher(Graph pattern, Graph template) {
    super(pattern, template);
  }

  protected int[] getMatching() {
    long time1 = System.currentTimeMillis();
    boolean[][] match1on1 = new boolean[pattern.virtualEdges().length][template.virtualEdges().length];

    KOSystem koSystem = new KOSystem(pattern, template, matchingOptions);

    int numberOfVirtualEdgesInPattern = pattern.virtualEdges().length;
    int numberOfVirtualEdgesInTemplate = template.virtualEdges().length;

    logger.info("Erstelle initiale CandidateBundles");
    int matchingCandidates = 0;

    int[][] virtualConnectedComponentEdgeIDs = pattern.getVirtualConnectedComponentsEdgeIDs();

    for (int vccID = 0; vccID < virtualConnectedComponentEdgeIDs.length; vccID++) {
      int[] ccEdgeIds = virtualConnectedComponentEdgeIDs[vccID];
      for (int ccEdgeID = 0; ccEdgeID < ccEdgeIds.length; ccEdgeID++) {
        int patternEdgeID = ccEdgeIds[ccEdgeID];

        CandidateBundle bundle = new CandidateBundle(pattern, template, patternEdgeID, match1on1,
            matchingOptions);
        Edge e = pattern.virtualEdges()[patternEdgeID];
        Edge gesuchtePatternEdge = new Edge(32, 22);
        if (e.equals(gesuchtePatternEdge)) {
          System.out.println("PatternEdge gefunden.");
        }
        double bestRating = 0;
        int bestTemplateEdgeID = -1;

        for (int templateEdgeID = 0; templateEdgeID < numberOfVirtualEdgesInTemplate; templateEdgeID++) {
          Edge e2 = template.virtualEdges()[templateEdgeID];
          Edge gesuchteTemplateEdge = new Edge(24, 18);
          if (e.equals(gesuchtePatternEdge) && e2.equals(gesuchteTemplateEdge)) {
            System.out.println("Kantenpaar gefunden");
          }

          double rating = EdgeRater.computeInitialEdgeRating(pattern, patternEdgeID, template,
              templateEdgeID, match1on1, matchingOptions);
          if (rating > bestRating) {
            bestRating = rating;
            bestTemplateEdgeID = templateEdgeID;
          }
          if (rating > matchingOptions.getCandidateLimit()) {
            Candidate candidate = new Candidate(pattern, template, patternEdgeID, templateEdgeID,
                match1on1);
            bundle.addCandidate(candidate);
            logger.debug(candidate + ": " + rating);
            matchingCandidates++;
          }
        }
        if (bundle.getSize() == 0 && bestRating > 0) {
          Candidate candidate = new Candidate(pattern, template, patternEdgeID, bestTemplateEdgeID,
              match1on1);
          bundle.addCandidate(candidate);
          logger.debug("*** Notkandidat *** : " + candidate + ": " + bestRating);
          matchingCandidates++;
        }
        if (bundle.getSize() > 0) {
          bundle.mergeSimilarCandidates();
          koSystem.addCandidateBundle(bundle, patternEdgeID, vccID);
        } else {
          logger.debug("Bundle von " + pattern.virtualEdges()[patternEdgeID] + " zu klein");
        }
      }
    }

    long time2 = System.currentTimeMillis();
    logger.debug("Anzahl virtueller Kanten im Pattern: " + pattern.virtualEdges().length);
    logger.debug("Anzahl virtueller Kanten im Template: " + template.virtualEdges().length);
    logger.info("Kandidaten: " + matchingCandidates);

    long[] times = koSystem.mergeBundles();

    long time3 = System.currentTimeMillis();
    logger.debug("Zeitmessung:");
    logger.debug("Initialisierung: " + (time2 - time1) + " ms");
    logger.debug("Matching: " + (time3 - time2) + " ms");
    logger.debug(" -Zusammenhangsk.-Merge: " + times[0] + " ms");
    logger.debug(" -Voting: " + times[1] + " ms");
    logger.debug(" -Ausz�hlung: " + times[2] + " ms");
    logger.info("Gesamtdauer: " + (time3 - time1) + " ms");
    try {
      CandidateBundle lastBundle = koSystem.getLastBundle();
      edgeMatching = lastBundle.getEdgeMatching();
      return lastBundle.getMatching(match1on1);
    } catch (IllegalStateException ise) {
      int[] result = new int[pattern.getNumberOfVertices()];
      Arrays.fill(result, -1);
      return result;
    }
  }

  @Override
  public String getName() {
    return "KO-System-Matcher";
  }

  @Override
  public String getMatcherID() {
    return matcherID;
  }

  @Override
  protected byte getMatchingType() {
    return AbstractMatcher.EDGE_MATCHING;
  }

  @Override
  protected int[] getEdgeMatching() {
    return edgeMatching;
  }
}
TOP

Related Classes of graphmatcher.matcher.komatcher.KOSystemGraphMatcher

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.