Version 4 (modified by 18 years ago) ( diff ) | ,
---|
Documentation | NodeHandler | Commands | defTopology
defTopology: Define a Topology
This command defines a topology consisting of a set of nodes and noise injection settings to configure a specific topology. An experiment can normally only contain a single topology with noise settings, but may create additional topology declarations which are a sub set of the 'base' topology.
Syntax: defTopology(name, nodeArray = nil, &block = nil)
- name: Name of the defined topology.
- nodeArray: Selects the nodes used in this topology.
- block: Additional modifications on the create topology.
The 'name' is a uri string identifying the topology. For instance, it can be used in 'defNodes' commands. The following naming convention is encouraged: projectName:topo:topologyName
The 'nodeArray' defines which nodes are in the topology. The following array patterns are supported:
- [x,y]: Describes a single node at location x@y
- [x1..x2, y]: Describes a set of nodes along a line starting at x1@y and ending at x2@y. For instance, [2..4, 5] defines the nodes [2,5], [3,5], [4,5].
- [x, y1..y2]: Same as previous, but for the y coordinate.
- [x1..x2, y1..y2]: This defines a rectangle area of nodes within the grid.
- x1,y1], [x2,y2], [x3,y3: An arbitrary long list of single nodes. Obvioulsy, any entry in this list can also use any of the above defined syntaxes.
The optional 'block' allows the experimenter to further configure the topology. The following commands are defined inside the block:
- addNode(x,y) Add node at location x@y to the topology
- removeNode(x,y) Remove node at location x@y from the topology
Instructions on how to incorporate noise are missing
Usage
# topology contains 1 node defTopology('test:topo:origin', [1, 1]) # nodes arranged in a circle defTopology('test:topo:circle') { |t| # use simple 4-way algorithm radius = 8 xCenter = 10 yCenter = 10 r2 = radius * radius t.addNode(xCenter, yCenter + radius) t.addNode(xCenter, yCenter - radius) (1..radius).each { |x| y = (Math.sqrt(r2 - x*x) + 0.5).to_i t.addNode(xCenter + x, yCenter + y) t.addNode(xCenter + x, yCenter - y) t.addNode(xCenter - x, yCenter + y) t.addNode(xCenter - x, yCenter - y) } }