orngNetwork

The orngNetwork module provides the functionality to perform network analises and layout optimization.

NetworkOptimization

NetworkOptimization is the main class for performing network layout optimization. Network structure is defined in orangeom.Network class that is inherited from orange.Graph. Coordinates for all vertices are stored in variable coors and are initialized to random positions. You can modify coordinates manually or use one of the optimization algorithms.

Attributes

graph
Holds the Network object.
coors
Holds coordinates. Usage: coors[0][i], coors[1][i]; 0 for x-axis, 1 for y-axis.

Methods

NetworkOptimization()
Default constrctor.
NetworkOptimization(network)
Constructor that takes the Network object.
readNetwork(file)
Reads network from Pajek (.net) file and adds graph structure to NetworkOptimization object. Returns Network object.
saveNetwork(file)
Saves network structure of NetworkOptimization object to Pajek (.net) file.
random()
Random layout optimization.
fruchtermanReingold(steps, temperature, hidden_nodes=[])
Fruchterman-Reingold spring layout optimization. Set number of iterations with argument steps, start temperature with temperature (for example: 1000) and set list of hidden nodes with argument hidden_nodes.
radialFruchtermanReingold(center, steps, temperature)
Radial Fruchterman-Reingold spring layout optimization. Set center node with attribute center, number of iterations with argument steps and start temperature with temperature (for example: 1000).
circularOriginal()
Circular layout optimization based on original order.
circularRandom()
Circular layout optimization based on random order.
circularCrossingReduction()
Circular layout optimization (Michael Baur, Ulrik Brandes) with crossing reduction.

Examples

NetworkOptimization constructor and random layout

In our first example we create a NetworkOptimization object with a simple full graph (K5). Vertices are initially played randomly. Graph is visualized using pylabs matplotlib.

network_constructor.py

import orangeom from orngNetwork import NetworkOptimization from pylab import * # create graph object of type Network graph = orangeom.Network(5, 0) # set edges for i in range(4): for j in range(i + 1, 5): graph[i,j] = 1 # vertices are placed randomly in NetworkOptimization constructor network = NetworkOptimization(graph) # read all edges and plot a line for u, v in graph.getEdges(): x1, y1 = network.coors[0][u], network.coors[1][u] x2, y2 = network.coors[0][v], network.coors[1][v] plot([x1, x2], [y1, y2], 'b-') # read x and y coordinates to Python list x = [coordinate[0] for coordinate in network.coors] y = [coordinate[1] for coordinate in network.coors] # plot vertices plot(x, y, 'ro') show()

Executing the above script pops-up a pylab window with the following graph drawing:

Network layout optimization

This example demonstrates how to optimize network layout using one of included algorithms.

part of network_optimization.py

# vertices are placed randomly in NetworkOptimization constructor network = NetworkOptimization(graph) # optimize verices layout with one of included algorithms network.fruchtermanReingold(100, 1000)

You can use one of the following optimization algorithms:

Spring forces layout optimization is the result of the above script:

Reading and saving a network

This example demonstrates reading a network. NetworkOptimization class can read or write Pajek (.net) file format.

network_read.py (uses K5.net)

# vertices are placed randomly in NetworkOptimization constructor network = NetworkOptimization() # read network from file network.readNetwork("K5.net")

You can save network in the same way with method saveNetwork(fn).