Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
peersimgrid release 1.0
[simgrid.git] / contrib / psg / src / peersim / graph / Graph.java
1 /*
2  * Copyright (c) 2003-2005 The BISON Project
3  *
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.
7  *
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.
12  *
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.
16  *
17  */
18
19 package peersim.graph;
20
21 import java.util.Collection;
22
23 /**
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.
29 *
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).
32 */
33 public interface Graph {
34
35         /**
36         * Returns true if there is a directed edge between node i
37         * and node j.
38         */
39         boolean isEdge(int i, int j);
40
41         /**
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.
46         */
47         Collection<Integer> getNeighbours(int i);
48
49         /**
50         * Returns the node object associated with the index. Optional
51         * operation.
52         */
53         Object getNode(int i);
54         
55         /**
56         * Returns the edge object associated with the index. Optional
57         * operation.
58         */
59         Object getEdge(int i, int j);
60
61         /**
62         * The number of nodes in the graph.
63         */
64         int size();
65
66         /**
67         * Returns true if the graph is directed otherwise false.
68         */
69         boolean directed();
70
71         /**
72         * Sets given edge, returns true if it did not exist before.
73         * If the graph is
74         * undirected, sets the edge (j,i) as well. Optional operation.
75         */
76         public boolean setEdge(int i, int j);
77
78         /**
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.
81         */
82         public boolean clearEdge(int i, int j);
83
84         /**
85         * Returns the degree of the given node. If the graph is directed,
86         * returns out degree.
87         */
88         public int degree(int i);
89 }