|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--jdsl.core.ref.AbstractPositionalContainer
|
+--jdsl.graph.ref.AbstractGraph
|
+--jdsl.map.ref.IncidenceListOrderedGraph
Implements the OrderedGraph interface by a list of vertices, each of which has a circular sequence of edges. The graph also has a list of edges, in order to support certain operation more easily and quickly (for example, elements(), isElement(), size()).
The sequences store as their elements the positions of the graph. So verts_ stores ILOGVertex's as its elements, edges_ stores ILOGEdge's. The positions in turn know their position within the appropriate sequence, so that when the user gives the graph a vertex or an edge, the graph can extract that information in constant-time.
That is a source of some difficulty for the edges, since they are contained within the graph's edgelist, as well as within its two endvertices' incidence lists. This was resolved by requiring the caller to identify itself, so that the edge can then know which position to report.
This class does not claim to be the most efficient graph data structure possible: asymptotic improvements are possible in certain methods, and large constant factors could be fixed. Some places to improve:
| Inner classes inherited from class jdsl.graph.ref.AbstractGraph |
AbstractGraph.OO_to_O_MergerIterator |
| Constructor Summary | |
IncidenceListOrderedGraph()
|
|
| Method Summary | |
Edge |
anEdge()
O(1) |
Edge |
anIncidentEdge(Vertex v)
O(1) |
Edge |
anIncidentEdge(Vertex v,
int edgetype)
O(degree) |
boolean |
areIncident(Vertex v,
Edge e)
O(1) |
Edge |
attachVertex(Vertex v,
java.lang.Object vertexElement,
java.lang.Object edgeElement)
|
Edge |
attachVertex(Vertex v,
Order order,
Edge e,
java.lang.Object vertexInfo,
java.lang.Object edgeInfo)
O(1) |
Edge |
attachVertexFrom(Vertex v,
java.lang.Object vertexElement,
java.lang.Object edgeElement)
|
Edge |
attachVertexFrom(Vertex origin,
Order order,
Edge e,
java.lang.Object vertexInfo,
java.lang.Object edgeInfo)
O(1) |
Edge |
attachVertexTo(Vertex v,
java.lang.Object vertexElement,
java.lang.Object edgeElement)
|
Edge |
attachVertexTo(Vertex destination,
Order order,
Edge e,
java.lang.Object vertexInfo,
java.lang.Object edgeInfo)
O(1) |
Vertex |
aVertex()
O(1) |
boolean |
contains(Accessor p)
O(1) |
int |
degree(Vertex v)
O(1) |
int |
degree(Vertex v,
int edgetype)
O(degree) |
Vertex |
destination(Edge e)
O(1) |
EdgeIterator |
edges()
O(m) |
ObjectIterator |
elements()
O(n+m) |
Vertex[] |
endVertices(Edge e)
O(1) |
EdgeIterator |
incidentEdges(Vertex v)
O(degree) |
EdgeIterator |
incidentEdges(Vertex v,
int edgetype)
O(degree) |
Edge |
insertDirectedEdge(Vertex v1,
Order order1,
Edge e1,
Vertex v2,
Order order2,
Edge e2,
java.lang.Object info)
O(1) |
Edge |
insertDirectedEdge(Vertex v1,
Vertex v2,
java.lang.Object element)
|
Edge |
insertEdge(Vertex v1,
Order order1,
Edge e1,
Vertex v2,
Order order2,
Edge e2,
java.lang.Object info)
O(1) |
Edge |
insertEdge(Vertex v1,
Vertex v2,
java.lang.Object element)
|
Vertex |
insertVertex(java.lang.Object elt)
O(1) |
boolean |
isDirected(Edge e)
O(1) |
void |
makeUndirected(Edge e)
O(1) |
void |
moveEndVertex(Edge e1,
Vertex v1,
Vertex v2,
Order order,
Edge e2)
O(1) |
Container |
newContainer()
O(1) |
Edge |
nextIncidentEdge(Vertex v,
Edge e)
O(1) |
Edge |
nextIncidentEdge(Vertex v,
Edge e,
int edgetype)
O(degree) |
int |
numEdges()
O(1) |
int |
numVertices()
O(1) |
Vertex |
opposite(Vertex v,
Edge e)
O(1) |
Vertex |
origin(Edge e)
O(1) |
Edge |
prevIncidentEdge(Vertex v,
Edge e)
O(1) |
Edge |
prevIncidentEdge(Vertex v,
Edge e,
int edgetype)
O(degree) |
java.lang.Object |
removeEdge(Edge e)
O(1) |
java.lang.Object |
removeVertex(Vertex v)
O(degree) |
java.lang.Object |
replaceElement(Accessor p,
java.lang.Object newElement)
O(1) |
void |
reverseDirection(Edge e)
O(1) |
void |
setDirectionFrom(Edge e,
Vertex v)
O(1) |
void |
setDirectionTo(Edge e,
Vertex v)
O(1) |
Vertex |
splitEdge(Edge e,
java.lang.Object info)
O(1) |
Edge |
splitVertex(Vertex v,
Edge e1,
Edge e2,
java.lang.Object edgeinfo)
O(degree) |
Edge |
unsplitEdge(Vertex v,
java.lang.Object info)
O(1) |
Vertex |
unsplitVertex(Edge e,
java.lang.Object vertexinfo)
O(degree1+degree2) |
VertexIterator |
vertices()
O(n) |
| Methods inherited from class jdsl.graph.ref.AbstractGraph |
aCommonVertex, aConnectingEdge, adjacentVertices, adjacentVertices, areAdjacent, areAdjacent, connectingEdges, directedEdges, positions, size, undirectedEdges |
| Methods inherited from class jdsl.core.ref.AbstractPositionalContainer |
isEmpty, swapElements |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface jdsl.graph.api.InspectableGraph |
aCommonVertex, aConnectingEdge, adjacentVertices, adjacentVertices, areAdjacent, areAdjacent, connectingEdges, directedEdges, undirectedEdges |
| Methods inherited from interface jdsl.core.api.InspectablePositionalContainer |
positions |
| Methods inherited from interface jdsl.core.api.InspectableContainer |
isEmpty, size |
| Methods inherited from interface jdsl.core.api.PositionalContainer |
swapElements |
| Constructor Detail |
public IncidenceListOrderedGraph()
| Method Detail |
public boolean contains(Accessor p)
throws InvalidAccessorException
contains in interface InspectableContainerjdsl.core.api.InspectableContainerInvalidAccessorException - if a is nullpublic ObjectIterator elements()
elements in interface InspectableContainerjdsl.core.api.InspectableContainerpublic Container newContainer()
newContainer in interface Containerjdsl.core.api.Container
public java.lang.Object replaceElement(Accessor p,
java.lang.Object newElement)
throws InvalidAccessorException
replaceElement in interface Containerjdsl.core.api.Containera - Accessor in this containernewElement - to be stored at aInvalidAccessorException - if a is null or does not
belong to this containerpublic int numVertices()
numVertices in interface InspectableGraphjdsl.graph.api.InspectableGraphpublic VertexIterator vertices()
vertices in interface InspectableGraphjdsl.graph.api.InspectableGraphpublic Vertex aVertex()
aVertex in interface InspectableGraphjdsl.graph.api.InspectableGraphpublic int numEdges()
numEdges in interface InspectableGraphjdsl.graph.api.InspectableGraphpublic EdgeIterator edges()
edges in interface InspectableGraphjdsl.graph.api.InspectableGraphpublic Edge anEdge()
anEdge in interface InspectableGraphjdsl.graph.api.InspectableGraph
public int degree(Vertex v)
throws InvalidAccessorException
degree in interface InspectableGraphjdsl.graph.api.InspectableGraphv - a vertexvInvalidAccessorException - if v is
not contained in this graph
public int degree(Vertex v,
int edgetype)
throws InvalidAccessorException
degree in interface InspectableGraphjdsl.graph.api.InspectableGraphv - a vertexedgetype - A constant from the EdgeDirection interfacevInvalidAccessorException - if v is
not contained in this graphEdgeDirection
public EdgeIterator incidentEdges(Vertex v)
throws InvalidAccessorException
incidentEdges in interface InspectableGraphjdsl.graph.api.InspectableGraphv - a vertexvInvalidAccessorException - if v is not
contained in this graph
public EdgeIterator incidentEdges(Vertex v,
int edgetype)
throws InvalidAccessorException
incidentEdges in interface InspectableGraphjdsl.graph.api.InspectableGraphv - a vertexedgetype - A constant from the EdgeDirection interfacevInvalidAccessorException - if v is not
contained in this graphEdgeDirection
public boolean areIncident(Vertex v,
Edge e)
throws InvalidAccessorException
areIncident in interface InspectableGraphjdsl.graph.api.InspectableGraphv - a vertexe - an edgev and e are incident,
i.e., whether v is an endvertex of eInvalidAccessorException - if either v or
e is not contained in this graph
public Vertex[] endVertices(Edge e)
throws InvalidAccessorException
endVertices in interface InspectableGraphjdsl.graph.api.InspectableGraphe - an edgee;
if e is directed, the first element of the array is the origin of e
and the second element is the destination of eInvalidAccessorException - if e is not
contained in this graph
public Vertex opposite(Vertex v,
Edge e)
opposite in interface InspectableGraphjdsl.graph.api.InspectableGraphv - one endvertex of ee - an edgee different from vInvalidVertexException - if v is not an
endvertex of eInvalidAccessorException - if v or e
is not contained in this graph
public boolean isDirected(Edge e)
throws InvalidAccessorException
isDirected in interface InspectableGraphjdsl.graph.api.InspectableGraphe - an edgetrue if e is directed,
false otherwiseInvalidAccessorException - if e is not
contained in this graph
public Vertex origin(Edge e)
throws InvalidEdgeException
origin in interface InspectableGraphjdsl.graph.api.InspectableGraphe - an edgee, if e is directedInvalidEdgeException - if e is undirectedInvalidAccessorException - if e is not
contained in this graph
public Vertex destination(Edge e)
throws InvalidEdgeException
destination in interface InspectableGraphjdsl.graph.api.InspectableGraphe - an edgee, if
e is directedInvalidEdgeException - if e is undirectedInvalidAccessorException - if e is not
contained in this graph
public Edge anIncidentEdge(Vertex v)
throws InvalidAccessorException
anIncidentEdge in interface InspectableGraphjdsl.graph.api.InspectableGraphv - a vertexv, or Edge.NONE if
there is no edge incident on vInvalidAccessorException - if v is not
contained in this graph
public Edge anIncidentEdge(Vertex v,
int edgetype)
throws InvalidAccessorException
anIncidentEdge in interface InspectableGraphjdsl.graph.api.InspectableGraphv - a vertexedgetype - A constant from the EdgeDirection interfacev,
or Edge.NONE if there is no such edge incident on vInvalidAccessorException - if v is not
contained in this graphEdgeDirection
public void setDirectionFrom(Edge e,
Vertex v)
throws InvalidVertexException,
InvalidAccessorException
setDirectionFrom in interface ModifiableGraphjdsl.graph.api.ModifiableGraphe - an edgev - an endvertex of eInvalidVertexException - if v is not an
endvertex of e but both v and
e belong to this graphInvalidAccessorException - if either e or
v does not belong to this graph
public void setDirectionTo(Edge e,
Vertex v)
throws InvalidEdgeException,
InvalidAccessorException
setDirectionTo in interface ModifiableGraphjdsl.graph.api.ModifiableGraphe - an edgev - an endvertex of eInvalidVertexException - if v is not an
endvertex of eInvalidAccessorException - if either e or
v does not belong to this graph
public void makeUndirected(Edge e)
throws InvalidAccessorException
makeUndirected in interface ModifiableGraphjdsl.graph.api.ModifiableGraphe - an edgeInvalidAccessorException - if the edge does not belong
to this graph
public void reverseDirection(Edge e)
throws InvalidEdgeException,
InvalidAccessorException
reverseDirection in interface ModifiableGraphjdsl.graph.api.ModifiableGraphe - an edgeInvalidEdgeException - If the edge is undirectedInvalidAccessorException - if the edge does not belong
to this graph
public java.lang.Object removeEdge(Edge e)
throws InvalidAccessorException
removeEdge in interface OrderedGraphjdsl.map.api.OrderedGraphe - the edge to be removedeInvalidAccessorException - if e is null or not contained
in this graph
public java.lang.Object removeVertex(Vertex v)
throws InvalidAccessorException
removeVertex in interface OrderedGraphjdsl.map.api.OrderedGraphv - the vertex to be deletedvInvalidAccessorException - if v is null or not contained
in this graph
public Vertex splitEdge(Edge e,
java.lang.Object info)
throws InvalidAccessorException
splitEdge in interface ModifiableGraphjdsl.graph.api.ModifiableGraphe - the edge to be splitvertElement - the object to be stored in vw; to get the new edges, use method
incidentEdges(w)InvalidAccessorException - if the edge does not belong
to this graph
public Edge unsplitEdge(Vertex v,
java.lang.Object info)
throws InvalidAccessorException,
InvalidVertexException
unsplitEdge in interface ModifiableGraphjdsl.graph.api.ModifiableGraphv - the vertex to be removededgeElement - the element to be stored in the new edgeInvalidVertexException - If the vertex is not of degree 2
or is of degree 2 but the "two" edges are a single self-loopInvalidAccessorException - if the vertex does not
belong to this graph
public Edge prevIncidentEdge(Vertex v,
Edge e)
throws InvalidAccessorException,
InvalidEdgeException
prevIncidentEdge in interface InspectableOrderedGraphjdsl.map.api.InspectableOrderedGraphv - a vertexe - an edge incident with vInvalidAccessorException - if v or e is not contained in
this graphInvalidEdgeException - if e is not an edge incident with
v
public Edge prevIncidentEdge(Vertex v,
Edge e,
int edgetype)
throws InvalidAccessorException,
InvalidEdgeException
prevIncidentEdge in interface InspectableOrderedGraphjdsl.map.api.InspectableOrderedGraphv - a vertexe - an edge incident with vedgetype - a constant from the EdgeDirection interfaceInvalidAccessorException - if v or e is not contained in
this graphInvalidEdgeException - if e is not an edge incident with
v
public Edge nextIncidentEdge(Vertex v,
Edge e)
throws InvalidAccessorException,
InvalidEdgeException
nextIncidentEdge in interface InspectableOrderedGraphjdsl.map.api.InspectableOrderedGraphv - a vertexe - an edge incident with vInvalidAccessorException - if v or e is not contained in
this graphInvalidEdgeException - if e is not an edge incident with
v
public Edge nextIncidentEdge(Vertex v,
Edge e,
int edgetype)
throws InvalidAccessorException,
InvalidEdgeException
nextIncidentEdge in interface InspectableOrderedGraphjdsl.map.api.InspectableOrderedGraphv - a vertexe - an edge incident with vedgetype - a constant from the EdgeDirection interfaceInvalidAccessorException - if v or e is not contained in
this graphInvalidEdgeException - if e is not an edge incident with
vpublic Vertex insertVertex(java.lang.Object elt)
insertVertex in interface OrderedGraphjdsl.map.api.OrderedGraphinfo - the object to be stored in the new vertex
public Edge insertEdge(Vertex v1,
Order order1,
Edge e1,
Vertex v2,
Order order2,
Edge e2,
java.lang.Object info)
throws InvalidEdgeException
insertEdge in interface OrderedGraphjdsl.map.api.OrderedGraphv1 - a vertexorder1 - indicates if the new edge is to be inserted
Order.BEFORE or Order.AFTER e1 around v1e1 - an edge incident with v1 or Edge.NONE if v1 is an
isolated vertexv2 - a vertex different form v1order2 - indicates if the new edge is to be inserted
Order.BEFORE or Order.AFTER e2 around v2e2 - an edge incident with v2 or Edge.NONE if v2 is an
isolated vertexinfo - the object to be stored in the new edgeInvalidAccessorException - if v1, v2, e1, or e2 is null
or not contained in this graphInvalidVertexException - if v1 and v2 are the same vertexInvalidEdgeException - if e1 (e2) is not an edge
incident with v1 (v2), or if Edge.NONE is passed as e1 (e2) and
v1 (v2) is not an isolated vertex, or if Edge.NONE is not passed
as e1 (e2) and v1 (v2) is an isolated vertex
public Edge insertDirectedEdge(Vertex v1,
Order order1,
Edge e1,
Vertex v2,
Order order2,
Edge e2,
java.lang.Object info)
insertDirectedEdge in interface OrderedGraphjdsl.map.api.OrderedGraphv1 - the origin vertexorder1 - indicates if the new edge is to be inserted
Order.BEFORE or Order.AFTER e1 around v1e1 - an edge incident with v1 or Edge.NONE if v1 is an
isolated vertexv2 - the destination vertex, different from v1order2 - indicates if the new edge is to be inserted
Order.BEFORE or Order.AFTER e2 around v2e2 - an edge incident with v2 or Edge.NONE if v2 is an
isolated vertexinfo - the object to be stored in the new edgeInvalidAccessorException - if v1, v2, e1, or e2 is null
or not contained in this graphInvalidVertexException - if v1 and v2 are the same vertexInvalidEdgeException - if e1 (e2) is not an edge
incident with v1 (v2), or if Edge.NONE is passed as e1 (e2) and
v1 (v2) is not an isolated vertex, or if Edge.NONE is not passed
as e1 (e2) and v1 (v2) is an isolated vertex
public Edge attachVertex(Vertex v,
Order order,
Edge e,
java.lang.Object vertexInfo,
java.lang.Object edgeInfo)
throws InvalidEdgeException
attachVertex in interface OrderedGraphjdsl.map.api.OrderedGraphv - a vertexorder - indicates if the new edge is to be inserted
Order.BEFORE or Order.AFTER e around ve - an edge incident with v or Edge.NONE if v is an isolated
vertexvertexInfo - the object to be stored in the new vertexedgeInfo - the object to be stored in the new edgeInvalidAccessorException - if v or e is null or not
contained in this graphInvalidEdgeException - if e is not an edge incident with
v, or if Edge.NONE is passed as e and v is not an isolated
vertex, or if Edge.NONE is not passed as e and v is an isolated
vertex
public Edge attachVertexFrom(Vertex origin,
Order order,
Edge e,
java.lang.Object vertexInfo,
java.lang.Object edgeInfo)
attachVertexFrom in interface OrderedGraphjdsl.map.api.OrderedGraphorigin - a vertexorder - indicates if the new edge is to be inserted
Order.BEFORE or Order.AFTER e around ve - an edge incident with v or Edge.NONE if v is an isolated
vertexvertexInfo - the object to be stored in the new vertexedgeInfo - the object to be stored in the new edgeInvalidAccessorException - if v or e is null or not
contained in this graphInvalidEdgeException - if e is not an edge incident with
v, or if Edge.NONE is passed as e and v is not an isolated
vertex, or if Edge.NONE is not passed as e and v is an isolated
vertex
public Edge attachVertexTo(Vertex destination,
Order order,
Edge e,
java.lang.Object vertexInfo,
java.lang.Object edgeInfo)
attachVertexTo in interface OrderedGraphjdsl.map.api.OrderedGraphdestination - a vertexorder - indicates if the new edge is to be inserted
Order.BEFORE or Order.AFTER e around ve - an edge incident with v or Edge.NONE if v is an isolated
vertexvertexInfo - the object to be stored in the new vertexedgeInfo - the object to be stored in the new edgeInvalidAccessorException - if v or e is null or not
contained in this graphInvalidEdgeException - if e is not an edge incident with
v, or if Edge.NONE is passed as e and v is not an isolated
vertex, or if Edge.NONE is not passed as e and v is an isolated
vertex
public Edge splitVertex(Vertex v,
Edge e1,
Edge e2,
java.lang.Object edgeinfo)
splitVertex in interface OrderedGraphjdsl.map.api.OrderedGraphv - the vertex to be splite1 - an edge incident with v or Edge.NONE if v is an
isolated vertexe2 - an edge incident with v or Edge.NONE if v is an
isolated vertexedgeinfo - the object to be stored in the new edgeInvalidAccessorException - if v, e1, or e2 is null or
not contained in this graphInvalidEdgeException - if e1 or e2 is not an edge
incident with v, or if Edge.NONE is passed as e1 or e2 and v is
not an isolated vertex, or if Edge.NONE is not passed as e1 and
e2 and v is an isolated vertex
public Vertex unsplitVertex(Edge e,
java.lang.Object vertexinfo)
unsplitVertex in interface OrderedGraphjdsl.map.api.OrderedGraphe - the edge to be removedvertexinfo - the object to be stored in the new vertexInvalidAccessorException - if e is null or not contained
in this graph
public void moveEndVertex(Edge e1,
Vertex v1,
Vertex v2,
Order order,
Edge e2)
throws InvalidVertexException,
InvalidEdgeException
moveEndVertex in interface OrderedGraphjdsl.map.api.OrderedGraphe1 - an edgev1 - an endvertex of e1v2 - a vertex (not necessarily different from v1)order - indicates if the new edge is to be inserted
Order.BEFORE or Order.AFTER e2 around v2e2 - an edge incident with v2 or Edge.NONE if v2 is an
isolated vertexInvalidAccessorException - if e1, v1, or v2 is null or
not contained in this graphInvalidVertexException - if v1 is not an endvertex of e1
or if v2 is equal to the endvertex of e1 opposite to v1InvalidEdgeException - if e2 is equal to e1, or if
Edge.NONE is passed as e1, or if Edge.NONE is passed as e2 and v2
is not an isolated vertex, or if Edge.NONE is not passed as e2
and v2 is an isolated vertex
public Edge attachVertex(Vertex v,
java.lang.Object vertexElement,
java.lang.Object edgeElement)
public Edge attachVertexFrom(Vertex v,
java.lang.Object vertexElement,
java.lang.Object edgeElement)
public Edge attachVertexTo(Vertex v,
java.lang.Object vertexElement,
java.lang.Object edgeElement)
public Edge insertDirectedEdge(Vertex v1,
Vertex v2,
java.lang.Object element)
public Edge insertEdge(Vertex v1,
Vertex v2,
java.lang.Object element)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||