diff --git a/IncrementalMinimization/src/Main.java b/IncrementalMinimization/src/Main.java index 6d869282..1d409a6d 100644 --- a/IncrementalMinimization/src/Main.java +++ b/IncrementalMinimization/src/Main.java @@ -1,8 +1,10 @@ +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; +import java.util.List; import java.util.Set; import org.apache.commons.lang3.NotImplementedException; @@ -19,44 +21,116 @@ public class Main { private static class EquivTest
{ - private SFA
aut;
- private HashSet aut;
+ private final BooleanAlgebra ba;
+ private final DisjointSets aut, HashSet aut, BooleanAlgebra ba, DisjointSets pMove = outp.iterator().next();
+ P pGuard = pMove.guard;
+ for(SFAInputMove qMove : outq)
+ {
+ P qGuard = qMove.guard;
+ P pqAnd = ba.MkAnd(pGuard, qGuard);
+ if(ba.IsSatisfiable(pqAnd))
+ {
+ return Arrays.asList(pMove,qMove);
+ }
+ }
+ return null;
+ }
+
+ public boolean isEquiv(Integer p, Integer q) throws TimeoutException
{
- //TODO
- throw new NotImplementedException("Incremental Equivalence Not Implemented Yet");
+ List pMove = nonDisjointGuards.get(0);
+ SFAInputMove qMove = nonDisjointGuards.get(1);
+ //note: we don't actually need to generate a witness, only need to know pMove,qMove are non-disjoint
+ Integer pNextClass = equivClasses.find(pMove.to);
+ Integer qNextClass = equivClasses.find(qMove.to);
+ List (pMove.from, pMove.to, newPGuard));
+ }
+ P newQGuard = ba.MkAnd(qMove.guard, ba.MkNot(pMove.guard));
+ if (ba.IsSatisfiable(newQGuard))
+ {
+ outq.add(new SFAInputMove (qMove.from, qMove.to, newQGuard));
+ }
+ }
+ equiv.add(pair);
+ return true;
}
- public HashSet incrementalMinimize(SFA aut, BooleanAlgebra<
{
return SFA.getEmptySFA(ba);
}
- aut = aut.determinize(ba).mkTotal(ba);
+ aut = aut.determinize(ba).mkTotal(ba); //TODO: normalizes?
DisjointSets SFA incrementalMinimize(SFA aut, BooleanAlgebra<
{
continue;
}
- Integer[] pair = new Integer[]{p,q};
+ List pEquiv = new EquivTest (aut, equiv, path);
+ HashSet pEquiv = new EquivTest (aut, ba, equivClasses, neq, equiv, path);
if(pEquiv.isEquiv(p,q))
{
//p,q found equivalent. Other pairs may be found equivalent.
- for(Integer[] equivPair : pEquiv.getEquiv())
+ for(List> neq;
+ private HashSet
> equiv;
+ private HashSet
> path;
+
+ public EquivTest(SFA
> neq, HashSet
> equiv, HashSet
> path)
{
this.aut = aut;
+ this.ba = ba;
+ this.equivClasses = equivClasses;
+ this.neq = neq;
this.equiv = equiv;
this.path = path;
}
- public boolean isEquiv(Integer p, Integer q) throws NotImplementedException
+ private List
> getEquiv()
{
return equiv;
}
- public HashSet
> getPath()
{
return path;
}
}
- private static Integer[] normalize(Integer p, Integer q)
+ private static List
SFA
> neq = new HashSet
>(num_pairs, 1); //set is given initial capacity of n^2, won't exceed this
for(Integer p : aut.getFinalStates())
{
for(Integer q : aut.getNonFinalStates())
@@ -91,10 +165,9 @@ public static
> equiv = new HashSet
>(num_pairs,1);
+ HashSet
> path = new HashSet
>(num_pairs,1);
+ EquivTest