简体   繁体   English

有向图和加权图的复合图案

[英]Composite pattern for a directed and weighted graph

What's the best way to use the composite pattern for a directed graph? 将复合模式用于有向图的最佳方法是什么? The graph represents the time progress of a software . 该图表示软件的时间进度。 The nodes are events of the software (for example the starting of an activity). 节点是软件的事件(例如,活动的开始)。 The edges are the activities , and the weight of the edge is the duration of the activity. 边缘是活动,边缘的权重是活动的持续时间。 I've ,for example , two events A and B ,and this relation: 例如,我有两个事件A和B,以及这种关系:

A ----4---> B A ---- 4 ---> B

It's mean that to complete the event A and starting B , requires 4 mseconds. 这意味着要完成事件A和从B开始,需要4毫秒。

Obviously , the graph has the starting node(only outgoing edges) , the intermediate nodes , and the last node (only incoming edges). 显然,该图具有起始节点(仅输出边缘),中间节点和最后节点(仅输入边缘)。

Some ideas for the Composite Pattern? 有关复合模式的一些想法?

The composite pattern is mostly to model nested relationships, where a group of objects share the same characteristics of a single object. 复合模式主要用于对嵌套关系进行建模,其中一组对象共享单个对象的相同特征。 For the graph you're describing, I don't see any nesting or grouping that would need to be modeled like that. 对于您正在描述的图形,我看不到任何需要像这样建模的嵌套或分组。

Graphs can be modeled simply with a Node and an Edge classes that have the usual connections. 可以使用具有通常连接的NodeEdge类对模型进行简单建模。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM