Skip to content

Commit

Permalink
Suggest more simple method to inverse weight for MST in Graph
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
Xrayez committed Feb 12, 2022
1 parent 9ee8d39 commit e0ba42d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions doc/Graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,16 @@
<method name="minimum_spanning_tree" qualifiers="const">
<return type="Array" />
<description>
Returns a minimum spanning tree (MST) of this graph. The MST is represented as an [Array] of [GraphEdge]s in this graph, from which you can create a new [Graph], if you need to.
Returns a minimum spanning tree (MST) of this graph. An MST is represented as an [Array] of [GraphEdge]s in this graph, from which you can create a new [Graph], if you need to.
The [member GraphEdge.value] is interpreted as a [float] weight, which is up to you to define.
In order to obtain a [i]maximum spanning tree[/i], you can inverse the weights, for example:
[codeblock]
var a = graph.add_vertex(Vector2(0, 0))
var b = graph.add_vertex(Vector2(100, 100))
var w = a.value.distance_to(b.value) # Euclidean distance.
w = 1.0 / w
graph.add_edge(a, b, w)
graph.add_edge(a, b, -w) # Notice negative weight.
[/codeblock]
[b]Note:[b] there may exist several MSTs if some edges have equal weight. If weights are not configured, the method will eliminate all edges that cause cycles (a tree is an acyclic graph).
</description>
</method>
<method name="remove_edge">
Expand Down

0 comments on commit e0ba42d

Please sign in to comment.