AssignEdgeWeights - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Mozilla Firefox.

Online Help

All Products    Maple    MapleSim


GraphTheory[RandomGraphs]

  

AssignEdgeWeights

  

generate random edge weights for a graph

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

AssignEdgeWeights(G,m..n)

AssignEdgeWeights(G,a..b)

AssignEdgeWeights(G,R)

Parameters

G

-

graph

m, n

-

integers satisfying m≤n

a, b

-

floats satisfying a≤b

R

-

user-defined function for generating random edge weights

Description

• 

If G is a weighted graph, AssignEdgeWeights(G,...) assigns new random edge weights to G, that is, for each edge (i,j) in G the (i,j)th entry in the weight matrix of G is updated inplace.

• 

If G is an unweighted graph, a weighted graph is first created before assigning the edge weights.  The structure of G is not copied.

• 

AssignEdgeWeights(G,m..n) assigns the edges of the weighted graph random integer weights uniformly distributed on [m,n].

• 

AssignEdgeWeights(G,a..b) assigns the edges of the weighted graph random decimal weights uniformly distributed on [a,b).

• 

AssignEdgeWeights(G,R) assigns the edges of the weighted graph G values defined by R().  The Maple procedure R must return numerical values, that is, integers, rationals, or floating-point constants.

• 

The random number generator used to compute the edge weights can be seeded using the seed option or the randomize function.

Examples

> 

with⁡GraphTheory:

> 

with⁡RandomGraphs:

> 

T≔Graph⁡weighted,1,2,2,3,3,4,4,1

T≔Graph 1: a directed weighted graph with 4 vertices and 4 arcs

(1)
> 

WeightMatrix⁡T

0100001000011000

(2)
> 

AssignEdgeWeights⁡T,1..9

Graph 1: a directed weighted graph with 4 vertices and 4 arcs

(3)
> 

WeightMatrix⁡T

0400001000071000

(4)
> 

T≔RandomTree⁡4

T≔Graph 2: an undirected graph with 4 vertices and 3 edges

(5)
> 

T≔AssignEdgeWeights⁡T,0...1.0

T≔Graph 3: an undirected weighted graph with 4 vertices and 3 edges

(6)
> 

W≔WeightMatrix⁡T

W≔0.0.09754040499940950.0.6323592462254100.09754040499940950.0.0.0.0.0.0.9133758561390190.6323592462254100.0.9133758561390190.

(7)
> 

op⁡3,W

datatype=float8,storage=rectangular,order=Fortran_order,shape=symmetric

(8)
> 

T≔RandomTree⁡100

T≔Graph 4: an undirected graph with 100 vertices and 99 edges

(9)
> 

T≔AssignEdgeWeights⁡T,1..99

T≔Graph 5: an undirected weighted graph with 100 vertices and 99 edges

(10)
> 

op⁡3,WeightMatrix⁡T

datatype=integer,storage=sparse,order=Fortran_order,shape=symmetric

(11)

This example creates a network

> 

N≔Graph⁡1,2,1,3,1,4,2,3,2,5,3,5,4,3,4,5

N≔Graph 6: a directed graph with 5 vertices and 8 arcs

(12)
> 

U≔rand⁡1..4:

> 

B := proc() if U()=1 then 1 else 2 end if; end proc:

So Prob(B=1)=1/4, Prob(B=2)=3/4

> 

N≔AssignEdgeWeights⁡N,B

N≔Graph 7: a directed weighted graph with 5 vertices and 8 arcs

(13)
> 

W≔WeightMatrix⁡N

W≔0121000101000020010200000

(14)
> 

op⁡3,W

datatype=anything,storage=rectangular,order=Fortran_order,shape=

(15)

See Also

GraphTheory:-Graph

GraphTheory:-MakeWeighted

GraphTheory:-RandomGraphs:-RandomTree

GraphTheory:-WeightMatrix