de.cesr.more.basic.network
Class MUndirectedNetwork<V,E extends MoreEdge<V>>

java.lang.Object
  extended by edu.uci.ics.jung.graph.AbstractGraph<V,E>
      extended by edu.uci.ics.jung.graph.AbstractTypedGraph<V,E>
          extended by edu.uci.ics.jung.graph.UndirectedSparseGraph<V,E>
              extended by de.cesr.more.basic.network.MUndirectedNetwork<V,E>
All Implemented Interfaces:
MoreNetwork<V,E>, Graph<V,E>, Hypergraph<V,E>, UndirectedGraph<V,E>, Serializable

public class MUndirectedNetwork<V,E extends MoreEdge<V>>
extends UndirectedSparseGraph<V,E>
implements MoreNetwork<V,E>

MORe TODO test

See Also:
Serialized Form
Date:
21.11.2011

Field Summary
protected  MoreEdgeFactory<V,E> edgeFactory
           
protected  String name
           
protected  Class<? extends MoreNetworkBuilder<?,?>> networkBuilderClass
           
protected  cern.jet.random.Uniform randomNodeSelectionStream
           
 
Fields inherited from class edu.uci.ics.jung.graph.UndirectedSparseGraph
edges, vertices
 
Fields inherited from class edu.uci.ics.jung.graph.AbstractTypedGraph
edge_type
 
Constructor Summary
MUndirectedNetwork()
          Deprecated. (used to build new instances by JUNG...)
MUndirectedNetwork(MoreEdgeFactory<V,E> edgeFactory, String name)
           
 
Method Summary
 void addNode(V node)
          Add a node to the network.
 void connect(E edge)
          Adds an edge to this network.
 E connect(V source, V target)
          If there is already a connection object between these nodes it is removed and the given one added.
 boolean containsNode(V node)
          Return true if the given node is contained within this network
 E disconnect(V source, V target)
           
 Iterable<V> getAdjacent(V ego)
           
 int getDegree(V ego)
           
 E getEdge(V source, V target)
           
 Collection<E> getEdgesCollection()
           
 MoreNetwork<V,E> getGraphFilteredInstance(Graph<V,E> graph, String newName)
          The method is used to obtain a new Sub-MoreNetwork.
 int getInDegree(V ego)
           
 Graph<V,E> getJungGraph()
          Return a JUNG Graph object of this network.
 String getName()
           
static
<V,E extends MoreEdge<V>>
MUndirectedNetwork<V,E>
getNetwork(MoreEdgeFactory<V,E> edgeFactory, UndirectedGraph<V,E> graph, String name)
          Adds nodes and edges from the given graph to a new MDirectedNetwork.
 Class<? extends MoreNetworkBuilder<?,?>> getNetworkBuilderClass()
           
 String getNetworkInfo()
          Provides some basic oinformation on the network: - number of links - number of edges - directedness
static
<V,E extends MoreEdge<V>>
MUndirectedNetwork<V,E>
getNewNetwork(MoreEdgeFactory<V,E> edgeFactory, UndirectedGraph<V,E> graph, String name)
          Adds nodes and edges from the given graph to a new MDirectedNetwork.
 Iterable<V> getNodes()
           
 int getOutDegree(V ego)
           
 cern.jet.random.Uniform getRandomNodeSelectionStream()
           
 V getRandomPredecessor(V ego)
          Return a random neighbour.
 V getRandomSuccessor(V ego)
          Return a random neighbour.
 double getWeight(V source, V target)
           
 boolean isAdjacent(V ego, V alter)
           
 boolean isDirected()
           
 void normalizeWeights()
          Normalises the edges' weights by dividing by the largest weight.
 int numEdges()
           
 int numNodes()
           
 void removeNode(V node)
          Removes a node and all its edges from the network.
 void reverseNetwork()
          Returns a reversed network, i.e. for all edges source and target vertices are exchanged.
 void setEdgeFactory(MoreEdgeFactory<V,E> edgeFac)
          Sets the MoreEdgeFactory that is used to connect agents.
 void setNetworkBuilderClass(Class<? extends MoreNetworkBuilder<?,?>> builderClass)
           
 void setRandomNodeSelectionStream(cern.jet.random.Uniform randomNodeSelectionStream)
           
 void setWeight(V source, V target, double weight)
           
 String toString()
           
 
Methods inherited from class edu.uci.ics.jung.graph.UndirectedSparseGraph
addEdge, addVertex, containsEdge, containsVertex, findEdge, findEdgeSet, getDest, getEdgeCount, getEdges, getEndpoints, getFactory, getIncidentEdges, getInEdges, getNeighbors, getOutEdges, getPredecessors, getSource, getSuccessors, getVertexCount, getVertices, isDest, isSource, removeEdge, removeVertex
 
Methods inherited from class edu.uci.ics.jung.graph.AbstractTypedGraph
getDefaultEdgeType, getEdgeCount, getEdges, getEdgeType, hasEqualEdgeType, validateEdgeType
 
Methods inherited from class edu.uci.ics.jung.graph.AbstractGraph
addEdge, addEdge, addEdge, addEdge, addEdge, degree, getIncidentCount, getIncidentVertices, getNeighborCount, getOpposite, getPredecessorCount, getSuccessorCount, getValidatedEndpoints, inDegree, isIncident, isNeighbor, isPredecessor, isSuccessor, outDegree
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface de.cesr.more.basic.network.MoreNetwork
getPredecessors, getSuccessors, isSuccessor
 
Methods inherited from interface edu.uci.ics.jung.graph.Graph
addEdge, addEdge, getOpposite, getPredecessorCount, getSuccessorCount, inDegree, isPredecessor, isSuccessor, outDegree
 
Methods inherited from interface edu.uci.ics.jung.graph.Hypergraph
addEdge, addEdge, degree, getDefaultEdgeType, getEdgeCount, getEdges, getEdgeType, getIncidentCount, getIncidentVertices, getNeighborCount, isIncident, isNeighbor
 

Field Detail

edgeFactory

protected MoreEdgeFactory<V,E extends MoreEdge<V>> edgeFactory

name

protected String name

randomNodeSelectionStream

protected cern.jet.random.Uniform randomNodeSelectionStream

networkBuilderClass

protected Class<? extends MoreNetworkBuilder<?,?>> networkBuilderClass
Constructor Detail

MUndirectedNetwork

@Deprecated
public MUndirectedNetwork()
Deprecated. (used to build new instances by JUNG...)


MUndirectedNetwork

public MUndirectedNetwork(MoreEdgeFactory<V,E> edgeFactory,
                          String name)
Method Detail

getNewNetwork

public static <V,E extends MoreEdge<V>> MUndirectedNetwork<V,E> getNewNetwork(MoreEdgeFactory<V,E> edgeFactory,
                                                                              UndirectedGraph<V,E> graph,
                                                                              String name)
Adds nodes and edges from the given graph to a new MDirectedNetwork. Uses the edge factory to create new edges. Does not assign the previous edge weights from the graph.

Type Parameters:
V -
E -
Parameters:
edgeFactory -
graph -
Returns:
the new network

getNetwork

public static <V,E extends MoreEdge<V>> MUndirectedNetwork<V,E> getNetwork(MoreEdgeFactory<V,E> edgeFactory,
                                                                           UndirectedGraph<V,E> graph,
                                                                           String name)
Adds nodes and edges from the given graph to a new MDirectedNetwork. Uses the edge objects from the given graph.

Type Parameters:
V -
E -
Parameters:
edgeFactory -
graph -
Returns:
the new network

addNode

public void addNode(V node)
Description copied from interface: MoreNetwork
Add a node to the network.

Specified by:
addNode in interface MoreNetwork<V,E extends MoreEdge<V>>
See Also:
MoreNetwork.addNode(java.lang.Object)

connect

public E connect(V source,
                 V target)
Description copied from interface: MoreNetwork
If there is already a connection object between these nodes it is removed and the given one added.

Specified by:
connect in interface MoreNetwork<V,E extends MoreEdge<V>>
Returns:
the new edge
See Also:
MoreNetwork.connect(java.lang.Object, java.lang.Object)

disconnect

public E disconnect(V source,
                    V target)
Specified by:
disconnect in interface MoreNetwork<V,E extends MoreEdge<V>>
See Also:
MoreNetwork.disconnect(java.lang.Object, java.lang.Object)

getAdjacent

public Iterable<V> getAdjacent(V ego)
Specified by:
getAdjacent in interface MoreNetwork<V,E extends MoreEdge<V>>
Returns:
iterable collection of all adjacent nodes (predecessors and successors) to the given node
See Also:
MoreNetwork.getAdjacent(java.lang.Object)

getDegree

public int getDegree(V ego)
Specified by:
getDegree in interface MoreNetwork<V,E extends MoreEdge<V>>
Returns:
the number of in- and outgoing edges (degree)
See Also:
MoreNetwork.getDegree(java.lang.Object)

getEdge

public E getEdge(V source,
                 V target)
Specified by:
getEdge in interface MoreNetwork<V,E extends MoreEdge<V>>
Returns:
See Also:
MoreNetwork.getEdge(java.lang.Object, java.lang.Object)

getJungGraph

public Graph<V,E> getJungGraph()
Description copied from interface: MoreNetwork
Return a JUNG Graph object of this network.

Specified by:
getJungGraph in interface MoreNetwork<V,E extends MoreEdge<V>>
Returns:
a JUNG Graph object of this network
See Also:
de.cesr.more.basic.network.MoreNetwork#getGraph()

getInDegree

public int getInDegree(V ego)
Specified by:
getInDegree in interface MoreNetwork<V,E extends MoreEdge<V>>
Returns:
the number of incoming edges (in-degree)
See Also:
MoreNetwork.getInDegree(java.lang.Object)

getName

public String getName()
Specified by:
getName in interface MoreNetwork<V,E extends MoreEdge<V>>
Returns:
the network's name
See Also:
MoreNetwork.getName()

getNodes

public Iterable<V> getNodes()
Specified by:
getNodes in interface MoreNetwork<V,E extends MoreEdge<V>>
Returns:
the collection of all nodes
See Also:
MoreNetwork.getNodes()

getOutDegree

public int getOutDegree(V ego)
Specified by:
getOutDegree in interface MoreNetwork<V,E extends MoreEdge<V>>
Returns:
the number of outgoing edges (out-degree)
See Also:
MoreNetwork.getOutDegree(java.lang.Object)

getRandomSuccessor

public V getRandomSuccessor(V ego)
Description copied from interface: MoreNetwork
Return a random neighbour. For directed networks, this is a successor.

Specified by:
getRandomSuccessor in interface MoreNetwork<V,E extends MoreEdge<V>>
Returns:
alter the randomly chosen successor
See Also:
MoreNetwork.getRandomSuccessor(java.lang.Object)

getRandomPredecessor

public V getRandomPredecessor(V ego)
Description copied from interface: MoreNetwork
Return a random neighbour. For directed networks, this is a predecessor.

Specified by:
getRandomPredecessor in interface MoreNetwork<V,E extends MoreEdge<V>>
Returns:
alter the randomly chosen predecessor
See Also:
MoreNetwork.getRandomPredecessor(java.lang.Object)

getWeight

public double getWeight(V source,
                        V target)
Specified by:
getWeight in interface MoreNetwork<V,E extends MoreEdge<V>>
Returns:
the weight of the edge between source and target node
See Also:
MoreNetwork.getWeight(java.lang.Object, java.lang.Object)

isAdjacent

public boolean isAdjacent(V ego,
                          V alter)
Specified by:
isAdjacent in interface MoreNetwork<V,E extends MoreEdge<V>>
Returns:
true if the given nodes are adjacent to each other
See Also:
MoreNetwork.isAdjacent(java.lang.Object, java.lang.Object)

isDirected

public boolean isDirected()
Specified by:
isDirected in interface MoreNetwork<V,E extends MoreEdge<V>>
Returns:
true if this network is directed
See Also:
MoreNetwork.isDirected()

normalizeWeights

public void normalizeWeights()
Description copied from interface: MoreNetwork
Normalises the edges' weights by dividing by the largest weight.

Specified by:
normalizeWeights in interface MoreNetwork<V,E extends MoreEdge<V>>
See Also:
MoreNetwork.normalizeWeights()

numEdges

public int numEdges()
Specified by:
numEdges in interface MoreNetwork<V,E extends MoreEdge<V>>
Returns:
the number of edges in this network
See Also:
MoreNetwork.numEdges()

numNodes

public int numNodes()
Specified by:
numNodes in interface MoreNetwork<V,E extends MoreEdge<V>>
Returns:
the number of nodes in this network
See Also:
MoreNetwork.numNodes()

setWeight

public void setWeight(V source,
                      V target,
                      double weight)
Specified by:
setWeight in interface MoreNetwork<V,E extends MoreEdge<V>>
See Also:
MoreNetwork.setWeight(java.lang.Object, java.lang.Object, double)

getGraphFilteredInstance

public MoreNetwork<V,E> getGraphFilteredInstance(Graph<V,E> graph,
                                                 String newName)
Description copied from interface: MoreNetwork
The method is used to obtain a new Sub-MoreNetwork. The parameter is a Graph instance that contains subsets of vertices and edges in the original MoreNetwork this method is applied to. For instance, such graphs may be a result of a VertexPredicateFilter. The given graph needs to be of corresponding directedness! This (the original) instance of MoreNetwork is not altered!

Specified by:
getGraphFilteredInstance in interface MoreNetwork<V,E extends MoreEdge<V>>
Returns:
A new MoreNetwork containing only vertices and edges contained in given graph object
See Also:
de.cesr.more.basic.network.MoreNetwork#getEmptyInstance()

toString

public String toString()
Overrides:
toString in class AbstractGraph<V,E extends MoreEdge<V>>
See Also:
AbstractGraph.toString()

reverseNetwork

public void reverseNetwork()
Description copied from interface: MoreNetwork
Returns a reversed network, i.e. for all edges source and target vertices are exchanged.

Specified by:
reverseNetwork in interface MoreNetwork<V,E extends MoreEdge<V>>
See Also:
MoreNetwork.reverseNetwork()

getEdgesCollection

public Collection<E> getEdgesCollection()
Specified by:
getEdgesCollection in interface MoreNetwork<V,E extends MoreEdge<V>>
Returns:
collection of all edges
See Also:
MoreNetwork.getEdgesCollection()

connect

public void connect(E edge)
Description copied from interface: MoreNetwork
Adds an edge to this network. Implementing classes are required to use the edge factory.

Specified by:
connect in interface MoreNetwork<V,E extends MoreEdge<V>>
Parameters:
edge - to add to the network
See Also:
MoreNetwork.connect(de.cesr.more.basic.edge.MoreEdge)

removeNode

public void removeNode(V node)
Description copied from interface: MoreNetwork
Removes a node and all its edges from the network.

Specified by:
removeNode in interface MoreNetwork<V,E extends MoreEdge<V>>
See Also:
MoreNetwork.removeNode(java.lang.Object)

setEdgeFactory

public void setEdgeFactory(MoreEdgeFactory<V,E> edgeFac)
Description copied from interface: MoreNetwork
Sets the MoreEdgeFactory that is used to connect agents.

Specified by:
setEdgeFactory in interface MoreNetwork<V,E extends MoreEdge<V>>
See Also:
MoreNetwork.setEdgeFactory(de.cesr.more.building.edge.MoreEdgeFactory)

containsNode

public boolean containsNode(V node)
Description copied from interface: MoreNetwork
Return true if the given node is contained within this network

Specified by:
containsNode in interface MoreNetwork<V,E extends MoreEdge<V>>
Returns:
true if the network contains the given node
See Also:
MoreNetwork.containsNode(java.lang.Object)

getNetworkBuilderClass

public Class<? extends MoreNetworkBuilder<?,?>> getNetworkBuilderClass()
Specified by:
getNetworkBuilderClass in interface MoreNetwork<V,E extends MoreEdge<V>>
See Also:
MoreNetwork.getNetworkBuilderClass()

setNetworkBuilderClass

public void setNetworkBuilderClass(Class<? extends MoreNetworkBuilder<?,?>> builderClass)
Specified by:
setNetworkBuilderClass in interface MoreNetwork<V,E extends MoreEdge<V>>
See Also:
MoreNetwork.setNetworkBuilderClass(java.lang.Class)

getRandomNodeSelectionStream

public cern.jet.random.Uniform getRandomNodeSelectionStream()
Returns:
random stream for random node selection

setRandomNodeSelectionStream

public void setRandomNodeSelectionStream(cern.jet.random.Uniform randomNodeSelectionStream)
Parameters:
randomNodeSelectionStream - random stream for random node selection

getNetworkInfo

public String getNetworkInfo()
Description copied from interface: MoreNetwork
Provides some basic oinformation on the network: - number of links - number of edges - directedness

Specified by:
getNetworkInfo in interface MoreNetwork<V,E extends MoreEdge<V>>
See Also:
MoreNetwork.getNetworkInfo()