/*
 * This file is part of choco-solver, http://choco-solver.org/
 *
 * Copyright (c) 2019, IMT Atlantique. All rights reserved.
 *
 * Licensed under the BSD 4-clause license.
 *
 * See LICENSE file in the project root for full license information.
 */
package org.chocosolver.util.objects.graphs;

import org.chocosolver.util.objects.setDataStructures.ISet;
import org.chocosolver.util.objects.setDataStructures.SetType;

/**
 * @author Jean-Guillaume Fages, Xavier Lorca
 *         <p/>
 *         Provide an interface for the graph manipulation
 */
public interface IGraph  {


    /**
     * @return the collection of nodes present in the graph
     */
    ISet getNodes();

    /**
     * Adds node x to the node set of the graph
     *
     * @param x a node index
     * @return true iff x was not already present in the graph
     */
    boolean addNode(int x);

    /**
     * Remove node x from the graph
     *
     * @param x a node index
     * @return true iff x was present in the graph
     */
    boolean removeNode(int x);

    /**
     * The maximum number of nodes in the graph
	 * Vertices of the graph belong to [0,getNbMaxNodes()-1]
	 * This quantity is fixed at the creation of the graph
     *
     * @return the maximum number of nodes of the graph
     */
    int getNbMaxNodes();

    /**
     * Get the type of data structures used in the graph
	 *
     * @return the type of data structures used in the graph
     */
    SetType getType();


    /**
     * Get either x's successors or neighbors.
     * <p/>
     * This method enables to capitalize some code but should be called with care
     *
     * @param x a node index
     * @return x's successors if <code>this</code> is directed
     *         x's neighbors otherwise
     */
    ISet getSuccOrNeighOf(int x);

    /**
     * Get either x's predecessors or neighbors.
     * <p/>
     * This method enables to capitalize some code but should be called with care
     *
     * @param x a node index
     * @return x's predecessors if <code>this</code> is directed
     *         x's neighbors otherwise
     */
    ISet getPredOrNeighOf(int x);

    /**
     * If <code>this </code> is directed
     * returns true if and only if arc (x,y) exists
     * Else, if <code>this</code> is undirected
     * returns true if and only if edge (x,y) exists
     * <p/>
     * This method enables to capitalize some code but should be called with care
     *
     * @param x a node index
     * @param y a node index
     */
    boolean isArcOrEdge(int x, int y);

    /**
     * @return true if and only if <code>this</code> is a directed graph
     */
    boolean isDirected();
}

@@ -2652,11 +2652,972 @@
 ected();
+%0A%0A    //***********************************************************************************%0A    // GraphViz%0A    //***********************************************************************************%0A%0A    /**%0A     * Export graph to graphviz format, see http://www.webgraphviz.com/%0A     *%0A     * @return a String encoding the graph to be displayed by graphViz%0A     */%0A    default String graphVizExport() %7B%0A        boolean directed = isDirected();%0A        String arc = directed ? %22 -%3E %22 : %22 -- %22;%0A        StringBuilder sb = new StringBuilder();%0A        sb.append(directed ? %22digraph %22 : %22graph %22).append(%22G%22 + %22%7B%5Cn%22);%0A        sb.append(%22node ; %22);%0A        for (int i : getNodes()) sb.append(i + %22 %22);%0A        sb.append(%22;%5Cn%22);%0A        for (int i : getNodes()) %7B%0A            for (int j : getSuccOrNeighOf(i)) %7B%0A                if (directed %7C%7C i %3C j) sb.append(i + arc + j + %22 ;%5Cn%22);%0A            %7D%0A        %7D%0A        sb.append(%22%7D%22);%0A        return sb.toString();%0A    %7D
 %0A%7D%0A

add graphviz export to graph objects