Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
553 views
in Technique[技术] by (71.8m points)

collections - Is there a Directed Acyclic Graph (DAG) data type in Java, and should I use it?

I am modeling a power subsystem in Java. A simple SQLite database contains a set of Line Replaceable Units (LRUs) and the connections between them. I am writing a Power Model API to simplify queries of the data store, using DDD patterns and repositories.

I am seeking an appropriate Java collection to model the query results. There are some special cases in a LRU connection stream that have to be modeled:

  1. Initially, there's a Power Distribution Unit (PDU) with multiple ports (<=16) that feeds power to downstream LRUs.
  2. Typical connections in a power stream involve a single source LRU where power originates and a single Sink LRU where power is drained.
  3. However, downstream there could be a single source LRU connected to multiple sink LRUs.
  4. There are no cycles in a power stream.

The inclusion of #3 above has led me to think about returning query results from the API as a tree. But the only tree I've found in java.util is a TreeMap key-value paired red-black tree, which doesn't seem appropriate (or I can't think of an appropriate abstraction for modeling power streams with it.) I've also been considering a LinkedHashSet, but I'm not convinced it is appropriate either. It's not clear to me how a node in this structure would point to downstream nodes.

I'm not concerned about efficiency in time or space at this point. My API just has to work by supplying power connection information to external clients (i.e., the Presentation Tier of a Java-based Power Monitoring & Control app.) There are also no restrictions on the use of open source data types/libraries.

In general computer science parlance, what I'm really seeking is a Directed-Acyclic-Graph (DAG).

Is there an implementation of that for Java? Am I correct that a DAG is appropriate for my scenario?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I don't know if it can help but take a look at JGraphT.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...