Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

draw a graph where the distance between vertices correspond to the edge weights

Is there an algorithm that gives me coordinates of vertices in a graph, when I give him a weighted graph and the edge weights between vertices points to the distance between vertices?

Something like:

public _ArrayOfCoordinatesForVertices_ **super_hyper_algorithm**(weighted_graph){  
     return _foo_;  
}
like image 930
Vladimír Magyar Avatar asked Oct 30 '25 07:10

Vladimír Magyar


2 Answers

This is in general not possible: Imagine a graph with 3 nodes n1, n2, and n3.

now consider the following distances:

n1-n2: 4
n1-n3: 1
n2-n3: 1

(This violates the triangle inquality).

like image 138
flolo Avatar answered Nov 01 '25 12:11

flolo


What you are referring to is called Multidimensional scaling (MDS) and you should find plenty of implementations now you know how to search for it.

Like others said, to some extent, it is impossible to draw a perfect graph without violating some of your constraints (the distances between points). MDS algorithms are specifically targeted at minimizing such violations.

like image 31
flodel Avatar answered Nov 01 '25 13:11

flodel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!