Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Graph::createRandomEdgeCosts

Sets random costs to edges

MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

Syntax

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

Description

Graph::createRandomEdgeCosts(G, x..y) creates random edge weights of type Integer within the range x..y.

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

Graph::createRandomEdgeCosts(G, x..y, Dom::Real) creates random edge weights of type Real within the range x..y.

    Note:   Already existing edge costs 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 costss are set within the range -100..50 (your output may differ due random assignment):

G2 := Graph::createRandomEdgeCosts(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: no edge weights.
Edge costs: [1, 2] = 47, [2, 3] = -12, [3, 4] = 28, [4, 5] = 1, [5, 1] = -\
36 (other existing edges have costs zero)
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 costs should be of type Real it can be set optionally:

G2 := Graph::createRandomEdgeCosts(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: no edge weights.
Edge costs: [1, 2] = -67.72964183, [2, 3] = -10.16896282, [3, 4] = -72.846\
84348, [4, 5] = -61.00518722, [5, 1] = 18.2662729 (other existing edges ha\
ve costs zero)
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?