Assigns edge 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.
Graph::setEdgeCosts(G
, Edge
, EdgeCosts
, <OnlySpecifiedEdges>)
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 
Note:
The substitute 
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.
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.
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)

A graph 

A list of one or more edges 

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

Only the edges specified in 
New graph with the corrected edge costs.