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

后端 未结 4 1906
甜味超标
甜味超标 2020-12-16 23:10

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 Mode

相关标签:
4条回答
  • 2020-12-16 23:40

    FWIW if someone wants a standard-libraries only solution, A map of sets or a map of other collections might do the job too, although not as well.

    0 讨论(0)
  • 2020-12-16 23:41

    For this particular problem. I've decided to use a LinkedListMultimap from Guava.

    0 讨论(0)
  • 2020-12-16 23:47

    As you can see if regarding the "related" questions, similar questions were already asked. And no, Java does not have a general-purpose graph/tree/DAG data type (if we don't count Swing's TreeModel).

    Make your own one.


    Here is an example (readonly) interface:

    interface Node<N extends Node<N,E>, E extends Edge<N,E>> {
        public Set<E> outgoingEdges();
        public Set<E> ingoingEdges();
    }
    
    interface Edge<N extends Node<N,E>, E extends Edge<N,E>> {
        public E source();
        public E sink();
    }
    

    You would then have

    interface LRU implements Node<LRU, Line> { ... }
    interface Line implements Edge<LRU, Line> { ... }
    

    (or classes instead).

    0 讨论(0)
  • 2020-12-16 23:59

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

    0 讨论(0)
提交回复
热议问题