de.cesr.more.rs.network
Class MRsEncapsulatedContextJungNetwork<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>

java.lang.Object
  extended by de.cesr.more.rs.network.MRsEncapsulatedContextJungNetwork<AgentT,EdgeT>
Type Parameters:
AgentT -
All Implemented Interfaces:
MoreNetwork<AgentT,EdgeT>

public final class MRsEncapsulatedContextJungNetwork<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
extends Object
implements MoreNetwork<AgentT,EdgeT>

Network Adapter for Repast Simphony models. Encapsulates a ContextJungNetwork. TODO handle edge objects to deal with weights etc... and allow more complex edge objects. TODO error handling for missing nodes TODO comment

See Also:
MRsContextJungNetwork
Date:
03.02.2010

Field Summary
static double DEFAULT_EDGE_WEIGHT
           
protected  MoreEdgeFactory<AgentT,EdgeT> edgeFac
           
protected  Class<? extends MoreNetworkBuilder<?,?>> networkBuilderClass
           
 
Constructor Summary
MRsEncapsulatedContextJungNetwork(repast.simphony.context.space.graph.ContextJungNetwork<AgentT> network, repast.simphony.context.Context<AgentT> context)
          Adds the encapsulated network as projection to the given context.
 
Method Summary
 EdgeT addEdge(AgentT source, AgentT target)
           
 void addNode(AgentT node)
          Add a node to the network.
protected  void checkVertex(AgentT ego)
           
 EdgeT connect(AgentT source, AgentT target)
          If there is already a connection object between these nodes it is removed and the given one added.
 void connect(EdgeT edge)
          Adds an edge to this network.
 boolean containsNode(AgentT node)
          Return true if the given node is contained within this network
 EdgeT disconnect(AgentT source, AgentT target)
           
 Iterable<AgentT> getAdjacent(AgentT ego)
           
 int getDegree(AgentT ego)
           
 EdgeT getEdge(AgentT source, AgentT target)
           
 Collection<EdgeT> getEdgesCollection()
           
 MoreNetwork<AgentT,EdgeT> getGraphFilteredInstance(Graph<AgentT,EdgeT> graph, String newName)
          The method is used to obtain a new Sub-MoreNetwork.
 int getInDegree(AgentT ego)
           
 Graph<AgentT,EdgeT> getJungGraph()
          Return a JUNG Graph object of this network.
 String getName()
           
 repast.simphony.context.space.graph.ContextJungNetwork<AgentT> getNetwork()
           
 Class<? extends MoreNetworkBuilder<?,?>> getNetworkBuilderClass()
           
 String getNetworkInfo()
          Provides some basic oinformation on the network: - number of links - number of edges - directedness
 Iterable<AgentT> getNodes()
           
 int getOutDegree(AgentT ego)
           
 Iterable<AgentT> getPredecessors(AgentT ego)
           
 AgentT getRandomPredecessor(AgentT ego)
          Return a random neighbour.
 AgentT getRandomSuccessor(AgentT ego)
          Return a random neighbour.
 Iterable<AgentT> getSuccessors(AgentT ego)
           
 double getWeight(AgentT source, AgentT target)
           
 boolean isAdjacent(AgentT ego, AgentT alter)
           
 boolean isDirected()
           
 boolean isSuccessor(AgentT alter, AgentT ego)
          Checks whether there is a link from ego to alter.
 void normalizeWeights()
          Normalises the edges' weights by dividing by the largest weight.
 int numEdges()
           
 int numNodes()
           
 void removeNode(AgentT 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<AgentT,EdgeT> edgeFac)
          Sets the MoreEdgeFactory that is used to connect agents.
 void setNetworkBuilderClass(Class<? extends MoreNetworkBuilder<?,?>> builderClass)
           
 void setWeight(AgentT source, AgentT target, double weight)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

edgeFac

protected MoreEdgeFactory<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>> edgeFac

DEFAULT_EDGE_WEIGHT

public static double DEFAULT_EDGE_WEIGHT

networkBuilderClass

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

MRsEncapsulatedContextJungNetwork

public MRsEncapsulatedContextJungNetwork(repast.simphony.context.space.graph.ContextJungNetwork<AgentT> network,
                                         repast.simphony.context.Context<AgentT> context)
Adds the encapsulated network as projection to the given context.

Parameters:
network - the network that is going to be wrapped
Method Detail

connect

public EdgeT connect(AgentT source,
                     AgentT 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<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
Returns:
the new edge

disconnect

public EdgeT disconnect(AgentT source,
                        AgentT target)
Specified by:
disconnect in interface MoreNetwork<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>

getAdjacent

public Iterable<AgentT> getAdjacent(AgentT ego)
Specified by:
getAdjacent in interface MoreNetwork<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
Returns:
iterable collection of all adjacent nodes (predecessors and successors) to the given node

getDegree

public int getDegree(AgentT ego)
Specified by:
getDegree in interface MoreNetwork<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
Returns:
the number of in- and outgoing edges (degree)

getInDegree

public int getInDegree(AgentT ego)
Specified by:
getInDegree in interface MoreNetwork<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
Returns:
the number of incoming edges (in-degree)

getName

public String getName()
Specified by:
getName in interface MoreNetwork<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
Returns:
the network's name

getNodes

public Iterable<AgentT> getNodes()
Specified by:
getNodes in interface MoreNetwork<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
Returns:
the collection of all nodes

getOutDegree

public int getOutDegree(AgentT ego)
Specified by:
getOutDegree in interface MoreNetwork<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
Returns:
the number of outgoing edges (out-degree)

getPredecessors

public Iterable<AgentT> getPredecessors(AgentT ego)
Specified by:
getPredecessors in interface MoreNetwork<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
Returns:
iterable collection of all predecessors of the given node

checkVertex

protected void checkVertex(AgentT ego)
Parameters:
ego -

getSuccessors

public Iterable<AgentT> getSuccessors(AgentT ego)
Specified by:
getSuccessors in interface MoreNetwork<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
Returns:
iterable collection of all successors from the given node

getWeight

public double getWeight(AgentT source,
                        AgentT target)
Specified by:
getWeight in interface MoreNetwork<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
Returns:
the weight of the edge between source and target node

isAdjacent

public boolean isAdjacent(AgentT ego,
                          AgentT alter)
Specified by:
isAdjacent in interface MoreNetwork<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
Returns:
true if the given nodes are adjacent to each other

isDirected

public boolean isDirected()
Specified by:
isDirected in interface MoreNetwork<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
Returns:
true if this network is directed

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<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>

numEdges

public int numEdges()
Specified by:
numEdges in interface MoreNetwork<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
Returns:
the number of edges in this network

numNodes

public int numNodes()
Specified by:
numNodes in interface MoreNetwork<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
Returns:
the number of nodes in this network

setWeight

public void setWeight(AgentT source,
                      AgentT target,
                      double weight)
Specified by:
setWeight in interface MoreNetwork<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>

getRandomSuccessor

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

Specified by:
getRandomSuccessor in interface MoreNetwork<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
Returns:
alter the randomly chosen successor

getRandomPredecessor

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

Specified by:
getRandomPredecessor in interface MoreNetwork<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
Returns:
alter the randomly chosen predecessor
See Also:
MoreNetwork.getRandomPredecessor(java.lang.Object)

isSuccessor

public boolean isSuccessor(AgentT alter,
                           AgentT ego)
Description copied from interface: MoreNetwork
Checks whether there is a link from ego to alter.

Specified by:
isSuccessor in interface MoreNetwork<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
Returns:
true, if alter (1st node) is a successor of ego (2nd node)
See Also:
MoreNetwork.isSuccessor(java.lang.Object, java.lang.Object)

getNetwork

public repast.simphony.context.space.graph.ContextJungNetwork<AgentT> getNetwork()

addNode

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

Specified by:
addNode in interface MoreNetwork<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>

getJungGraph

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

Specified by:
getJungGraph in interface MoreNetwork<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
Returns:
a JUNG Graph object of this network

getEdge

public EdgeT getEdge(AgentT source,
                     AgentT target)
Specified by:
getEdge in interface MoreNetwork<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
Returns:

getGraphFilteredInstance

public MoreNetwork<AgentT,EdgeT> getGraphFilteredInstance(Graph<AgentT,EdgeT> 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<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
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 Object
See Also:
Object.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<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
See Also:
MoreNetwork.reverseNetwork()

getEdgesCollection

public Collection<EdgeT> getEdgesCollection()
Specified by:
getEdgesCollection in interface MoreNetwork<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
Returns:
collection of all edges
See Also:
de.cesr.more.basic.network.MoreNetwork#getEdges()

addEdge

public EdgeT addEdge(AgentT source,
                     AgentT target)
See Also:
de.cesr.more.basic.network.MoreNetwork#connect(java.lang.Object)

connect

public void connect(EdgeT 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<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
Parameters:
edge - to add to the network
See Also:
MoreNetwork.connect(de.cesr.more.basic.edge.MoreEdge)

removeNode

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

Specified by:
removeNode in interface MoreNetwork<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
See Also:
MoreNetwork.removeNode(java.lang.Object)

containsNode

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

Specified by:
containsNode in interface MoreNetwork<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
Returns:
true if the network contains the given node
See Also:
MoreNetwork.containsNode(java.lang.Object)

setEdgeFactory

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

Specified by:
setEdgeFactory in interface MoreNetwork<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
See Also:
MoreNetwork.setEdgeFactory(de.cesr.more.building.edge.MoreEdgeFactory)

getNetworkBuilderClass

public Class<? extends MoreNetworkBuilder<?,?>> getNetworkBuilderClass()
Specified by:
getNetworkBuilderClass in interface MoreNetwork<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
See Also:
MoreNetwork.getNetworkBuilderClass()

setNetworkBuilderClass

public void setNetworkBuilderClass(Class<? extends MoreNetworkBuilder<?,?>> builderClass)
Specified by:
setNetworkBuilderClass in interface MoreNetwork<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
See Also:
MoreNetwork.setNetworkBuilderClass(java.lang.Class)

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<AgentT,EdgeT extends repast.simphony.space.graph.RepastEdge<AgentT> & MoreEdge<AgentT>>
See Also:
MoreNetwork.getNetworkInfo()