public static SimulationPath <A, S> RunSimulation(PDA <A, S> pda, A[] word) { var acceptanceResult = pda.AcceptsWord(word); if (!acceptanceResult.Accepts()) { throw new NoAcceptanceException("the pda does not accept the word, therefore, a simulation is not possible"); } var initialNode = SimulationNode <A, S> .InitialNode( new Configuration <A, S>(pda.InitialState, new Word <A>(word), CurrentStack <S> .WithSingleSymbol(pda.FirstStackSymbol)), pda.AcceptanceCondition); var frontChain = new List <SimulationNode <A, S> > { initialNode }; while (frontChain.Count() > 0) { var nodesAcceptedWord = frontChain.Where(node => node.HasAcceptedWord).ToList(); if (nodesAcceptedWord.Count() > 0) { return(SimulationPathFromFinalNode(nodesAcceptedWord.First())); } foreach (var node in frontChain) { node.DoStep(); } frontChain = frontChain.SelectMany(node => node.Children).ToList(); } throw new InvalidOperationException("the given pda does not accept the word, therefore a simulation is not possible"); }
public void Push(T value) { if (CurrentStorage == 'ㅇ') { _queue.Add(value); } else { CurrentStack.Push(value); } }
public T Pop() { if (CurrentStorage == 'ㅇ') { var res = _queue[0]; _queue.RemoveAt(0); return(res); } else { return(CurrentStack.Pop()); } }
/** Push element x to the back of queue. */ public void Push(int x) { Discriminator = !Discriminator; Stack <int> previousStack = PreviousStack; CurrentStack.Push(x); int stackCount = PreviousStack.Count; previousStack = ReverseStack(PreviousStack); for (int i = 0; i < stackCount; i++) { CurrentStack.Push(previousStack.Pop()); } }
public bool OrderMoneySum(int Value) { //Коды возврата нельзя выдать, вообще не хватает MoneyStacksCount = MoneyBox.ReturnMoneyStackCount(); int[] DesireStacks = GetValueToNoteConversion(Value); int L = MainUnitProcessor.GlobalNominals.Length; bool IsAvailable = true; for (int i = 0; i < L; i++) { if (MoneyStacksCount[i] < DesireStacks[i]) { IsAvailable = false; if (i != L - 1) //Если i четное - то в следующем номинале добавляем 5, иначе 2 { DesireStacks[i + 1] += (i % 2 == 0 || i == 0) ? (5 * (-MoneyStacksCount[i] + DesireStacks[i])) : (2 * (-MoneyStacksCount[i] + DesireStacks[i])); DesireStacks[i] = MoneyStacksCount[i]; } else { break; } } else { IsAvailable = true; } } if (IsAvailable) { Collections.MoneyStack CurrentStack; for (int i = 0; i < L; i++) { CurrentStack = MoneyBox.ReturnByIndex(i); CurrentStack.TakeMoneyFromStack(DesireStacks[i]); } return(true); } return(false); }
//--------------------------------------------------------------------------------- /// <summary> /// ProcessRecord - main processing goes here /// </summary> //--------------------------------------------------------------------------------- protected override void ProcessRecord() { ProcessSafely(() => { int stackLevel = (int)StackLevelAlias.Top; var stackName = (string)null; if (Name == null) { } else if (Level != null) { stackName = Name; if (TryParseLevelNumber(Level, out var parsedLevel)) { stackLevel = parsedLevel; } else { throw new ShortStackException("Stack level must be a number or [Top|Bottom|Root]"); } } else if (TryParseLevelNumber(Name, out var parsedLevel)) { stackLevel = parsedLevel; } else { stackName = Name; stackLevel = (int)StackLevelAlias.Top; } Handler.GoToStack(stackName, stackLevel); Print(ConsoleColor.White, $"Checked out to {GetCurrentStackLevel().LocalBranch}"); if (ObjectOutput.IsPresent) { WriteObject(CurrentStack.CurrentLevel()); } }); }
//FIXME: create own subclass class for derivation start node /// <summary> /// converts a derivation of a word in a CFG in 2NF, that was originally created from a PDA, back to a path in this PDA; /// this path is generated according to the converting-algorithm of a PDA to a CFG implemented in <see cref="PDAToCFGConverter{A, S}"/>; /// if this method is called on a CFG that does not fulfill the described conditions, it produces not useful result /// </summary> /// <param name="pda">pda</param> /// <param name="startSymbol">start symbol of the cfg</param> /// <param name="word">word of the derivation</param> /// <returns></returns> public SimulationPath <A, char> ConvertToPDASimulationPath(PDA <A, char> pda, GrammarSymbol startSymbol, A[] word) { Assertion.Assert(Symbol == startSymbol, "this method should only be called on the start node; FIXME to make it only availabe there"); Assertion.Assert(productionFromHere.Rhs.Count() == 1, "the first production should only lead to one element"); Assertion.Assert(children.Count() == 1, "the start symbol should only have one child"); var symbol = productionFromHere.Rhs[0].Name; var splitted = PDAToCFGConverter <A, char> .SplitNonTerminalId(symbol); var firstNode = Node <A, char> .InitialNode(new Configuration <A, char>(pda.States[splitted.Item1], new Word <A>(word), CurrentStack <char> .WithSingleSymbol(splitted.Item2))); var nodes = new List <Node <A, char> >() { firstNode }; children.First().ConvertToPDASimulationPath(nodes, pda); return(new SimulationPath <A, char>(nodes)); }
public void Pop() { CurrentStack.Pop(); }
public void Push(ComponentModel model, CreationContext context) { CurrentStack.Push(new Pair <ComponentModel, CreationContext>(model, context)); }
public virtual void ImportDocuments() { InitializeFolders(); var xmlPath = CurrentStack.First(); FileLogger.Info(LoggerName, "Importazione documenti per: " + xmlPath); var xmlInfo = new FileDocumentInfo(new FileInfo(xmlPath)); try { var deserialized = DeserializeXml(xmlPath); FileLogger.Info(LoggerName, "Deserializzato in: " + deserialized.GetType().ToString()); var documents = GetDocumentInfos(deserialized); if (documents.IsNullOrEmpty()) { throw new InvalidCastException("Nessun documento trovato per: " + xmlInfo.Name); } FileLogger.Info(LoggerName, "Documenti trovati: " + documents.Count.ToString()); SaveToBiblos(documents, deserialized); FileLogger.Info(LoggerName, "Salvataggio in Biblos completato."); var disposable = documents; disposable.Add(xmlInfo); MoveToBackup(disposable, Path.GetFileNameWithoutExtension(xmlInfo.Name)); FileLogger.Info(LoggerName, "Importazione documenti completata."); } catch (FileNotFoundException fnf) { FileLogger.Warn(LoggerName, "Uno o più documenti mancanti o non validi.", fnf); if (!IsExpired(xmlInfo.FileInfo, Parameters.PostponeMissingExpires)) { return; } var message = string.Format("Documenti mancanti per {0} del {1} da più di {2} giorni.", xmlInfo.Name, xmlInfo.FileInfo.CreationTime, Parameters.PostponeMissingExpires); var expired = new Exception(message, fnf); FileLogger.Error(LoggerName, "Importazione documenti interrotta.", expired); MoveToError(xmlInfo, Path.GetFileNameWithoutExtension(xmlInfo.Name), expired); } catch (EndpointNotFoundException enf) { var temp = new Exception("Servizio Biblos non disponibile.", enf); FileLogger.Warn(LoggerName, temp.Message, temp); OnParsingError(temp.ToVerboseString()); } catch (SignatureDocumentValidationException sdve) { FileLogger.Error(LoggerName, "Importazione documenti interrotta.", sdve); if (sdve.ToRetry) { FileLogger.Warn(LoggerName, string.Format(@"Il server di validazione firme ha restituito un errore temporaneo per il documento {0}. Il documento verrà lasciato nella directory corrente per provare nuovamente l'importazione.", xmlInfo.Name)); return; } FileDocumentInfo document = new FileDocumentInfo(new FileInfo(sdve.FilePath)); IList <FileDocumentInfo> documents = new List <FileDocumentInfo>() { document, xmlInfo }; MoveToRejected(documents, Path.GetFileNameWithoutExtension(xmlInfo.Name), sdve); } catch (Exception ex) { FileLogger.Error(LoggerName, "Importazione documenti interrotta.", ex); MoveToError(xmlInfo, Path.GetFileNameWithoutExtension(xmlInfo.Name), ex); } finally { FileLogger.Info(LoggerName, "Rimozione dallo stack: " + xmlPath); CurrentStack.Remove(xmlPath); } }
//--------------------------------------------------------------------------------- /// <summary> /// ProcessRecord - main processing goes here /// </summary> //--------------------------------------------------------------------------------- protected override void ProcessRecord() { base.ProcessRecord(); if (CurrentStack == null) { Print(ConsoleColor.Red, "You are not in a stacked branch. Use Get-Stacks to see available stacks."); return; } var danglingStatus = Handler.CheckServerForDanglingWork(); if (danglingStatus == DanglingWorkStatus.UncommittedChanges) { Print(ConsoleColor.Red, "There are uncommitted changes. Please commit your changes first."); return; } int startLevel, stopLevel; if (!this.TryParseLevelNumber(Start, out startLevel)) { if (String.IsNullOrEmpty(Start)) { startLevel = 1; } else { Print(ConsoleColor.Red, "Start is an invalid level number"); return; } } if (!this.TryParseLevelNumber(Stop, out stopLevel)) { if (String.IsNullOrEmpty(Stop)) { stopLevel = CurrentStack.CurrentLevel().Number; } else { Print(ConsoleColor.Red, "Stop is an invalid level number"); return; } } if (startLevel > stopLevel) { Print(ConsoleColor.Red, "Start must be an earlier level than Stop"); return; } StackLevel originalLevel = this.GetCurrentStackLevel(); for (int i = startLevel; i <= stopLevel; i++) { StackLevel level = this.CurrentStack.Levels[i]; this.Handler.GoToStack(this.CurrentStack.StackName, level.Number); level.FillDetails(this.Handler); if (level.UnpulledCommits.Any()) { //Pull and do a merge conflict } if (level.UnpushedCommits.Any() || level.UnpushedCommits.Any()) { this.Handler.PushStackLevel(); } } this.Handler.GoToStack(this.CurrentStack.StackName, originalLevel.Number); }