Documentation Center

  • Trial Software
  • Product Updates

Graph::setEdgeCosts

Assigns edge costs to edges.

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

Syntax

Graph::setEdgeCosts(G, Edge, EdgeCosts, <OnlySpecifiedEdges>)

Description

Graph::setEdgeCosts(G, Edges, EdgeCosts) returns a graph where Edges have the edge costs EdgeCosts.

    Note:   If OnlySpecifiedEdges is stated and an undirected graph is to be changed, only the edges specified are used and not the inverted ones. For example if a call Graph::setEdgeCosts(G, [[u,v]], [1]) is invoked, only the edge [u, v] gets 1. The edge [v, u] will not be changed.

    Note:   The substitute None can be used when a specified edge should not get the assigned costs.

Examples

Example 1

First lets define a graph without edge costs:

G1 := Graph::createCircleGraph(3):
Graph::getEdgeCosts(G1)

FAIL was returned, because no edge costs werde defined.

Graph::getEdges(G1);
G1 := Graph::setEdgeCosts(G1, [[1, 2], [3, 1]], [5, 1/2]):
Graph::getEdgeCosts(G1)

The first output shows all the edges and the second one the assigned edge costs.

G1 := Graph::setEdgeCosts(G1, [[2, 3]], [infinity]):
Graph::getEdgeCosts(G1)

It is easy to see that only the edge cost of [2,3] was changed.

Example 2

First lets define a graph without edge costs:

G1 := Graph::createCompleteGraph(3):
Graph::getEdgeCosts(G1)

FAIL was returned, because no edge costs werde defined.

Graph::getEdges(G1);
G2 := Graph::setEdgeCosts(G1, [[1, 2], [3, 1]], [5, 1/2]):
Graph::getEdgeCosts(G2)

The first output shows all the edges (the graph is undirected !) and the second one the assigned edge costs. Not only the specified edges were set, but also the reverted edges.

Graph::getEdges(G1);
G2 := Graph::setEdgeCosts(G1, [[1, 2], [3, 1]], [5, 1/2], 
                          OnlySpecifiedEdges):
Graph::getEdgeCosts(G2)

It is easy to see that only the specified edge costs were changed and not the reverted edges, too.

Example 3

There exist also the possibility to set the costs via a table instead of a list.

tbl := table([1, 2] = 15, [1, 3] = 20):
G2 := Graph::createCompleteGraph(3):
G2 := Graph::setEdgeCosts(G2, [[1, 2], [3, 1]], tbl):
Graph::getEdgeCosts(G2)

And again, but this time only the specified edges:

tbl := table([1, 2] = 15, [1, 3] = 20):
G2 := Graph::createCompleteGraph(3):
G2 := Graph::setEdgeCosts(G2, [[1, 2], [3, 1]], tbl, 
                          OnlySpecifiedEdges):
Graph::getEdgeCosts(G2)

Parameters

G

A graph

Edge

A list of one or more edges

EdgeCosts

A list of one or more numbers, or a table consisting of the edges with their costs.

Options

OnlySpecifiedEdges

Only the edges specified in Edge will be set.

Return Values

New graph with the corrected edge costs.

Was this topic helpful?