Skip to content

Commit

Permalink
Collapse similar NFA states
Browse files Browse the repository at this point in the history
  • Loading branch information
colder committed Jun 13, 2012
1 parent 74f5c02 commit 9a54c4c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/insane/alias/EffectRepresentations.scala
Expand Up @@ -184,6 +184,8 @@ trait EffectRepresentations extends PointToGraphsDefs with PointToEnvs {

res = res.removeDeadPaths

res = res.collapseSimilarStates

res
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/insane/utils/Automatons.scala
Expand Up @@ -61,6 +61,21 @@ object Automatons {

removeStates(states -- markedStates)
}

case class StateSig(ins: Set[(S, L)], outs: Set[(S, L)])

object StateSig {
def fromState(s: S): StateSig = {
StateSig(graph.ins(s).map(t => (t.v1, t.label)).toSet,
graph.outs(s).map(t => (t.v2, t.label)).toSet)
}
}
def collapseSimilarStates: Automaton[S, T, L] = {
// Keep the head of each kind, remove the rest
val toRemove = states.groupBy(StateSig.fromState _).values.flatMap(_.tail)

removeStates(toRemove)
}
}

class AutomatonDotConverter[S <: StateAbs, T <: TransitionAbs[L, S], L](atm: Automaton[S, T, L], _title: String, _prefix: String) extends DotConverter[S, T](atm.graph, _title, _prefix) {
Expand Down

0 comments on commit 9a54c4c

Please sign in to comment.