Skip to content

Commit

Permalink
Hack in support for labels
Browse files Browse the repository at this point in the history
  • Loading branch information
amandasystems committed Jul 1, 2021
1 parent 9ae315f commit 9148260
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
1 change: 1 addition & 0 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.5.3
43 changes: 38 additions & 5 deletions src/main/scala/ostrich/Automaton.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ import scala.collection.mutable.{HashMap => MHashMap,

import uuverifiers.parikh_theory.{
Automaton => OtherAutomaton,
LengthCounting
LengthCounting,
SymbolicLabel
}

/**
Expand Down Expand Up @@ -85,6 +86,8 @@ trait Automaton {
*/
def assertLengthConstraint(lengthTerm: Term, prover: SimpleAPI) : Unit

def toAmandaAutomaton(): OtherAutomaton

}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -154,6 +157,8 @@ trait TLabelOps[TLabel] {
* Get representation of interval [min,max]
*/
def interval(min : Char, max : Char) : TLabel

def labelToSymbolicLabel(label: TLabel): SymbolicLabel
}

/**
Expand Down Expand Up @@ -193,7 +198,7 @@ trait TLabelEnumerator[TLabel] {
* don't have any structure and are not composite, there is a unique
* initial state, and a set of accepting states.
*/
trait AtomicStateAutomaton extends Automaton with OtherAutomaton {
trait AtomicStateAutomaton extends Automaton {
/**
* Type of states
*/
Expand All @@ -204,7 +209,7 @@ trait AtomicStateAutomaton extends Automaton with OtherAutomaton {
*/
type TLabel

type Label = TLabel


/**
* Operations on labels
Expand Down Expand Up @@ -259,10 +264,38 @@ trait AtomicStateAutomaton extends Automaton with OtherAutomaton {
//////////////////////////////////////////////////////////////////////////
// Derived methods



/**
* I gave up and made these
*/
override lazy val toAmandaAutomaton: OtherAutomaton = {
val parent = this

object AutomatonAdapter extends OtherAutomaton {
import uuverifiers.parikh_theory.AutomataTypes.{State => OtherState}

// This really is not exactly a beautiful solution but let's go.
val stateToIndex: Map[parent.State, OtherState] = parent.states.zipWithIndex.toMap
lazy val indexToState: Map[OtherState, parent.State] = stateToIndex.map(_.swap)

val initialState: OtherState = stateToIndex(parent.initialState)
def isAccept(s: OtherState): Boolean = parent.isAccept(indexToState(s))
def outgoingTransitions(from: OtherState): Iterator[(OtherState, SymbolicLabel)] =
parent.outgoingTransitions(indexToState(from)).map{
case(s, l) =>
(stateToIndex(s), parent.LabelOps.labelToSymbolicLabel(l))
}
def states: Iterable[OtherState] = parent.states.map(stateToIndex)
}

AutomatonAdapter
}

/**
* Iterate over all transitions
*/
override def transitions : Iterator[(State, TLabel, State)] =
def transitions : Iterator[(State, TLabel, State)] =
for (s1 <- states.iterator; (s2, lbl) <- outgoingTransitions(s1))
yield (s1, lbl, s2)

Expand Down Expand Up @@ -340,7 +373,7 @@ trait AtomicStateAutomaton extends Automaton with OtherAutomaton {
}

// Spare us running multiple instantiations (it might be expensive)
lazy private val lengthTheory = LengthCounting(IndexedSeq(this))
lazy private val lengthTheory = LengthCounting(IndexedSeq(toAmandaAutomaton))

/**
* Compute the length abstraction of this automaton.
Expand Down
4 changes: 4 additions & 0 deletions src/main/scala/ostrich/BricsAutomaton.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import scala.collection.mutable.{HashMap => MHashMap,
MultiMap => MMultiMap,
Set => MSet}
import scala.jdk.CollectionConverters._
import uuverifiers.parikh_theory.SymbolicLabel

object BricsAutomaton {
private def toBAutomaton(aut : Automaton) : BAutomaton = aut match {
Expand Down Expand Up @@ -212,6 +213,9 @@ object BricsTLabelOps extends TLabelOps[(Char, Char)] {
* Get representation of interval [min,max]
*/
def interval(min : Char, max : Char) : (Char, Char) = (min, max)

def labelToSymbolicLabel(label: (Char, Char)): SymbolicLabel =
SymbolicLabel(label._1, label._2)
}

class BricsTLabelEnumerator(labels: Iterator[(Char, Char)])
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/ostrich/Exploration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ abstract class Exploration(val funApps : Seq[(PreOp, Seq[Term], Term)],
sources : Seq[Automaton]) : Unit = {
// FIXME cache the theory using Princess LRUcache and/or move to AutomataUtils
// FIXME change the type to require AtomicStateAutomaton here
val automata = sources.map(_.asInstanceOf[AtomicStateAutomaton]).toIndexedSeq
val automata = sources.map(_.toAmandaAutomaton()).toIndexedSeq
val lengthTheory = LengthCounting(automata)

for (prover <- lengthProver) {
Expand Down

0 comments on commit 9148260

Please sign in to comment.