Search code examples
javagraphjgrapht

What should the types of the edges be in this Graph ADT?


I'm working on a game as a class project, and it was suggested to me to use a Graph ADT to represent the set of territories on a world map such that each vertex is a territory, and the edges represent adjacent territories that the player can move between. I found a good Java library for the Graph ADT (JGraphT) but I have absolutely no idea what type the edges should be...

For example, the Graph<V,E> interface clearly requires me to define an object type for the vertex (which I think makes perfect sense to use my Territory type) but what should the edges be? I can't think of any object type that makes sense to use as an edge.


Solution

  • Well, for example:

    (1)

    public class Border {
       // ... put here anything that's useful
       // e.g. length of border or type of border (land,sea,river)
    }
    

    The edge is actually the border between the two territories.

    So for me it makes sense your edge to be of class Border.

    Another idea:

    (2)

    public class Distance {
       // ... put here anything that's useful
       // e.g. the distance between the two capitals
    }
    

    I usually represent those graphs in my head as if the vertices are the capitals, and the edges are say the roads between the capitals (of any two bordering states/territories, I mean).