private static bool CheckIfStackIsEmpty <U, V>(PDA <U, V> pda, Transition <U, V> epsilonTransition, VirtualConfiguration <U, V> currentConfig) where U : IEquatable <U> where V : IEquatable <V> { if (currentConfig.stack.Count() == 0) { pda.RemoveTransition(epsilonTransition); pda.AddTransition().From(epsilonTransition.Origin.Id).To(currentConfig.state.Id).Read().Pop(epsilonTransition.StackSymbolIn).Push(); return(true); } return(false); }
private static bool CheckIfConfigIsStable <U, V>(PDA <U, V> pda, Transition <U, V> epsilonTransition, VirtualConfiguration <U, V> currentConfig) where U : IEquatable <U> where V : IEquatable <V> { var enterableTransitions = currentConfig.GetEnterableTransitions(); var enterableEpsilonTransitions = enterableTransitions.Where(t => t.SymbolIn.IsEmpty()).ToList(); Assertion.Assert(enterableEpsilonTransitions.Count <= 1, "a DPDA can only have one enterable epsilon transition in each configuration"); if (enterableEpsilonTransitions.Count == 0) { pda.RemoveTransition(epsilonTransition); foreach (var transition in enterableTransitions) { Assertion.Assert(!transition.SymbolIn.IsEmpty(), "there should be no epsilon transitions at this point"); var newStack = transition.StackSymbolsWritten.Concat(currentConfig.stack.Skip(1).ToList()).ToList(); pda.AddTransition().From(epsilonTransition.Origin.Id).To(transition.Target.Id).Read(transition.SymbolIn).Pop(epsilonTransition.StackSymbolIn).Push(newStack); } return(true); } return(false); }
/// <summary> /// checks whether a circle, that does not decrease the stack, was finished for the second time /// </summary> /// <param name="pda">DPDA</param> /// <param name="epsilonTransition">the initial transition which is examined</param> /// <param name="configPath">the path with all configurations</param> /// <returns></returns> private static bool CheckIfTransitionIsUseless <U, V>(PDA <U, V> pda, Transition <U, V> epsilonTransition, List <VirtualConfiguration <U, V> > configPath) where U : IEquatable <U> where V : IEquatable <V> { var currentConfig = configPath.Last(); var potentialCircleStarts = ((IEnumerable <VirtualConfiguration <U, V> >)configPath).Reverse().Skip(1).Where(c => c.IsStartOfNotDecreasingCircle(currentConfig)).ToList(); return(potentialCircleStarts.Any(circleStartConfig => { var i = configPath.IndexOf(circleStartConfig); var circleTransitions = configPath.Skip(i + 1).Select(c => c.transitionToHere).ToList(); if (i >= circleTransitions.Count()) { var potentialLastCircleRun = configPath.Skip(i + 1 - circleTransitions.Count).Take(circleTransitions.Count).Select(c => c.transitionToHere).ToList(); if (Enumerable.SequenceEqual(circleTransitions, potentialLastCircleRun)) { pda.RemoveTransition(epsilonTransition); return true; } return false; } return false; })); }