Class UndirectedGraph
- java.lang.Object
-
- org.chocosolver.util.objects.graphs.UndirectedGraph
-
-
Constructor Summary
Constructors Constructor Description UndirectedGraph(int n, SetType type, boolean allNodes)Creates an empty (non-backtrackable) undirected graph.UndirectedGraph(Model model, int n, SetType type, boolean allNodes)Creates an empty backtrable undirected graph.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddEdge(int x, int y)Add edge (x,y) to the graphbooleanaddNode(int x)Adds node x to the node set of the graphbooleanedgeExists(int x, int y)test whether edge (x,y) is in the graph or notintgetNbMaxNodes()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 graphISetgetNeighOf(int x)Get neighbors of node xISetgetNodes()ISetgetPredOrNeighOf(int x)Get either x's predecessors or neighbors.ISetgetSuccOrNeighOf(int x)Get either x's successors or neighbors.SetTypegetType()Get the type of data structures used in the graphbooleanisArcOrEdge(int x, int y)Ifthisis directed returns true if and only if arc (x,y) exists Else, ifthisis undirected returns true if and only if edge (x,y) existsbooleanisDirected()booleanremoveEdge(int x, int y)Remove edge (x,y) from the graphbooleanremoveNode(int x)Remove node x from the graphStringtoString()
-
-
-
Constructor Detail
-
UndirectedGraph
public UndirectedGraph(Model model, int n, SetType type, boolean allNodes)
Creates an empty backtrable undirected graph. Allocates memory for n nodes (but they should then be added explicitly, unless allNodes is true).- Parameters:
model- model providing the backtracking environmentn- max number of nodestype- data structure storing for node neighborsallNodes- true iff all nodes will always remain in the graph
-
UndirectedGraph
public UndirectedGraph(int n, SetType type, boolean allNodes)Creates an empty (non-backtrackable) undirected graph. Allocates memory for n nodes (but they should then be added explicitly, unless allNodes is true).- Parameters:
n- max number of nodestype- data structure used for storing node neighborsallNodes- true iff all nodes will always remain in the graph
-
-
Method Detail
-
getNbMaxNodes
public int getNbMaxNodes()
Description copied from interface:IGraphThe 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- Specified by:
getNbMaxNodesin interfaceIGraph- Returns:
- the maximum number of nodes of the graph
-
getNodes
public ISet getNodes()
-
getType
public SetType getType()
Description copied from interface:IGraphGet the type of data structures used in the graph
-
addNode
public boolean addNode(int x)
Description copied from interface:IGraphAdds node x to the node set of the graph
-
removeNode
public boolean removeNode(int x)
Description copied from interface:IGraphRemove node x from the graph- Specified by:
removeNodein interfaceIGraph- Parameters:
x- a node index- Returns:
- true iff x was present in the graph
-
addEdge
public boolean addEdge(int x, int y)Add edge (x,y) to the graph- Parameters:
x- a node indexy- a node index- Returns:
- true iff (x,y) was not already in the graph
-
edgeExists
public boolean edgeExists(int x, int y)test whether edge (x,y) is in the graph or not- Parameters:
x- a node indexy- a node index- Returns:
- true iff edge (x,y) is in the graph
-
isArcOrEdge
public boolean isArcOrEdge(int x, int y)Description copied from interface:IGraphIfthisis directed returns true if and only if arc (x,y) exists Else, ifthisis undirected returns true if and only if edge (x,y) exists This method enables to capitalize some code but should be called with care- Specified by:
isArcOrEdgein interfaceIGraph- Parameters:
x- a node indexy- a node index
-
removeEdge
public boolean removeEdge(int x, int y)Remove edge (x,y) from the graph- Parameters:
x- a node indexy- a node index- Returns:
- true iff (x,y) was in the graph
-
getNeighOf
public ISet getNeighOf(int x)
Get neighbors of node x- Parameters:
x- node index- Returns:
- neighbors of x (predecessors and/or successors)
-
getPredOrNeighOf
public ISet getPredOrNeighOf(int x)
Description copied from interface:IGraphGet either x's predecessors or neighbors. This method enables to capitalize some code but should be called with care- Specified by:
getPredOrNeighOfin interfaceIGraph- Parameters:
x- a node index- Returns:
- x's predecessors if
thisis directed x's neighbors otherwise
-
getSuccOrNeighOf
public ISet getSuccOrNeighOf(int x)
Description copied from interface:IGraphGet either x's successors or neighbors. This method enables to capitalize some code but should be called with care- Specified by:
getSuccOrNeighOfin interfaceIGraph- Parameters:
x- a node index- Returns:
- x's successors if
thisis directed x's neighbors otherwise
-
isDirected
public boolean isDirected()
- Specified by:
isDirectedin interfaceIGraph- Returns:
- true if and only if
thisis a directed graph
-
-