java.lang.Object
dev.civl.gmc.smc.MatrixDirectedGraph
A simple directed graph implemented with a square matrix.
-
Constructor Summary
ConstructorsConstructorDescriptionMatrixDirectedGraph(String[][] squareMatrix) Constructs aMatrixDirectedGraphwith givensquareMatrix. -
Method Summary
Modifier and TypeMethodDescriptionString[]allTransitions(Integer sourceState) Get all outgoing transitions from the given source state to all other states inthisgraph.existingTransitions(Integer sourceState) Get all existing outgoing transitions from the givensourceStateinthisgraph.getDestState(Integer sourceState, String transition) Find the destination state with the givensourceStateandtransition.toString()
-
Constructor Details
-
MatrixDirectedGraph
Constructs aMatrixDirectedGraphwith givensquareMatrix.
ThesquareMatrixis 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 states, ifshas at least one outgoing transition starting with '@' then the ample set forsconsists of all transitions departing fromswhose names start with '@'. Ifshas no outgoing transition with name beginning with '@' then the ample set consists of all transitions departing froms.
E.g.,
Preconditions: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'
1. The givensquareMatrixmust 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
Get all outgoing transitions from the given source state to all other states inthisgraph. If there is no transition between thesourceStateand the specific destination state then the corresponding transition isnull- Parameters:
sourceState- The source state.- Returns:
- an array consisting of all transitions outgoing from the given state
-
getDestState
Find the destination state with the givensourceStateandtransition.- Parameters:
sourceState- the source statetransition- the transition outgoing from thesourceState- Returns:
- the destination state; if it is not found then
Integer.MIN_VALUEwill be returned.
-
existingTransitions
Get all existing outgoing transitions from the givensourceStateinthisgraph.- Parameters:
sourceState- The source state.- Returns:
- a
LinkedListof outgoing transitions
-
toString
-