Documentation

Graph::createRandomEdgeWeights

Sets random weights to edges

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

Syntax

Graph::createRandomEdgeWeights(G, r, <Dom::Integer | Dom::Real>)

Description

Graph::createRandomEdgeWeights(G, x..y) creates random integer edge weights within the range x..y.

Graph::createRandomEdgeWeights(G, x..y, Dom::Integer) does exactly the same.

Graph::createRandomEdgeWeights(G, x..y, Dom::Real) creates random real edge weights within the range x..y.

    Note:   Already existing edge weights will be changed, too!

Examples

Example 1

Creating edge weights for a small cyclic graph. First, it has no specified weights:

G1 := Graph::createCircleGraph(5):
Graph::printGraphInformation(G1)
Vertices: [1, 2, 3, 4, 5]
Edges: [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1]]
Vertex weights: no vertex weights.
Edge descriptions: no edge descriptions.
Edge weights: no edge weights.
Edge costs: no edge costs.
Adjacency list (out): 1 = [2], 2 = [3], 3 = [4], 4 = [5], 5 = [1]
Adjacency list (in): 1 = [5], 2 = [1], 3 = [2], 4 = [3], 5 = [4]
Graph is directed.

Now the weights are set within the range -100..50 (your output may differ due random assignment):

G2 := Graph::createRandomEdgeWeights(G1, -100..50):
Graph::printGraphInformation(G2)
Vertices: [1, 2, 3, 4, 5]
Edges: [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1]]
Vertex weights: no vertex weights.
Edge descriptions: no edge descriptions.
Edge weights: [1, 2] = 47, [2, 3] = -12, [3, 4] = 28, [4, 5] = 1, [5, 1] = -36 (other existing edges have no weight)
Edge costs: no edge costs.
Adjacency list (out): 1 = [2], 2 = [3], 3 = [4], 4 = [5], 5 = [1]
Adjacency list (in): 1 = [5], 2 = [1], 3 = [2], 4 = [3], 5 = [4]
Graph is directed.

If the weights should be of type Real it can be set optionally:

G2 := Graph::createRandomEdgeWeights(G1, -100..50, Dom::Real):
Graph::printGraphInformation(G2)
Vertices: [1, 2, 3, 4, 5]
Edges: [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1]]
Vertex weights: no vertex weights.
Edge descriptions: no edge descriptions.
Edge weights: [1, 2] = -67.72964183, [2, 3] = -10.16896282, [3, 4] = -72.84684348, [4, 5] = -61.00518722, [5, 1] = 18.2\
662729 (other existing edges have no weight)
Edge costs: no edge costs.
Adjacency list (out): 1 = [2], 2 = [3], 3 = [4], 4 = [5], 5 = [1]
Adjacency list (in): 1 = [5], 2 = [1], 3 = [2], 4 = [3], 5 = [4]
Graph is directed.

Parameters

G

A graph

r

A range

Return Values

Graph

Was this topic helpful?