Package casa.lepton
Class OppNetGraph
java.lang.Object
org.graphstream.graph.implementations.AbstractElement
org.graphstream.graph.implementations.AbstractGraph
org.graphstream.graph.implementations.AdjacencyListGraph
org.graphstream.graph.implementations.MultiGraph
casa.lepton.OppNetGraph
- All Implemented Interfaces:
OppNet
,OppNetEventsSource
,Closeable
,AutoCloseable
,Iterable<org.graphstream.graph.Node>
,Runnable
,org.graphstream.graph.Element
,org.graphstream.graph.Graph
,org.graphstream.graph.Structure
,org.graphstream.stream.AttributeSink
,org.graphstream.stream.ElementSink
,org.graphstream.stream.Pipe
,org.graphstream.stream.Replayable
,org.graphstream.stream.Sink
,org.graphstream.stream.Source
- Direct Known Subclasses:
OppNetGraphDGS
,OppNetGraphWalk
public class OppNetGraph
extends org.graphstream.graph.implementations.MultiGraph
implements OppNet, Runnable, Closeable
A
OppNetGraph
represents a network composed of devices
(OppNode
) linked by edges (OppEdge
) representing actual or
possible connections between them.
Multiple edges can exist between two nodes, each edge representing a
connection between the nodes through a specific connectivity type
(OppEdge.getConnectivityType()
), provided both nodes support the
connectivity type (OppNode.hasConnectivityType(String)
).
The graph is dynamic: it is runnable (play()
and stop()
methods). At each step, its nodes move and edges are updated accordingly:
edges are added (resp. removed) if the nodes are (resp. no more) in mutual
radio range according to their connectivity types
(areInRange(OppNode, OppNode, String)
).
The steps are characterized by a simulation time. The simulation can run in
real time or not (accelerated or slowed down).
This class has two main subclasses: OppNetGraphDGS
if the simulation
is run according to an input DGS file and OppNetGraphWalk
if the
simulation is run according to a mobility model (see Walk
).-
Nested Class Summary
Nested classes/interfaces inherited from class org.graphstream.graph.implementations.AdjacencyListGraph
org.graphstream.graph.implementations.AdjacencyListGraph.EdgeIterator<T extends org.graphstream.graph.Edge>, org.graphstream.graph.implementations.AdjacencyListGraph.NodeIterator<T extends org.graphstream.graph.Node>
Nested classes/interfaces inherited from class org.graphstream.graph.implementations.AbstractElement
org.graphstream.graph.implementations.AbstractElement.AttributeChangeEvent
Nested classes/interfaces inherited from interface org.graphstream.stream.Replayable
org.graphstream.stream.Replayable.Controller
-
Field Summary
Modifier and TypeFieldDescriptionprotected casa.util.geom.AreaCar
protected ConnectivityProfiles
protected OppNetConsole
protected long
protected String
protected final PrintWriter
protected final long
protected OppEdgeFactory
protected Map<String,
OppEdgeListener> protected OppNetFrame
protected final casa.dgs.DGSAttributes
protected boolean
protected Hub
protected long
protected final boolean
protected OppNodeFactory
protected Map<String,
OppNodeListener> protected OppNetRules
protected OppNetOutput
protected final long
protected final OppNetProperties
protected long
protected boolean
protected Thread
protected TimeZone
Fields inherited from class org.graphstream.graph.implementations.AdjacencyListGraph
DEFAULT_EDGE_CAPACITY, DEFAULT_NODE_CAPACITY, edgeArray, edgeCount, edgeMap, GROW_FACTOR, nodeArray, nodeCount, nodeMap
Fields inherited from class org.graphstream.graph.implementations.AbstractElement
attributes, attributesBeingRemoved, id
Fields inherited from interface casa.lepton.OppNet
EDGE_ADDED, EDGE_CHANGED, EDGE_REMOVED, NODE_ADDED, NODE_MOVED, NODE_REMOVED
-
Constructor Summary
ModifierConstructorDescriptionprotected
OppNetGraph
(String networkId, OppNetProperties props) Graph attributes initialization from the given properties. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addConnectivityType
(String nodeId, String connectivityType) Add a new connectivity type for the node and update edges accordingly.addEdge
(String id, org.graphstream.graph.Node node1, org.graphstream.graph.Node node2, boolean directed) void
addEdgeListener
(String nodeId, String connectivityType, OppEdgeListener listener) Add a new listener interested in edge events for the given node.void
Add a new node in the OppNet.void
addNodeListener
(String nodeId, OppNodeListener listener) Add a new listener interested in node events for a specific node.boolean
areNeighbors
(String nodeId1, String nodeId2, String connectivityType, String edgeStatus) Returns true if there is an edge with the node for the given connectivity type and status.void
close()
Stops playing the simulation and close all resources.void
deleteNode
(String nodeId) Remove a node from the OppNet.double
getAccel()
Give the simulation current accelerationcasa.util.geom.AreaCar
getArea()
Give the graph area.casa.dgs.DGSAttributes
Give the consolegetCoordCar
(String nodeId) getCoordGeo
(String nodeId) long
Gives the current step.long
Gives the current simulation time, extrapolated according to the real time and the real start time, if the simulation is running.getEdgeStatus
(String nodeId1, String nodeId2, String connectivityType) Give the status of an edge charaterized by the nodes' ids and the connectivity type.getHub()
Give the hubGive the label of the nodegetNeighbors
(String nodeId, String connectivityType, String edgeStatus) Give the neighbors' ids of the node for a given connectivity type and status.getNeighborsNodes
(String nodeId, String connectivityType, String edgeStatus) Give the neighbor nodes of the node for a given connectivity type and status.getNodes()
Give the nodes in the OppNet.getNodeStatus
(String nodeId, String connectivityType) Give the status of a node for a given connectivity type.long
Give the tag of the node.Give the timezone of the step timesboolean
Return true if a console is provided to access the graphboolean
hasNext()
Return true if the simulation has more steps to runboolean
Check whether the node exists in the OppNet.boolean
Give the on/offline status of the node.void
join()
Waits until the simulation is stopped.protected final void
Write a DGS line preceded by a 'st' line if needed in the dgsWriter, if it is not null.makeEdgeId
(String id1, String id2, String connectivityType) Give a unique edge id from the given nodes ids and connectivityType in the form "idA-idB:type" where idA = min(id1,id2) and idB = max(id1,id2).Make a unique instance of the frame that displays the graph ifOppNetProperties.isShow()
is trueMake a unique instance ofOppNetOutput
, that produces a video of the simulation ifOppNetProperties.getVideoImgDir()
is not nullint
nbNeighbors
(String nodeId, String connectivityType, String edgeStatus) Returns the number of neighbors of the node for the given connectivity type and status.protected void
notifyEdgeListeners
(OppEdge edge, String command) protected void
notifyNodeListeners
(OppNode node, String command) void
play()
Starts playing the simulation.protected void
println
(PrintWriter writer, String line) Write a line in the given writer, if it is not nullprotected void
removeAllEdges
(OppNode node) void
removeConnectivityType
(String nodeId, String connectivityType) Remove a connectivity type for the node and update edges accordingly.removeEdge
(String id) removeEdge
(org.graphstream.graph.Edge e) void
removeEdgeListener
(String nodeId, String connectivityType) Remove a listener interested in edge events for the given node.void
removeNodeListener
(String nodeId) Remove a listener interested in node events.void
run()
Run simulation steps separated by the period given at object's instanciation.void
setAccel
(double newAccel) Change the acceleration and reset the startTime accordingly.final void
setArea
(casa.util.geom.AreaCar area) Set the graph area.boolean
setEdgeStatus
(String nodeId1, String nodeId2, String connectivityType, String status) Change the status of an edge charaterized by the nodes' ids and the connectivity type.void
Change the label of the nodevoid
setNodeStatus
(String nodeId, String connectivityType, String status) Change the status of a node for a given connectivity type.void
Change the on/offline status of the node and update edges accordingly.void
Set the given tag to the node.boolean
step()
Run a simulation step: move nodes and update edges accordingly, and wait for the next step timevoid
stop()
Stops playing the simulation.protected void
updateEdges
(Collection<OppNode> movedNodes) protected void
waitUntil
(long step) Wait until the given step, with theaccel
factor.Methods inherited from class org.graphstream.graph.implementations.AdjacencyListGraph
addEdgeCallback, addNodeCallback, clearCallback, getEdge, getEdge, getEdgeCount, getEdgeIterator, getNode, getNode, getNodeCount, getNodeIterator, removeEdgeCallback, removeNodeCallback
Methods inherited from class org.graphstream.graph.implementations.AbstractGraph
addAttributeSink, addEdge, addEdge, addEdge, addEdge, addEdge, addElementSink, addNode, addSink, attributeChanged, attributeSinks, clear, clearAttributeSinks, clearElementSinks, clearSinks, display, display, edgeAdded, edgeAttributeAdded, edgeAttributeChanged, edgeAttributeRemoved, edgeFactory, edgeRemoved, elementSinks, getEachEdge, getEachNode, getEdgeSet, getNodeSet, getReplayController, getStep, graphAttributeAdded, graphAttributeChanged, graphAttributeRemoved, graphCleared, isAutoCreationEnabled, isStrict, iterator, nodeAdded, nodeAttributeAdded, nodeAttributeChanged, nodeAttributeRemoved, nodeFactory, nodeRemoved, nullAttributesAreErrors, read, read, removeAttributeSink, removeEdge, removeEdge, removeEdge, removeEdge, removeEdge, removeElementSink, removeNode, removeNode, removeNode, removeNode, removeSink, setAutoCreate, setEdgeFactory, setNodeFactory, setNullAttributesAreErrors, setStrict, stepBegins, stepBegins, write, write
Methods inherited from class org.graphstream.graph.implementations.AbstractElement
addAttribute, addAttributes, changeAttribute, clearAttributes, clearAttributesWithNoEvent, getArray, getAttribute, getAttribute, getAttributeCount, getAttributeKeyIterator, getAttributeKeySet, getEachAttributeKey, getFirstAttributeOf, getFirstAttributeOf, getHash, getId, getIndex, getNumber, getVector, hasArray, hasAttribute, hasAttribute, hasHash, hasLabel, hasNumber, hasVector, removeAttribute, setAttribute, setIndex, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.graphstream.graph.Element
addAttribute, addAttributes, changeAttribute, clearAttributes, getArray, getAttribute, getAttribute, getAttributeCount, getAttributeKeyIterator, getAttributeKeySet, getEachAttributeKey, getFirstAttributeOf, getFirstAttributeOf, getHash, getId, getIndex, getNumber, getVector, hasArray, hasAttribute, hasAttribute, hasHash, hasLabel, hasNumber, hasVector, removeAttribute, setAttribute
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
props
-
dgsWriter
-
lastLogTime
protected long lastLogTime -
duration
protected final long duration -
period
protected final long period -
makeEdges
protected final boolean makeEdges -
currentStep
protected long currentStep -
refTime
protected long refTime -
timezone
-
started
protected boolean started -
thread
-
hasNext
protected boolean hasNext -
area
protected casa.util.geom.AreaCar area -
oppNetRules
-
connectivityProfiles
-
defaultConnectivityType
-
nodeFactory
-
edgeFactory
-
console
-
hub
-
edgeListeners
-
nodeListeners
-
frame
-
output
-
graphAttributes
protected final casa.dgs.DGSAttributes graphAttributes
-
-
Constructor Details
-
OppNetGraph
Graph attributes initialization from the given properties.- Parameters:
networkId
- the graph idprops
- the graph properties- Throws:
IOException
- if an error occurs while opening the console
-
-
Method Details
-
getAttributes
public casa.dgs.DGSAttributes getAttributes() -
hasConsole
public boolean hasConsole()Return true if a console is provided to access the graph- Returns:
- true if there is a console
-
getConsole
Give the console- Returns:
- the console
-
getHub
Give the hub- Returns:
- the hub
-
makeFrame
Make a unique instance of the frame that displays the graph ifOppNetProperties.isShow()
is true- Returns:
- the frame
-
makeOutput
Make a unique instance ofOppNetOutput
, that produces a video of the simulation ifOppNetProperties.getVideoImgDir()
is not null- Returns:
OppNetOutput
instance
-
makeEdgeId
Give a unique edge id from the given nodes ids and connectivityType in the form "idA-idB:type" where idA = min(id1,id2) and idB = max(id1,id2).- Specified by:
makeEdgeId
in interfaceOppNet
- Parameters:
id1
- a node id.id2
- other node id.connectivityType
- the connectivity type.- Returns:
- unique edge id.
-
getTimeZone
Give the timezone of the step times- Returns:
- the timezone
-
getArea
public casa.util.geom.AreaCar getArea()Give the graph area.- Returns:
- the graph area
-
setArea
public final void setArea(casa.util.geom.AreaCar area) Set the graph area.- Parameters:
area
- the new graph area (may be null)
-
play
public void play()Starts playing the simulation. -
stop
public void stop()Stops playing the simulation. -
join
public void join()Waits until the simulation is stopped. -
close
public void close()Stops playing the simulation and close all resources.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
run
public void run()Run simulation steps separated by the period given at object's instanciation. -
waitUntil
protected void waitUntil(long step) Wait until the given step, with theaccel
factor.- Parameters:
step
- the next step
-
getAccel
public double getAccel()Give the simulation current acceleration- Returns:
- the acceleration
-
setAccel
public void setAccel(double newAccel) Change the acceleration and reset the startTime accordingly. The- Parameters:
newAccel
- the new acceleration
-
step
public boolean step()Run a simulation step: move nodes and update edges accordingly, and wait for the next step time- Returns:
- false if this step is the last one
-
getCurrentStep
public long getCurrentStep()Gives the current step. -
getCurrentTime
public long getCurrentTime()Gives the current simulation time, extrapolated according to the real time and the real start time, if the simulation is running. Else return the time of the current step (currentStep + refTime) -
getRefTime
public long getRefTime() -
hasNext
public boolean hasNext()Return true if the simulation has more steps to run- Returns:
- true if the simulation has more steps to run
-
updateEdges
-
addNode
Description copied from interface:OppNet
Add a new node in the OppNet. -
deleteNode
Description copied from interface:OppNet
Remove a node from the OppNet.- Specified by:
deleteNode
in interfaceOppNet
- Parameters:
nodeId
- the id of the node to be deleted.
-
isNode
Description copied from interface:OppNet
Check whether the node exists in the OppNet. -
getNodes
Description copied from interface:OppNet
Give the nodes in the OppNet. -
setOnline
Description copied from interface:OppNet
Change the on/offline status of the node and update edges accordingly. -
isOnline
Description copied from interface:OppNet
Give the on/offline status of the node. -
setLabel
Description copied from interface:OppNet
Change the label of the node -
getLabel
Description copied from interface:OppNet
Give the label of the node -
getCoordCar
-
getCoordGeo
-
setTag
Description copied from interface:OppNet
Set the given tag to the node. -
getTag
Description copied from interface:OppNet
Give the tag of the node. -
addConnectivityType
Description copied from interface:OppNet
Add a new connectivity type for the node and update edges accordingly.- Specified by:
addConnectivityType
in interfaceOppNet
- Parameters:
nodeId
- a node id.connectivityType
- a connectivity type to be added to this node.
-
removeConnectivityType
Description copied from interface:OppNet
Remove a connectivity type for the node and update edges accordingly.- Specified by:
removeConnectivityType
in interfaceOppNet
- Parameters:
nodeId
- a node id.connectivityType
- a connectivity type to be removed from this node.
-
setNodeStatus
Description copied from interface:OppNet
Change the status of a node for a given connectivity type.- Specified by:
setNodeStatus
in interfaceOppNet
- Parameters:
nodeId
- a node id.connectivityType
- a connectivity type.status
- the new status.
-
getNodeStatus
Description copied from interface:OppNet
Give the status of a node for a given connectivity type.- Specified by:
getNodeStatus
in interfaceOppNet
- Parameters:
nodeId
- a node id.connectivityType
- a connectivity type.- Returns:
- the status for this node and connectivity type.
-
setEdgeStatus
public boolean setEdgeStatus(String nodeId1, String nodeId2, String connectivityType, String status) Description copied from interface:OppNet
Change the status of an edge charaterized by the nodes' ids and the connectivity type. If the edge does not exist, do nothing and change the status of nodes accordingly.- Specified by:
setEdgeStatus
in interfaceOppNet
- Parameters:
nodeId1
- a node id.nodeId2
- another node id.connectivityType
- a connectivity type.status
- the new edge status.- Returns:
- true if the status has been changed.
-
getEdgeStatus
Description copied from interface:OppNet
Give the status of an edge charaterized by the nodes' ids and the connectivity type. If the edge does not exist, return null- Specified by:
getEdgeStatus
in interfaceOppNet
- Parameters:
nodeId1
- a node id.nodeId2
- another node id.connectivityType
- a connectivity type.- Returns:
- the edge status
-
getNeighbors
Description copied from interface:OppNet
Give the neighbors' ids of the node for a given connectivity type and status. If connectivityType is null, give all neighbors for any connectivity type. If status is null, give all neighbors for any status.- Specified by:
getNeighbors
in interfaceOppNet
- Parameters:
nodeId
- a node id.connectivityType
- a connectivity type. May be null.edgeStatus
- an edge status. May be null.- Returns:
- ids of nodes having edges with the given status and connectivity type.
-
nbNeighbors
Description copied from interface:OppNet
Returns the number of neighbors of the node for the given connectivity type and status. If connectivityType is null, returns the number of neighbors for any connectivity type. If status is null, returns the number of neighbors whatever the connectivity status.- Specified by:
nbNeighbors
in interfaceOppNet
- Parameters:
nodeId
- a node id.connectivityType
- a connectivity type. May be null.edgeStatus
- an edge status. May be null.- Returns:
- return true if the nodes have an edge having the given status and connectivity type.
-
getNeighborsNodes
public Collection<OppNode> getNeighborsNodes(String nodeId, String connectivityType, String edgeStatus) Give the neighbor nodes of the node for a given connectivity type and status. If connectivityType is null, give all neighbors for any connectivity type. If status is null, give all neighbors for any status.- Parameters:
nodeId
- a node id.connectivityType
- a connectivity type. May be null.edgeStatus
- an edge status. May be null.- Returns:
- nodes having edges with the given status and connectivity type.
-
areNeighbors
public boolean areNeighbors(String nodeId1, String nodeId2, String connectivityType, String edgeStatus) Description copied from interface:OppNet
Returns true if there is an edge with the node for the given connectivity type and status. If connectivityType is null, return true if there is an edge for any connectivity type. If status is null, give all neighbors for any status.- Specified by:
areNeighbors
in interfaceOppNet
- Parameters:
nodeId1
- a node id.nodeId2
- another node id.connectivityType
- a connectivity type. May be null.edgeStatus
- an edge status. May be null.- Returns:
- return true if the nodes have an edge having the given status and connectivity type.
-
removeEdge
- Specified by:
removeEdge
in interfaceorg.graphstream.graph.Graph
- Overrides:
removeEdge
in classorg.graphstream.graph.implementations.AbstractGraph
-
removeEdge
- Specified by:
removeEdge
in interfaceorg.graphstream.graph.Graph
- Overrides:
removeEdge
in classorg.graphstream.graph.implementations.AbstractGraph
-
addEdge
public OppEdge addEdge(String id, org.graphstream.graph.Node node1, org.graphstream.graph.Node node2) - Specified by:
addEdge
in interfaceorg.graphstream.graph.Graph
- Overrides:
addEdge
in classorg.graphstream.graph.implementations.AbstractGraph
-
addEdge
public OppEdge addEdge(String id, org.graphstream.graph.Node node1, org.graphstream.graph.Node node2, boolean directed) - Specified by:
addEdge
in interfaceorg.graphstream.graph.Graph
- Overrides:
addEdge
in classorg.graphstream.graph.implementations.AbstractGraph
-
removeAllEdges
-
logDGS
Write a DGS line preceded by a 'st' line if needed in the dgsWriter, if it is not null.lastLogTime
is the previous 'st' line written (-1 at the beginning)- Parameters:
line
- the DGS line
-
println
Write a line in the given writer, if it is not null -
addEdgeListener
Description copied from interface:OppNetEventsSource
Add a new listener interested in edge events for the given node.- Specified by:
addEdgeListener
in interfaceOppNetEventsSource
- Parameters:
nodeId
- a node id.connectivityType
- a connectivity type.listener
- the new listener.
-
removeEdgeListener
Description copied from interface:OppNetEventsSource
Remove a listener interested in edge events for the given node.- Specified by:
removeEdgeListener
in interfaceOppNetEventsSource
- Parameters:
nodeId
- a node id.connectivityType
- a connectivity type.
-
addNodeListener
Description copied from interface:OppNetEventsSource
Add a new listener interested in node events for a specific node.- Specified by:
addNodeListener
in interfaceOppNetEventsSource
- Parameters:
nodeId
- a node id.listener
- the new listener.
-
removeNodeListener
Description copied from interface:OppNetEventsSource
Remove a listener interested in node events.- Specified by:
removeNodeListener
in interfaceOppNetEventsSource
- Parameters:
nodeId
- a node id.
-
notifyNodeListeners
-
notifyEdgeListeners
-