public Map<Integer,Integer> findIsomorphism(Graph<? extends Edge> g1,
Graph<? extends Edge> g2) {
// Since the user has asked to find the mapping itself, we'll need to
// keep track of how the vertices are remapped. Note that if the graphs
// are already in canonical order, then these maps will be empty.
TIntIntHashMap g1vMap = new TIntIntHashMap(g1.order());
TIntIntHashMap g2vMap = new TIntIntHashMap(g2.order());
// Remap the graphs so that the vertices are contiguous, filling in a
// backwards mapping so we can recover the isomorphism later.
Graph<? extends Edge> g1mapped = remap(g1, g1vMap);
Graph<? extends Edge> g2mapped = remap(g2, g2vMap);
State state = makeInitialState(g1mapped, g2mapped);
Map<Integer,Integer> isoMapping = new HashMap<Integer,Integer>();
// If we mapped the vertices, we have to unmap the vertices in order
// to identify the isometric pairs.
if (match(state, isoMapping)) {
// Create a new isometric map that will contain the unmapped
// mappings
TIntIntMap fixedIsoMapping = new TIntIntHashMap(isoMapping.size());
for (Map.Entry<Integer,Integer> e : isoMapping.entrySet()) {
int v1 = e.getKey();
v1 = (g1vMap.isEmpty()) ? v1 : g1vMap.get(v1);
int v2 = e.getValue();
v2 = (g2vMap.isEmpty()) ? v2 : g2vMap.get(v2);
fixedIsoMapping.put(v1, v2);
}
return TDecorators.wrap(fixedIsoMapping);
}
else
return Collections.<Integer,Integer>emptyMap();