org.jgrapht.experimental.isomorphism.PermutationIsomorphismInspector Maven / Gradle / Ivy
/* ==========================================
* JGraphT : a free Java graph-theory library
* ==========================================
*
* Project Info: http://jgrapht.sourceforge.net/
* Project Creator: Barak Naveh (http://sourceforge.net/users/barak_naveh)
*
* (C) Copyright 2003-2008, by Barak Naveh and Contributors.
*
* This program and the accompanying materials are dual-licensed under
* either
*
* (a) the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation, or (at your option) any
* later version.
*
* or (per the licensee's choosing)
*
* (b) the terms of the Eclipse Public License v1.0 as published by
* the Eclipse Foundation.
*/
/* -----------------
* PermutationIsomorphismInspector.java
* -----------------
* (C) Copyright 2005-2008, by Assaf Lehr and Contributors.
*
* Original Author: Assaf Lehr
* Contributor(s): -
*
* $Id: PermutationIsomorphismInspector.java 485 2006-06-26 09:12:14Z
* perfecthash $
*
* Changes
* -------
*/
package org.jgrapht.experimental.isomorphism;
import java.util.*;
import org.jgrapht.*;
import org.jgrapht.experimental.equivalence.*;
import org.jgrapht.experimental.permutation.*;
/**
* Checks every possible permutation.
*
* It does not uses the graph topology to enhance the performance. It is
* recommended to use only if there cannot be a useful division into equivalence
* sets.
*
* @author Assaf
* @since Jul 29, 2005
*/
class PermutationIsomorphismInspector
extends AbstractExhaustiveIsomorphismInspector
{
/**
* @param graph1
* @param graph2
* @param vertexChecker eq. group checker for vertexes. If null,
* UniformEquivalenceComparator will be used as default (always return true)
* @param edgeChecker eq. group checker for edges. If null,
* UniformEquivalenceComparator will be used as default (always return true)
*/
public PermutationIsomorphismInspector(
Graph graph1,
Graph graph2,
// XXX hb 060128: FOllowing parameter may need Graph
EquivalenceComparator> vertexChecker,
EquivalenceComparator> edgeChecker)
{
super(graph1, graph2, vertexChecker, edgeChecker);
}
/**
* Constructor which uses the default comparators.
*
* @see AbstractExhaustiveIsomorphismInspector#AbstractExhaustiveIsomorphismInspector(Graph,
* Graph)
*/
public PermutationIsomorphismInspector(
Graph graph1,
Graph graph2)
{
super(graph1, graph2);
}
/**
* Creates the permutation iterator, not dependant on equality group, or the
* other vertexset.
*
* @param vertexSet1 FIXME Document me
* @param vertexSet2 FIXME Document me
*
* @return the permutation iterator
*/
protected CollectionPermutationIter createPermutationIterator(
Set vertexSet1,
Set vertexSet2)
{
return new CollectionPermutationIter(vertexSet2);
}
/**
* FIXME Document me FIXME Document me
*
* @param vertexSet1 FIXME Document me
* @param vertexSet2 FIXME Document me
*
* @return FIXME Document me
*/
protected boolean areVertexSetsOfTheSameEqualityGroup(
Set vertexSet1,
Set vertexSet2)
{
if (vertexSet1.size() != vertexSet2.size()) {
return false;
}
Iterator iter2 = vertexSet2.iterator();
// only check hasNext() of one , cause they are of the same size
for (Iterator iter1 = vertexSet1.iterator(); iter1.hasNext();) {
V vertex1 = iter1.next();
V vertex2 = iter2.next();
if (!this.vertexComparator.equivalenceCompare(
vertex1,
vertex2,
this.graph1,
this.graph2))
{
return false;
}
}
return true;
}
}
// End PermutationIsomorphismInspector.java