Fix DFA minimization
I assumed bijectivty between behaviours and equivalence groups, but there was no bijectivity.
This commit is contained in:
parent
764fffa1ca
commit
3b8e2fcbf9
1 changed files with 9 additions and 10 deletions
|
|
@ -119,28 +119,28 @@ groupByBehaviour mapping = groupByFirst . map (\s -> (mapping Map.! s, s)) . Set
|
||||||
groupAllByBehaviour :: (Ord s, Ord t)
|
groupAllByBehaviour :: (Ord s, Ord t)
|
||||||
=> Map.Map s (Behaviour s t)
|
=> Map.Map s (Behaviour s t)
|
||||||
-> Partition s
|
-> Partition s
|
||||||
-> Map.Map (Behaviour s t) (EquivalenceGroup s)
|
-> Map.Map (EquivalenceGroup s) (Behaviour s t)
|
||||||
groupAllByBehaviour mapping = Map.unions . map (groupByBehaviour mapping) . Set.toList
|
groupAllByBehaviour mapping = Map.fromList
|
||||||
|
. map swap
|
||||||
|
. concatMap (Map.assocs . groupByBehaviour mapping)
|
||||||
|
. Set.toList
|
||||||
|
|
||||||
findNewBehaviourGrouping :: (Ord s, Ord t)
|
findNewBehaviourGrouping :: (Ord s, Ord t)
|
||||||
=> Map.Map s (Dfa.State s t)
|
=> Map.Map s (Dfa.State s t)
|
||||||
-> Partition s
|
-> Partition s
|
||||||
-> Map.Map (Behaviour s t) (EquivalenceGroup s)
|
-> Map.Map (EquivalenceGroup s) (Behaviour s t)
|
||||||
findNewBehaviourGrouping statemap partition =
|
findNewBehaviourGrouping statemap partition =
|
||||||
let mapping = partitionToMap partition
|
let mapping = partitionToMap partition
|
||||||
behaviours = findBehaviours mapping statemap
|
behaviours = findBehaviours mapping statemap
|
||||||
in groupAllByBehaviour behaviours partition
|
in groupAllByBehaviour behaviours partition
|
||||||
|
|
||||||
groupingToPartition :: (Ord s) => Map.Map (Behaviour s t) (EquivalenceGroup s) -> Partition s
|
|
||||||
groupingToPartition = Set.fromList . Map.elems
|
|
||||||
|
|
||||||
findGroupingFixpoint :: (Ord s, Ord t)
|
findGroupingFixpoint :: (Ord s, Ord t)
|
||||||
=> Map.Map s (Dfa.State s t)
|
=> Map.Map s (Dfa.State s t)
|
||||||
-> Partition s
|
-> Partition s
|
||||||
-> Map.Map (Behaviour s t) (EquivalenceGroup s)
|
-> Map.Map (EquivalenceGroup s) (Behaviour s t)
|
||||||
findGroupingFixpoint statemap partition =
|
findGroupingFixpoint statemap partition =
|
||||||
let newGrouping = findNewBehaviourGrouping statemap partition
|
let newGrouping = findNewBehaviourGrouping statemap partition
|
||||||
newPartition = groupingToPartition newGrouping
|
newPartition = Map.keysSet newGrouping
|
||||||
in if partition == newPartition
|
in if partition == newPartition
|
||||||
then newGrouping
|
then newGrouping
|
||||||
else findGroupingFixpoint statemap newPartition
|
else findGroupingFixpoint statemap newPartition
|
||||||
|
|
@ -154,7 +154,6 @@ minimizeDfa :: (Ord s, Ord t) => Dfa.Dfa s t -> Dfa.Dfa (EquivalenceGroup s) t
|
||||||
minimizeDfa a =
|
minimizeDfa a =
|
||||||
let grouping = findGroupingFixpoint (stateMap a) (initialPartition a)
|
let grouping = findGroupingFixpoint (stateMap a) (initialPartition a)
|
||||||
mapping = partitionToMap $ groupingToPartition grouping
|
mapping = partitionToMap $ groupingToPartition grouping
|
||||||
newStateMap = Map.fromList $ map swap $ Map.assocs grouping
|
|
||||||
newEntryState = mapping Map.! entryState a
|
newEntryState = mapping Map.! entryState a
|
||||||
newExitStates = Set.map (mapping Map.!) (exitStates a)
|
newExitStates = Set.map (mapping Map.!) (exitStates a)
|
||||||
in fromJust $ fa newStateMap newEntryState newExitStates
|
in fromJust $ fa grouping newEntryState newExitStates
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue