protected Map<ElementExpression, FlowElement> findMapping( FinderContext finderContext, PlannerContext plannerContext, ElementGraph elementGraph ) { State state = new State( finderContext, plannerContext, matchExpression.getSearchOrder(), matchExpression.getGraph(), elementGraph ); Map<Integer, Integer> vertexMap = new LinkedHashMap<>(); boolean match = match( state, vertexMap ); if( !match ) return Collections.emptyMap(); Map<ElementExpression, FlowElement> result = new LinkedHashMap<>(); for( Map.Entry<Integer, Integer> entry : vertexMap.entrySet() ) result.put( state.getMatcherNode( entry.getKey() ), state.getElementNode( entry.getValue() ) ); return result; }
LOG.trace( "begin matching with state: {}", state ); if( state.isGoal() ) return true; if( state.isDead() ) return false; boolean found = false; while( !found && ( next = state.nextPair( n1, n2 ) ) != null ) LOG.trace( "begin matching pair: N1: {}, N2: {}", n1, n2 ); boolean feasiblePair = state.isFeasiblePair( n1, n2 ); State copy = state.copy(); copy.addPair( n1, n2 ); found = match( copy, vertexMap ); for( Map.Entry<Integer, Integer> entry : copy.getVertexMapping().entrySet() ) LOG.trace( "match for feasible pair: N1: {}, N2: {}", n1, n2 ); vertexMap.putAll( copy.getVertexMapping() ); copy.backTrack();
protected boolean areCompatibleEdges( int v1, int v2, int v3, int v4 ) { List<ScopeExpression> matchers = matchGraph.getAllEdgesList( v1, v2 ); // if there is any edge between the nodes, capture all and return true if( matchers.size() == 1 && matchers.get( 0 ).acceptsAll() ) { if( LOG.isDebugEnabled() ) debugCompatibleEdges( elementGraph.getAllEdgesList( v3, v4 ), v1, v2, matchers ); return true; } List<Scope> scopes = elementGraph.getAllEdgesList( v3, v4 ); Collection<Scope> results = areCompatibleEdges( plannerContext, elementGraph.getElementGraph(), matchers, scopes ); if( LOG.isDebugEnabled() && results != null ) debugCompatibleEdges( results, v1, v2, matchers ); return results != null; }
assert core2[ node2 ] == NULL_NODE; if( !areCompatibleNodes( node1, node2 ) ) return false; if( !elementGraph.containsEdge( node2, other2 ) || !areCompatibleEdges( node1, other1, node2, other2 ) ) return false; if( !elementGraph.containsEdge( other2, node2 ) || !areCompatibleEdges( other1, node1, other2, node2 ) ) return false;
public State copy() { return new State( this ); }