# Graph::createRandomEdgeCosts

Sets random costs to edges

### Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

## 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

Graph