[英]Storing vertices in Java - Mapping Edges
I'm trying to build a graph with vertices, A, B, C & D. The graph must map an edge to a particular vertex if there is an overlap, For instance vertices A and C overlap as A has 1 -> 2, and C has 1 -> 4. 我正在尝试构建具有顶点A,B,C和D的图。如果存在重叠,则该图必须将边映射到特定顶点,例如,顶点A和C重叠,因为A具有1-> 2, C具有1-> 4。
What would be an efficient way of storing these vertices then checking if their values overlap with one another? 一种有效的方法是存储这些顶点,然后检查它们的值是否相互重叠?
Example: 例:
A 1 2 3 4
B 9 10 12 13
C 1 4 2 3
D 15 16 17 18
It depends how often these graphs are expected to change. 这取决于期望这些图多久更改一次。 If it's just once off, storing the vertex constraint in a Map<Vertex, Set<Constraint>
, calculating the intersections and then storing the final graph as an adjacency list or matrix is just fine. 如果只是一次,将顶点约束存储在Map<Vertex, Set<Constraint>
,计算交点,然后将最终图形存储为邻接表或矩阵就可以了。
You would do something like 你会做类似的事情
For each vertex v:
For each other vertex u
if constraints(u) intersect constraints(v)
add edge between u and v
You will end up with a symmetric un-directed graph. 您将最终得到一个对称无向图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.