sim.field.network
Class Edge

java.lang.Object
  extended by sim.field.network.Edge
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable

public class Edge
extends java.lang.Object
implements java.io.Serializable, java.lang.Comparable

An Edge stores a relationship between two objects in a Network. Edges are directed: one object is a "from" object and one object is a "to" object. Edges also hold an "info" object, which is an arbitrary object that you specify on your own. An info object can be used to hold the edge weight, an edge label, or whatever you like. Edges are "semi-mutable": you can change the info object at any time, but you may not change the to or from objects once the Edge has been constructed.

An Edge may be added to at most one Network. You must remove it from that field before you can add it to a new Network. The Edge's field is known as its owner.

Explicitly stating weights. The getWeight() function returns a plausible weight for the edge. If your "info" object is a Number or a MutableDouble, or is sim.util.Valuable, then the weight of the edge is the doubleValue() of your object. Else the weight of the edge is a default of 1.0.

Edges are java.lang.Comparable as long as their 'info' elements are Numbers or are sim.util.Valuable. In this case, the comparison is such that lower values sort first.

Though Edges are comparable, they hash by reference. Edges are always considered unique.

See Also:
Serialized Form

Field Summary
 java.lang.Object info
          Other information (maybe cost) associated with the edge
 
Constructor Summary
Edge(Edge e)
           
Edge(java.lang.Object from, java.lang.Object to, java.lang.Object info)
           
 
Method Summary
 int compareTo(java.lang.Object obj)
           
 java.lang.Object from()
          Returns the "from" object.
 boolean getDirected()
          Returns true if the edge is directed or if we don't know our owner
 java.lang.Object getFrom()
          Returns the "from" object.
 java.lang.Object getInfo()
           
 java.lang.Object getOtherNode(java.lang.Object node)
          Returns the alternate to the provided node.
 java.lang.Object getTo()
          Returns the "to" object.
 double getWeight()
          Returns the weight of the edge.
 int indexFrom()
           
 int indexTo()
           
 Network owner()
          Returns the "owner" field.
 void setInfo(java.lang.Object val)
           
 java.lang.Object to()
          Returns the "to" object.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

info

public java.lang.Object info
Other information (maybe cost) associated with the edge

Constructor Detail

Edge

public Edge(Edge e)

Edge

public Edge(java.lang.Object from,
            java.lang.Object to,
            java.lang.Object info)
Method Detail

getFrom

public java.lang.Object getFrom()
Returns the "from" object.


getTo

public java.lang.Object getTo()
Returns the "to" object.


getDirected

public boolean getDirected()
Returns true if the edge is directed or if we don't know our owner


from

public java.lang.Object from()
Returns the "from" object.


to

public java.lang.Object to()
Returns the "to" object.


owner

public Network owner()
Returns the "owner" field.


indexFrom

public int indexFrom()

indexTo

public int indexTo()

getWeight

public double getWeight()
Returns the weight of the edge. The default version of the function returns the value of the info object if it is a subclass of Number (including MutableDouble) or is Valuable, else returns 1.0.


getOtherNode

public java.lang.Object getOtherNode(java.lang.Object node)
Returns the alternate to the provided node. Specifically: if node == getFrom(), then getTo() is returned; else getFrom() is returned. Note that if node != getFrom() AND node != getTo(), then getFrom() is still returned.

This method is useful for various algorithms which operate both on undirected and on directed graphs; rather than knowing if you're "to" or "from", you can just "get the node on the other side of the edge."


getInfo

public java.lang.Object getInfo()

setInfo

public void setInfo(java.lang.Object val)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

compareTo

public int compareTo(java.lang.Object obj)
Specified by:
compareTo in interface java.lang.Comparable