public CsAlgebra(IBooleanAlgebra <T> leafAlgebra, ICounter[] counters) { this.counters = counters; this.LeafAlgebra = leafAlgebra; this.NodeAlgebra = new BDDAlgebra <T>(leafAlgebra); __false = new CsPred <T>(this, (BDD <T>)NodeAlgebra.False); __true = new CsPred <T>(this, (BDD <T>)NodeAlgebra.True); this.K = counters.Length; TrueCsConditionSeq = CsConditionSeq.MkTrue(counters.Length); FalseCsConditionSeq = CsConditionSeq.MkFalse(counters.Length); }
/// <summary> /// Creates counter minterms for the given set of counting states and input predicate. /// </summary> /// <param name="list">list of counting states, possibly empty i.e. null</param> /// <param name="a">input predicate</param> /// <returns></returns> private IEnumerable <CsConditionSeq> GenerateCounterMinterms(ConsList <int> list, S a) { if (list == null) { yield return(CsConditionSeq.MkTrue(countingStates.Count)); } else { var a_moves = new List <Move <Tuple <Maybe <S>, Sequence <CounterOperation> > > >(GetMovesFrom(list.First, a)).ToArray(); var incr_exists = Array.Exists(a_moves, m => m.Label.Item2.First.OperationKind == CounterOp.INCR); var exit_exists = Array.Exists(a_moves, m => m.Label.Item2.First.OperationKind != CounterOp.INCR); var i = GetCounter(list.First).CounterId; foreach (var seq in GenerateCounterMinterms(list.Rest, a)) { if (a_moves.Length > 0) { if (incr_exists && exit_exists) { yield return(seq.Update(i, CsCondition.LOW)); if (!(IsSingletonCountingState(list.First) && GetCounter(list.First).LowerBound == GetCounter(list.First).UpperBound)) { yield return(seq.Update(i, CsCondition.MIDDLE)); } yield return(seq.Update(i, CsCondition.HIGH)); } else if (incr_exists) { yield return(seq.Update(i, CsCondition.CANLOOP)); } else if (exit_exists) { yield return(seq.Update(i, CsCondition.CANEXIT)); } else { throw new AutomataException(AutomataExceptionKind.InternalError_GenerateCounterMinterms); } } else { yield return(seq); } } } }