public class DirectedGraph extends Object implements IGraph
Constructor and Description |
---|
DirectedGraph(int n,
SetType type,
boolean allNodes)
Creates an empty graph.
|
DirectedGraph(Solver solver,
int n,
SetType type,
boolean allNodes)
Creates an empty backtrable graph of n nodes
Allocates memory for n nodes (but they should then be added explicitly,
unless allNodes is true).
|
Modifier and Type | Method and Description |
---|---|
boolean |
addArc(int from,
int to)
add arc (from,to) to the graph
|
boolean |
addNode(int x)
Adds node x to the node set of the graph
|
boolean |
arcExists(int from,
int to)
Test whether arc (from,to) exists or not in the graph
|
void |
duplicate(Solver solver,
gnu.trove.map.hash.THashMap<Object,Object> identitymap) |
int |
getNbMaxNodes()
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
|
ISet |
getNodes() |
ISet |
getPredOf(int x)
Get predecessors of node x
|
ISet |
getPredOrNeighOf(int x)
Get either x's predecessors or neighbors.
|
ISet |
getSuccOf(int x)
Get successors of node x
|
ISet |
getSuccOrNeighOf(int x)
Get either x's successors or neighbors.
|
SetType |
getType()
Get the type of data structures used in the graph
|
boolean |
isArcOrEdge(int from,
int to)
If
this is directed
returns true if and only if arc (x,y) exists
Else, if this is undirected
returns true if and only if edge (x,y) exists
This method enables to capitalize some code but should be called with care |
boolean |
isDirected() |
boolean |
removeArc(int from,
int to)
remove arc (from,to) from the graph
|
boolean |
removeNode(int x)
Remove node x from the graph
|
String |
toString() |
public DirectedGraph(int n, SetType type, boolean allNodes)
n
- maximum number of nodestype
- data structure to use for representing node successors and predecessorsallNodes
- true iff all nodes must always remain present in the graph.
i.e. The node set is fixed to [0,n-1] and will never changepublic DirectedGraph(Solver solver, int n, SetType type, boolean allNodes)
solver
- solver providing the backtracking environmentn
- maximum number of nodestype
- data structure to use for representing node successors and predecessorsallNodes
- true iff all nodes must always remain present in the graphpublic int getNbMaxNodes()
IGraph
getNbMaxNodes
in interface IGraph
public ISet getNodes()
public SetType getType()
IGraph
public boolean addNode(int x)
IGraph
public boolean removeNode(int x)
IGraph
removeNode
in interface IGraph
x
- a node indexpublic boolean removeArc(int from, int to)
from
- a node indexto
- a node indexpublic boolean arcExists(int from, int to)
from
- a node indexto
- a node indexpublic boolean isArcOrEdge(int from, int to)
IGraph
this
is directed
returns true if and only if arc (x,y) exists
Else, if this
is undirected
returns true if and only if edge (x,y) exists
This method enables to capitalize some code but should be called with careisArcOrEdge
in interface IGraph
from
- a node indexto
- a node indexpublic boolean isDirected()
isDirected
in interface IGraph
this
is a directed graphpublic boolean addArc(int from, int to)
from
- a node indexto
- a node indexpublic ISet getSuccOf(int x)
x
- node indexpublic ISet getSuccOrNeighOf(int x)
IGraph
getSuccOrNeighOf
in interface IGraph
x
- a node indexthis
is directed
x's neighbors otherwisepublic ISet getPredOf(int x)
x
- node indexpublic ISet getPredOrNeighOf(int x)
IGraph
getPredOrNeighOf
in interface IGraph
x
- a node indexthis
is directed
x's neighbors otherwiseCopyright © 2015. All rights reserved.