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

余生长醉 提交于 2019-12-06 08:41:30

问题


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_;  
}

回答1:


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).




回答2:


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.




回答3:


If the graph is drawn in the Euclidean Space you can't do that, because, as pointed out in this answer you could violate the Triangle Inequality.

Usually, you can visually represent edges' weights by using different colour (i.e. by mapping weights to a colour-map), or by using different thickness of the edges (i.e. by mapping weights to a thickness scale).




回答4:


OK i have found a library for python and it creates a graph image for me :) and i can give weights for edges like attribute: Weight of edge. In dot, the heavier the weight, the shorter, straighter and more vertical the edge is.



来源:https://stackoverflow.com/questions/5497329/draw-a-graph-where-the-distance-between-vertices-correspond-to-the-edge-weights

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!