Class Graph

java.lang.Object
org.ddolib.examples.layered.mcp.Graph

public class Graph extends Object
Represents a Graph with adjacency matrix. Used for MCP problem
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final int
    The number of edges in the graph.
    final int
    The number of nodes in the graph.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Graph(int[][] adjacencyMatrix)
    Given an adjacency matrix instantiate a graph.
  • Method Summary

    Modifier and Type
    Method
    Description
     
    int
    weightOf(int from, int to)
    Given two nodes, returns the weight of their edges.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • numNodes

      public final int numNodes
      The number of nodes in the graph.
    • numEdges

      public final int numEdges
      The number of edges in the graph.
  • Constructor Details

    • Graph

      public Graph(int[][] adjacencyMatrix)
      Given an adjacency matrix instantiate a graph. As these class is only used for MCP, we suppose that 2 nodes are not connected if the edge has weight 0
      Parameters:
      adjacencyMatrix - the adjacency matrix to initialize the graph
  • Method Details

    • weightOf

      public int weightOf(int from, int to)
      Given two nodes, returns the weight of their edges.
      Parameters:
      from - the start node of the edge
      to - the end node of the edges
      Returns:
      the weight of the edge
    • toString

      public String toString()
      Overrides:
      toString in class Object