uchicago.src.sim.topology.graph
Class UndirectedGraph

java.lang.Object
  extended byuchicago.src.sim.topology.graph.AbstractGraph
      extended byuchicago.src.sim.topology.graph.UndirectedGraph
All Implemented Interfaces:
Graph, ModifyableTopology, RelationTopology, java.io.Serializable

public class UndirectedGraph
extends AbstractGraph

This class represents an undirected graph. As such each edge has a strength of 1, so distance is equivelent to number of links separating two objects. If you don't need directional edges, you should use this class as it has less overhead in terms of memory.

Version:
$Revision: 1.4 $
Author:
Tom Howe
See Also:
Serialized Form

Field Summary
 
Fields inherited from class uchicago.src.sim.topology.graph.AbstractGraph
type
 
Constructor Summary
UndirectedGraph(java.util.Set s)
           
UndirectedGraph(java.util.Set con, java.lang.String type)
          Create a new DefaultGraph for a particular context with the given label.
 
Method Summary
 boolean areAdjacent(java.lang.Object element1, java.lang.Object element2)
          Determine if the two objects are connected by an edge.
 boolean areAdjacent(java.lang.Object v, java.lang.Object v1, EdgeType type)
          Returns whether the two elements share an edge with the given directionality.
 int degree()
           
 int degree(java.lang.Object v, EdgeType type)
          Returns the number of edges for the object with the given directionality.
 double distance(java.lang.Object element1, java.lang.Object element2)
          Gets the distance between two objects in this topology.
 boolean equals(java.lang.Object o)
          Two DefaultGraphs are equal if they have the same relationship table and the same type.
 java.util.List getAdjacentNodes(java.lang.Object v, double distance, EdgeType type)
           
 java.util.List getAdjacentNodes(java.lang.Object v, EdgeType type)
          Get the Nodes that share an edge with the parameter with the proper directionality.
 Edge getEdge(java.lang.Object element1, java.lang.Object element2)
           
 java.util.List getEdges(java.lang.Object v, EdgeType type)
          Returns the edge objects of the given directionality for the object.
protected  java.util.Set getEdgeSet(java.lang.Object e)
           
 java.util.Set getNodes()
           
 int hashCode()
           
 void insertEdge(Edge e)
          Insert an edge that has already been created.
 void insertEdge(java.lang.Object e, java.lang.Object e1)
          Insert a new edge into the graph.
 void insertEdge(java.lang.Object e, java.lang.Object e1, double strength)
          Insert a new edge into the graph.
 boolean isUndirected(Edge e)
          Determine if a given edge is directed or undirected.
 java.util.Iterator iterator()
          Get an iterator for the graph.
 void makeUndirected(Edge e)
          This method is not implemented in DefaultGraph.
 void removeEdge(Edge e)
          Removes an edge from the graph.
 void removeEdge(java.lang.Object e, java.lang.Object e1)
          Removes the edge between element1 and element2.
 boolean reverseDirection(Edge e)
          Reverse the direction of the edge.
 void setDirectionFrom(Edge e, java.lang.Object v)
          This should force the directionality of an edge to be from the passed element.
 int size()
           
 java.lang.String toString()
           
 
Methods inherited from class uchicago.src.sim.topology.graph.AbstractGraph
addRelation, getRelations, getRelations, getRelationType, removeRelation, setRelationType
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UndirectedGraph

public UndirectedGraph(java.util.Set con,
                       java.lang.String type)
Create a new DefaultGraph for a particular context with the given label.

Parameters:
con -
type -

UndirectedGraph

public UndirectedGraph(java.util.Set s)
Method Detail

areAdjacent

public boolean areAdjacent(java.lang.Object element1,
                           java.lang.Object element2)
Determine if the two objects are connected by an edge. Since all edges in this graphtype have a strength of 1, this is equivlent to a range query with distance = 1.

Parameters:
element1 -
element2 -
Returns:

insertEdge

public void insertEdge(java.lang.Object e,
                       java.lang.Object e1,
                       double strength)
Insert a new edge into the graph. This method will create a new edge based on the class specification from the edgeClass parameter. The directed flagged will be ignored in this implementation as all edges are assumed to be undirected.

Parameters:
e - The first element.
e1 - The second element.
strength - Ignored, as all edges are unweighted.

insertEdge

public void insertEdge(java.lang.Object e,
                       java.lang.Object e1)
Insert a new edge into the graph. This method will create a new undirected edge between element1 and element2.

Parameters:
e - The first element.
e1 - The second element.

getEdgeSet

protected java.util.Set getEdgeSet(java.lang.Object e)

insertEdge

public void insertEdge(Edge e)
Insert an edge that has already been created. This assumes that the edge should be undirected and makes sure both elements have the edge.

Parameters:
e -

removeEdge

public void removeEdge(Edge e)
Removes an edge from the graph. This should also remove the edge from the elements of the edge. In other words, after this call, there should be no references to the edge.

Parameters:
e -

removeEdge

public void removeEdge(java.lang.Object e,
                       java.lang.Object e1)
Removes the edge between element1 and element2.

Parameters:
e -
e1 -

makeUndirected

public void makeUndirected(Edge e)
This method is not implemented in DefaultGraph.

Parameters:
e -
Throws:
java.lang.UnsupportedOperationException

isUndirected

public boolean isUndirected(Edge e)
Determine if a given edge is directed or undirected. The semantics of how directionality is handled is left up to the implementor. This method always returns true for the DefaultGraph

Parameters:
e -
Returns:
True.

reverseDirection

public boolean reverseDirection(Edge e)
Reverse the direction of the edge. If the edge is undirected, this method, should not alter the directionality.

Parameters:
e -
Returns:

setDirectionFrom

public void setDirectionFrom(Edge e,
                             java.lang.Object v)
This should force the directionality of an edge to be from the passed element. An undirected edge should become directed.

Parameters:
e -
v -

getAdjacentNodes

public java.util.List getAdjacentNodes(java.lang.Object v,
                                       EdgeType type)
Get the Nodes that share an edge with the parameter with the proper directionality.

Parameters:
v -
type -
Returns:

areAdjacent

public boolean areAdjacent(java.lang.Object v,
                           java.lang.Object v1,
                           EdgeType type)
Returns whether the two elements share an edge with the given directionality.

Parameters:
v -
v1 -
type -
Returns:

getEdges

public java.util.List getEdges(java.lang.Object v,
                               EdgeType type)
Returns the edge objects of the given directionality for the object.

Parameters:
v -
type -
Returns:

getEdge

public Edge getEdge(java.lang.Object element1,
                    java.lang.Object element2)

degree

public int degree(java.lang.Object v,
                  EdgeType type)
Returns the number of edges for the object with the given directionality.

Parameters:
v -
type -
Returns:

iterator

public java.util.Iterator iterator()
Get an iterator for the graph.

Returns:

distance

public double distance(java.lang.Object element1,
                       java.lang.Object element2)
Description copied from interface: RelationTopology
Gets the distance between two objects in this topology. This could be either spatial distance, network distance or any other kind of well defined metric distance.

Parameters:
element1 -
element2 -
Returns:

size

public int size()

equals

public boolean equals(java.lang.Object o)
Two DefaultGraphs are equal if they have the same relationship table and the same type.

Overrides:
equals in class AbstractGraph
Parameters:
o -
Returns:

hashCode

public int hashCode()
Overrides:
hashCode in class AbstractGraph

toString

public java.lang.String toString()

degree

public int degree()

getAdjacentNodes

public java.util.List getAdjacentNodes(java.lang.Object v,
                                       double distance,
                                       EdgeType type)
Parameters:
v -
distance -
type -
Returns:

getNodes

public java.util.Set getNodes()