1 25 38 package org.jgrapht.experimental.isomorphism; 39 40 import java.util.*; 41 42 import org.jgrapht.*; 43 import org.jgrapht.graph.*; 44 45 46 65 public class IsomorphismRelation<V, E> 66 implements GraphMapping<V, E> 67 { 68 69 71 private List<V> vertexList1; 72 private List<V> vertexList2; 73 74 private GraphMapping<V, E> graphMapping = null; 75 76 private Graph<V, E> graph1; 77 private Graph<V, E> graph2; 78 79 81 83 public IsomorphismRelation( 84 List<V> aGraph1vertexArray, 85 List<V> aGraph2vertexArray, 86 Graph<V, E> g1, 87 Graph<V, E> g2) 88 { 89 this.vertexList1 = aGraph1vertexArray; 90 this.vertexList2 = aGraph2vertexArray; 91 this.graph1 = g1; 92 this.graph2 = g2; 93 } 94 95 97 public String toString() 98 { 99 StringBuffer sb = new StringBuffer (); 100 sb.append("vertexList1: ").append( 101 this.vertexList1.toString()); 102 sb.append("\tvertexList2: ").append( 103 this.vertexList2.toString()); 104 return sb.toString(); 105 } 106 107 public V getVertexCorrespondence(V vertex, boolean forward) 108 { 109 if (graphMapping == null) { 111 initGraphMapping(); 112 } 113 114 return graphMapping.getVertexCorrespondence(vertex, forward); 115 } 116 117 public E getEdgeCorrespondence(E edge, boolean forward) 118 { 119 if (graphMapping == null) { 121 initGraphMapping(); 122 } 123 124 return graphMapping.getEdgeCorrespondence(edge, forward); 125 } 126 127 131 private void initGraphMapping() 132 { 133 int mapSize = vertexList1.size(); 134 Map<V, V> g1ToG2 = new HashMap<V, V>(mapSize); 135 Map<V, V> g2ToG1 = new HashMap<V, V>(mapSize); 136 137 for (int i = 0; i < mapSize; i++) { 138 V source = this.vertexList1.get(i); 139 V target = this.vertexList2.get(i); 140 g1ToG2.put(source, target); 141 g2ToG1.put(target, source); 142 } 143 this.graphMapping = 144 new DefaultGraphMapping<V, E>( 145 g1ToG2, 146 g2ToG1, 147 this.graph1, 148 this.graph2); 149 } 150 } 151 | Popular Tags |