Package graphmatcher.matcher.simple

Source Code of graphmatcher.matcher.simple.SimpleMatcher

package graphmatcher.matcher.simple;

import graphmatcher.graph.Graph;
import graphmatcher.graph.Vertex;
import graphmatcher.helper.DistanceHelper;
import graphmatcher.matcher.AbstractMatcher;

import java.awt.Point;

public class SimpleMatcher extends AbstractMatcher {
  public static final String matcherID = "SIMPLE_MATCHER";

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

  protected int[] getMatching() {
    int[] matching = new int[pattern.getNumberOfVertices()];
    Point patternCenter = pattern.getCenter();
    Point templateCenter = template.getCenter();
    for (int i = 0; i < pattern.getNumberOfVertices(); i++) {
      Vertex patternVertex = pattern.vertices()[i];
      Point patternVertexPoint = new Point(patternVertex.x - patternCenter.x, patternVertex.y
          - patternCenter.y);
      int bestTemplateVertexID = -1;
      double minDist = Double.MAX_VALUE;
      for (int j = 0; j < template.getNumberOfVertices(); j++) {
        Vertex templateVertex = template.vertices()[j];
        Point templateVertexPoint = new Point(templateVertex.x - templateCenter.x, templateVertex.y
            - templateCenter.y);
        double dist = DistanceHelper.getDistance(patternVertexPoint, templateVertexPoint);
        if (dist < minDist) {
          minDist = dist;
          bestTemplateVertexID = j;
        }
      }
      matching[i] = bestTemplateVertexID;
    }
    return matching;
  }

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

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

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

  @Override
  protected int[] getEdgeMatching() {
    throw new IllegalStateException("Kein EdgeMatching beim SimpleMatcher!");
  }
}
TOP

Related Classes of graphmatcher.matcher.simple.SimpleMatcher

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.