private void resetEngine() { this.pe = new PrologEngine(new SpaceIO("[VS:csp] ")); SpaceIO.loadSource(ref pe); VSAlgo.logProlog("---Engine reset---"); }
//execute next query with optional removal of items public void nextQuery(string cmd, int atpos = -1) { VSHistoryItem hi = new VSHistoryItem(ref cmd); if (atpos >= 0) { this.items.RemoveRange(atpos, (this.items.Count - atpos)); this.resetEngine(); //rebuild history VSAlgo.setUserStatus("odtwarzanie historii..."); for (int i = 0; i <= atpos; i++) { this.pe.Query = this.buildQuery(this.items[i].cmd, i); foreach (PrologEngine.ISolution s in this.pe.SolutionIterator) { if (this.pe.Error) { VSAlgo.reportError("niepowodzenie w odtwarzaniu historii; sprawdź konsolę", "History rewind error on item " + i + ": " + s, "History rewind error on item " + i); this.pe.clearError(); } } this.persist(); } } this.pe.Query = this.buildQuery(cmd, atpos); VSAlgo.logProlog("Exec: " + this.pe.Query, false); bool first = true; foreach (PrologEngine.ISolution s in this.pe.SolutionIterator) { if (this.pe.Error) { VSAlgo.reportError("nieudane zatwierdzanie; sprawdź konsolę", "History commit error: " + s, "History commit error"); this.pe.clearError(); } else if (first) { foreach (PrologEngine.IVarValue vv in s.VarValuesIterator) { if (vv.Name == "UpdatedG") { hi.gen = vv.Value.ToString(); } else if (vv.Name == "UpdatedS") { hi.spec = vv.Value.ToString(); } } VSAlgo.setUserStatus("aktualizacja przestrzeni..."); VSAlgo.logPrologCont(s.ToString()); //don't crawl through other results first = false; } else { break; } } this.persist(); if (!VSAlgo.Error) { bool solved = false; this.setLists(hi.spec, ref hi.listSpec); this.setLists(hi.gen, ref hi.listGen); VSAlgo.setProposed(null); hi.lviCmd.ForeColor = System.Drawing.Color.Yellow; this.pe.Query = "covers_both(" + hi.gen + ", " + hi.spec + ")"; foreach (PrologEngine.ISolution s in this.pe.SolutionIterator) { if (this.pe.Error) { VSAlgo.reportError("nieudane sprawdzenie pokrycia; sprawdź konsolę", "Cover test error: " + s, "Cover test error"); this.pe.clearError(); } else if (solved = s.Solved) { SpaceForm.self.lvVSHistory.SelectedItems.Clear(); VSAlgo.setProposed(hi.listGen[0].Text); } else { break; } } //add colors if (!solved) { if (Regex.IsMatch(cmd, @"^[ ]*(negative)\(.*$")) { hi.lviCmd.ForeColor = System.Drawing.Color.DarkRed; } else { hi.lviCmd.ForeColor = System.Drawing.Color.DarkGreen; } } this.items.Add(hi); } }