Module dev.civl.gmc

Class MatrixDirectedGraph

java.lang.Object
dev.civl.gmc.smc.MatrixDirectedGraph

public class MatrixDirectedGraph extends Object
A simple directed graph implemented with a square matrix.
  • Constructor Details

    • MatrixDirectedGraph

      public MatrixDirectedGraph(String[][] squareMatrix) throws Exception
      Constructs a MatrixDirectedGraph with given squareMatrix.
      The squareMatrix is a 2-dimensional String matrix.The row index is the source state, the column index is the the destination state, and the String element in the matrix is the corresponding transition.
      E.g.,
       
       Matrix:     Graph:
       X 0 1 2 3      0	
       0   a b    'a'/ \'b'	
       1       c    1   2
       2       d  'c'\ /'d'	
       3     		3	
       
       

      For each state s, if s has at least one outgoing transition starting with '@' then the ample set for s consists of all transitions departing from s whose names start with '@'. If s has no outgoing transition with name beginning with '@' then the ample set consists of all transitions departing from s.
      E.g.,
       
       Matrix:      		Graph:
       X 0  1  2  3  4  5	      0	
       0    @a @b c   	'@a'/ |'@b'\'c'	
       1             d  e	   1  2     3
       2            	       'd'/ \'e'
       3            	  	 4   5
       4			- State 0 has an ample set consisting of '@a' and '@b'
       5			- State 1 has an ample set consisting of 'd' and 'e'
       
       
      Preconditions:
      1. The given squareMatrix must have a same value for its row number and column number.
      Parameters:
      squareMatrix - an input 2-dimensional String matrix used for generating the directed state-transition graph.
      Throws:
      Exception
  • Method Details

    • allTransitions

      public String[] allTransitions(Integer sourceState)
      Get all outgoing transitions from the given source state to all other states in this graph. If there is no transition between the sourceState and the specific destination state then the corresponding transition is null
      Parameters:
      sourceState - The source state.
      Returns:
      an array consisting of all transitions outgoing from the given state
    • getDestState

      public Integer getDestState(Integer sourceState, String transition)
      Find the destination state with the given sourceState and transition.
      Parameters:
      sourceState - the source state
      transition - the transition outgoing from the sourceState
      Returns:
      the destination state; if it is not found then Integer.MIN_VALUE will be returned.
    • existingTransitions

      public LinkedList<String> existingTransitions(Integer sourceState)
      Get all existing outgoing transitions from the given sourceState in this graph.
      Parameters:
      sourceState - The source state.
      Returns:
      a LinkedList of outgoing transitions
    • toString

      public String toString()
      Overrides:
      toString in class Object