public string PromptFactOperation(MainForm mf, string operation) { up.lastHRFFact = mf.PromptForString("Manual Fact " + operation, "Enter a fact in Human Readable Format (ASCII):", up.lastHRFFact); if (up.lastHRFFact != String.Empty) { if (!up.lastHRFFact.EndsWith(";")) { up.lastHRFFact += ";"; } int iniNbFacts = ie.FactsCount; using (HRF086Adapter hrfa = new HRF086Adapter(new MemoryStream(Encoding.ASCII.GetBytes("#DIRECTION_FORWARD\n\r+" + up.lastHRFFact)), FileAccess.Read)) { foreach (Fact f in hrfa.Facts) { if (operation == "Assertion") { ie.Assert(f); } else { ie.Retract(f); } } } if (iniNbFacts != ie.FactsCount) { return(up.lastHRFFact); } } return(String.Empty); }
public void Run() { mc.threadMap.Add(Thread.CurrentThread, stresserID); //Console.WriteLine("Stresser {0} Starting...", stresserID); try { while (mc.running) { mc.hits++; bumps++; a = mc.rnd.Next(1, 1 + LIMIT); b = mc.rnd.Next(1, 1 + LIMIT); ie.NewWorkingMemory(WorkingMemoryTypes.Isolated); if ((ie.Label != "subtract") && (binder)) { Hashtable bo = new Hashtable(); bo.Add(ie.Label + "-a", a); bo.Add(ie.Label + "-b", b); ie.Process(bo); } else { ie.Assert(new Fact("values", new Individual(a), new Individual(b))); ie.Process(); } if (ie.FactsCount != 2) { throw new Exception("Got wrong fact count: " + ie.FactsCount); } result = (int)ie.GetFact("result").GetPredicateValue(0); if (((ie.Label == "multiply") && (result != (7 + a * b))) || ((ie.Label == "add") && (result != (3 + a + b))) || ((ie.Label == "subtract") && (result != (11 + a - b)))) { mc.errors++; //Console.Write("[{0}?{1}={2}:{3}] ", a, b, result, ie.Label); } else if ((ie.Label != "multiply") && (ie.Label != "add") && (ie.Label != "subtract")) { throw new Exception("Unknown label: " + ie.Label); } if (HOT_SWAP) { ie.DisposeIsolatedMemory(); } } if ((switched) && (ie.Label == RULES[0])) { throw new Exception("Thread should have switched, but is still: " + ie.Label); } //Console.WriteLine("Stresser {0} Stopped (bumps: {3} - label:{2})", stresserID, switched, ie.Label, bumps); } catch (Exception e) { mc.errors++; Console.WriteLine("Stresser {0} Dead (bumps: {2} - ActiveRule:{3} - label:{4})", stresserID, switched, bumps, ActiveRule, ie.Label); Console.WriteLine(e); } }