简体   繁体   中英

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 ----4---> B

It's mean that to complete the event A and starting B , requires 4 mseconds.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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