001/* Copyright (C) 2013 TU Dortmund
002 * This file is part of AutomataLib, http://www.automatalib.net/.
003 * 
004 * AutomataLib is free software; you can redistribute it and/or
005 * modify it under the terms of the GNU Lesser General Public
006 * License version 3.0 as published by the Free Software Foundation.
007 * 
008 * AutomataLib is distributed in the hope that it will be useful,
009 * but WITHOUT ANY WARRANTY; without even the implied warranty of
010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
011 * Lesser General Public License for more details.
012 * 
013 * You should have received a copy of the GNU Lesser General Public
014 * License along with AutomataLib; if not, see
015 * http://www.gnu.de/documents/lgpl.en.html.
016 */
017package net.automatalib.util.graphs.traversal;
018
019import net.automatalib.commons.util.Holder;
020
021/**
022 * Visitor interface for graph traversals.
023 * <p>
024 * This interface declares methods that are called upon basic graph traversal actions.
025 *  
026 * @author Malte Isberner <malte.isberner@gmail.com>
027 *
028 * @param <N> node class
029 * @param <E> edge class
030 * @param <D> user data class
031 */
032public interface GraphTraversalVisitor<N, E, D> {
033        /**
034         * Called when a node is processed <i>initially</i>.
035         * @param initialNode the node that is processed
036         * @return the action to perform
037         */
038        public GraphTraversalAction processInitial(N initialNode, Holder<D> outData);
039        
040        /**
041         * Called when the exploration of a node is started.
042         * @param node the node which's exploration is about to be started
043         * @param data the user data associated with this node
044         * @return the action to perform
045         */
046        public boolean startExploration(N node, D data);
047        
048        /**
049         * Called when the exploration of a node is finished.
050         * @param node the node which's exploration is being finished
051         * @param data the user data associated with this node
052         */
053        public void finishExploration(N node, D inData);
054        
055        /**
056         * Called when an edge is processed.
057         * @param srcNode the source node
058         * @param srcData the user data associated with the source node
059         * @param edge the edge that is being processed
060         * @return the action to perform
061         */
062        public GraphTraversalAction processEdge(N srcNode, D srcData, E edge, N tgtNode, Holder<D> outData);
063        
064        public void backtrackEdge(N srcNode, D srcData, E edge, N tgtNode, D tgtData);
065}