2 * Copyright (c) 2003-2005 The BISON Project
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 2 as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 package peersim.graph;
21 import java.util.Collection;
24 * A general graph interface. It follows the following model:
25 * the graph has n nodes which are indexed from 0 to n-1.
26 * The parameters of operators refer to indices only.
27 * Implementations might return objects that represent the
28 * nodes or edges, although this is not required.
30 * Undirected graphs are modelled by the interface as directed graphs in which
31 * every edge (i,j) has a corresponding reverse edge (j,i).
33 public interface Graph {
36 * Returns true if there is a directed edge between node i
39 boolean isEdge(int i, int j);
42 * Returns a collection view to all outgoing edges from
43 * i. The collection should ideally be unmodifiable.
44 * In any case, modifying the returned collection is not safe and
45 * may result in unspecified behavior.
47 Collection<Integer> getNeighbours(int i);
50 * Returns the node object associated with the index. Optional
53 Object getNode(int i);
56 * Returns the edge object associated with the index. Optional
59 Object getEdge(int i, int j);
62 * The number of nodes in the graph.
67 * Returns true if the graph is directed otherwise false.
72 * Sets given edge, returns true if it did not exist before.
74 * undirected, sets the edge (j,i) as well. Optional operation.
76 public boolean setEdge(int i, int j);
79 * Removes given edge, returns true if it existed before. If the graph is
80 * undirected, removes the edge (j,i) as well. Optional operation.
82 public boolean clearEdge(int i, int j);
85 * Returns the degree of the given node. If the graph is directed,
88 public int degree(int i);