本文整理汇总了C#中Production.AddConditionToLHS方法的典型用法代码示例。如果您正苦于以下问题:C# Production.AddConditionToLHS方法的具体用法?C# Production.AddConditionToLHS怎么用?C# Production.AddConditionToLHS使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Production
的用法示例。
在下文中一共展示了Production.AddConditionToLHS方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetProductions
public List<Production> GetProductions()
{
List<Production> list = new List<Production>();
Production WhatsMyName = new Production("WhatsMyName");
WhatsMyName.Salience = 1;
Variable customer_var = new Variable("Customer");
Variable customer_name = new Variable("Customer.Name");
Variable site_status = new Variable("Customer.Status");
Variable site_status_name = new Variable("Customer.Status.Name");
WhatsMyName.AddConditionToLHS(new PositiveCondition("C1", customer_var, "$Customer.Name", customer_name));
WhatsMyName.AddConditionToLHS(new FunctionCondition("F1", customer_name, new FuncTerm("funcEquals", new funcEquals()), "Joe Blow"));
WhatsMyName.AddConditionToLHS(new PositiveCondition("C2", customer_var, "$Customer.Status", site_status));
WhatsMyName.AddConditionToLHS(new PositiveCondition("C3", site_status, "$Customer.Status.Name", site_status_name));
WhatsMyName.AddConditionToLHS(new FunctionCondition("F2", site_status_name, new FuncTerm("funcEquals", new funcEquals()), "Active"));
WhatsMyName.AddConditionToRHS(new SetCondition(customer_var, "Remarks", customer_name));
list.Add(WhatsMyName);
return list;
}
示例2: CollectionTest
public void CollectionTest()
{
CustomerFactory factory = new CustomerFactory(new ObjectContext(CreateDataStore()));
Customer customer = factory.FindFirst("Name = {0}", "Joe Blow");
IList<WME> factlist = customer.GenerateFactsForRootObject();
Assert.IsTrue(factlist.Count == 11, "Wrong count.");
Agenda agenda = new Agenda();
agenda.LoadRulesFromAssemblies = false;
Variable customer_var = new Variable("Customer");
Variable orders = new Variable("Orders");
Variable order = new Variable("Order");
Variable orderItems = new Variable("OrderItems");
Variable orderItem = new Variable("OrderItem");
Variable product = new Variable("Product");
//Variable comment = new Variable("Comment");
Variable description = new Variable("Description");
Production mostSimple = new Production("CollectionTest");
mostSimple.AddConditionToLHS(new PositiveCondition(customer_var, "$Customer.Orders", orders));
mostSimple.AddConditionToLHS(new PositiveCondition(orders, "$Customer.Orders.Order", order));
mostSimple.AddConditionToLHS(new PositiveCondition(order, "$Customer.Orders.Order.OrderItems", orderItems));
mostSimple.AddConditionToLHS(new PositiveCondition(orderItems, "$Customer.Orders.Order.OrderItems.OrderItem", orderItem));
mostSimple.AddConditionToLHS(new PositiveCondition(orderItem, "$Customer.Orders.Order.OrderItems.OrderItem.Product", product));
mostSimple.AddConditionToLHS(new PositiveCondition(product, "$Customer.Orders.Order.OrderItems.OrderItem.Product.Description", description));
mostSimple.AddConditionToLHS(new FunctionCondition(description, new FuncTerm("funcEquals", new funcEquals()), "Troll Food"));
mostSimple.AddConditionToRHS(new InvokeCondition("shout", customer_var, "Shout", "Yipee"));
mostSimple.AddConditionToRHS(new AssertCondition("Wow", customer_var, "eats", description));
agenda.AddProduction(mostSimple);
agenda.AddFacts(factlist);
agenda.Run();
agenda.VisualizeNetworkToFile(@"C:\Temp\CollectionTest.log", false);
Assert.IsTrue(agenda.TotalFacts == 11, "Bad");
Assert.IsTrue(agenda.ActionsTaken.Count == 1, "Bad");
Assert.IsTrue(agenda.ActionsSkipped.Count == 0, "Bad");
Assert.IsTrue(agenda.ActivatedRuleCount == 1, "Bad");
Assert.IsTrue(customer.Result != null && customer.Result.StartsWith("Shout"), "Did not invoke method.");
}
示例3: FirstAggTest
public void FirstAggTest()
{
CustomerFactory factory = new CustomerFactory(new ObjectContext(CreateDataStore()));
Customer customer = factory.FindFirst("Name = {0}", "Joe Blow");
IList<WME> factlist = customer.GenerateFactsForRootObject();
Assert.IsTrue(factlist.Count == 11, "Wrong count.");
Agenda agenda = new Agenda();
agenda.LoadRulesFromAssemblies = false;
Variable customer_var = new Variable("Customer");
Variable orders = new Variable("Orders");
Variable order = new Variable("Order");
Variable val = new Variable("?Value");
Aggregator ag = new Aggregator("Count of customer orders.");
ag.GroupBy = customer_var;
ag.AggregatorFunction = new Count("$Customer.Orders.Order", "$Customer.Orders.Count");
ag.AddConditionToLHS(new AND(customer_var, "$Customer.Orders", orders));
ag.AddConditionToLHS(new AND(orders, "$Customer.Orders.Order", order));
agenda.AddAggregator(ag);
Production mostSimple = new Production("If Big Spender");
mostSimple.AddConditionToLHS(new AND(customer_var, "$Customer.Orders.Count", val));
mostSimple.AddConditionToRHS(new INVOKE("shout", customer_var, "Shout", val));
agenda.AddProduction(mostSimple);
agenda.AddFacts(factlist);
agenda.Run();
agenda.VisualizeNetworkToFile(@"C:\Temp\FirstAggTest.log", false);
Assert.IsTrue(agenda.TotalFacts == 11, "Bad");
Assert.IsTrue(agenda.ActionsTaken.Count == 1, "Bad");
Assert.IsTrue(agenda.ActionsSkipped.Count == 0, "Bad");
Assert.IsTrue(agenda.ActivatedRuleCount == 1, "Bad");
Assert.IsTrue(customer.Result != null && customer.Result.StartsWith("Shout"), "Did not invoke method.");
}
示例4: FirstTest
public void FirstTest()
{
CustomerFactory factory = new CustomerFactory(new ObjectContext(CreateDataStore()));
Customer customer = factory.FindFirst("Status.Name = {0}", "Active");
Assert.IsNotNull(customer, "Should not be null.");
IList<WME> factlist = customer.GenerateFactsForRootObject();
Assert.IsTrue(factlist.Count == 11, "Wrong count.");
Agenda agenda = new Agenda();
agenda.LoadRulesFromAssemblies = false;
Variable customer_var = new Variable("Customer");
Variable customer_name = new Variable("Customer.Name");
Production mostSimple = new Production("Most Simple");
mostSimple.AddConditionToLHS(new PositiveCondition(customer_var, "$Customer.Name", customer_name));
mostSimple.AddConditionToRHS(new InvokeCondition("shout", customer_var, "Shout", customer_name));
agenda.AddProduction(mostSimple);
agenda.AddFacts(factlist);
agenda.Run();
agenda.VisualizeNetworkToFile(@"C:\Temp\NeoFirstTest.log", false);
Assert.IsTrue(agenda.TotalFacts == 11, "Bad");
Assert.IsTrue(agenda.ActionsTaken.Count == 1, "Bad");
Assert.IsTrue(agenda.ActionsSkipped.Count == 0, "Bad");
Assert.IsTrue(agenda.ActivatedRuleCount == 1, "Bad");
Assert.IsTrue(customer.Result != null && customer.Result.StartsWith("Shout"), "Did not invoke method.");
}
示例5: TestAddProduction
public void TestAddProduction()
{
Production prod = new Production();
prod.Label = "find-stack-of-two-blocks-to-the-left-of-a-red-block";
Variable x = new Variable("x");
Variable y = new Variable("y");
Variable z = new Variable("z");
prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y));
prod.AddConditionToLHS(new PositiveCondition("C2", y, "left of", z));
prod.AddConditionToLHS(new PositiveCondition("C3", z, "color", "red"));
AssertCondition rhs = new AssertCondition("C4", x, "is", "on top");
rhs.ConditionType = ConditionType.Assert;
prod.AddConditionToRHS(rhs);
Agenda agenda = new Agenda();
agenda.ConflictResolutionStrategy = new SalienceResolver();
agenda.AddProduction(prod);
WME wme1 = new WME("W1");
wme1.Fields[0] = "B1";
wme1.Fields[1] = "on";
wme1.Fields[2] = "B2";
agenda.AddFact(wme1);
WME wme2 = new WME("W2");
wme2.Fields[0] = "B1";
wme2.Fields[1] = "on";
wme2.Fields[2] = "B3";
agenda.AddFact(wme2);
WME wme3 = new WME("W3");
wme3.Fields[0] = "B1";
wme3.Fields[1] = "color";
wme3.Fields[2] = "red";
agenda.AddFact(wme3);
WME wme4 = new WME("W4");
wme4.Fields[0] = "B2";
wme4.Fields[1] = "on";
wme4.Fields[2] = "table";
agenda.AddFact(wme4);
WME wme5 = new WME("W5");
wme5.Fields[0] = "B2";
wme5.Fields[1] = "left of";
wme5.Fields[2] = "B3";
agenda.AddFact(wme5);
WME wme6 = new WME("W6");
wme6.Fields[0] = "B2";
wme6.Fields[1] = "color";
wme6.Fields[2] = "blue";
agenda.AddFact(wme6);
WME wme7 = new WME("W7");
wme7.Fields[0] = "B3";
wme7.Fields[1] = "left of";
wme7.Fields[2] = "B4";
agenda.AddFact(wme7);
WME wme8 = new WME("W8");
wme8.Fields[0] = "B3";
wme8.Fields[1] = "on";
wme8.Fields[2] = "table";
agenda.AddFact(wme8);
WME wme9 = new WME("W9");
wme9.Fields[0] = "B3";
wme9.Fields[1] = "color";
wme9.Fields[2] = "red";
agenda.AddFact(wme9);
agenda.Run();
agenda.VisualizeNetworkToFile(@"C:\Temp\TestAgenda.log", false);
Assert.IsTrue(agenda.ActivatedRuleCount == 1, "Rule did not fire.");
Assert.IsTrue(agenda.InferredFacts.Count == 1, "Bad");
}
示例6: RetractRule
public void RetractRule()
{
Agenda agenda = new Agenda();
agenda.ConflictResolutionStrategy = new SalienceResolver();
Variable x = new Variable("x");
Variable y = new Variable("y");
Variable z = new Variable("z");
Production prod = new Production("find-stack-of-two-blocks-to-the-left-of-a-red-block");
prod.Salience = 1;
prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y));
prod.AddConditionToLHS(new PositiveCondition("C2", y, "left of", z));
prod.AddConditionToLHS(new PositiveCondition("C3", z, "color", "red"));
prod.AddConditionToRHS(new AssertCondition("R1", x, "is", "on top"));
prod.AddConditionToRHS(new AssertCondition("R2", "mary", "looks", "fine"));
agenda.AddProduction(prod);
Production dependentProd = new Production("Dependent Production");
dependentProd.Salience = 55;
dependentProd.AddConditionToLHS(new AND("mary", "looks", "fine"));
dependentProd.AddConditionToRHS(new ASSERT("should", "not", "see"));
agenda.AddProduction(dependentProd);
Production retractProd = new Production("Retract Production");
retractProd.Salience = 50;
retractProd.AddConditionToLHS(new AND(x, "is", "on top"));
retractProd.AddConditionToRHS(new RETRACT("mary", "looks", "fine"));
agenda.AddProduction(retractProd);
WME wme1 = new WME("W1");
wme1.Fields[0] = "B1";
wme1.Fields[1] = "on";
wme1.Fields[2] = "B2";
agenda.AddFact(wme1);
WME wme2 = new WME("W2");
wme2.Fields[0] = "B1";
wme2.Fields[1] = "on";
wme2.Fields[2] = "B3";
agenda.AddFact(wme2);
WME wme3 = new WME("W3");
wme3.Fields[0] = "B1";
wme3.Fields[1] = "color";
wme3.Fields[2] = "red";
agenda.AddFact(wme3);
WME wme4 = new WME("W4");
wme4.Fields[0] = "B2";
wme4.Fields[1] = "on";
wme4.Fields[2] = "table";
agenda.AddFact(wme4);
WME wme5 = new WME("W5");
wme5.Fields[0] = "B2";
wme5.Fields[1] = "left of";
wme5.Fields[2] = "B3";
agenda.AddFact(wme5);
WME wme6 = new WME("W6");
wme6.Fields[0] = "B2";
wme6.Fields[1] = "color";
wme6.Fields[2] = "blue";
agenda.AddFact(wme6);
WME wme7 = new WME("W7");
wme7.Fields[0] = "B3";
wme7.Fields[1] = "left of";
wme7.Fields[2] = "B4";
agenda.AddFact(wme7);
WME wme8 = new WME("W8");
wme8.Fields[0] = "B3";
wme8.Fields[1] = "on";
wme8.Fields[2] = "table";
agenda.AddFact(wme8);
WME wme9 = new WME("W9");
wme9.Fields[0] = "B3";
wme9.Fields[1] = "color";
wme9.Fields[2] = "red";
agenda.AddFact(wme9);
agenda.Run();
agenda.VisualizeNetworkToFile(@"C:\Temp\RetractRule.log", false);
Assert.IsTrue(agenda.ActivatedRuleCount == 2, "Rule did not fire.");
Assert.IsTrue(agenda.NotActivatedRuleCount == 1, "Rule should not have fired.");
Assert.IsTrue(agenda.InferredFacts.Count == 1, "Bad");
}
示例7: SecondAggTest
public void SecondAggTest()
{
CustomerFactory factory = new CustomerFactory(new ObjectContext(CreateDataStore()));
ObjectList<Customer> customers = factory.FindAllObjects();
Agenda agenda = new Agenda();
agenda.LoadRulesFromAssemblies = false;
agenda.AddObjects(customers);
Variable customer_var = new Variable("Customer");
Variable orders = new Variable("Orders");
Variable order = new Variable("Order");
Variable count = new Variable("OrderCount");
Aggregator ag = new Aggregator("Count of customer orders.");
ag.GroupBy = customer_var;
ag.AggregatorFunction = new Count("$Customer.Orders.Order", "Customer.Orders.Count");
ag.AddConditionToLHS(new AND(customer_var, "$Customer.Orders", orders));
ag.AddConditionToLHS(new AND(orders, "$Customer.Orders.Order", order));
agenda.AddAggregator(ag);
Production mostSimple = new Production("If Big Spender");
mostSimple.AddConditionToLHS(new AND(customer_var, "Customer.Orders.Count", count));
mostSimple.AddConditionToRHS(new INVOKE("shout", customer_var, "Shout", count));
agenda.AddProduction(mostSimple);
agenda.Run();
agenda.VisualizeNetworkToFile(@"C:\Temp\SecondAggTest.log", false);
Assert.IsTrue(agenda.TotalFacts == 22, "Bad");
Assert.IsTrue(agenda.ActionsTaken.Count == 2, "Bad");
Assert.IsTrue(agenda.ActionsSkipped.Count == 0, "Bad");
Assert.IsTrue(agenda.ActivatedRuleCount == 1, "Bad");
foreach (Customer customer in customers)
{
Assert.IsTrue(customer.Result != null && customer.Result.StartsWith("Shout"), "Did not invoke method.");
}
}
示例8: GiveBestDiscount
public void GiveBestDiscount()
{
Agenda agenda = new Agenda();
agenda.ConflictResolutionStrategy = new SalienceResolver();
Variable customer = new Variable("customer");
Variable purchases = new Variable("purchases");
Variable discount = new Variable("discount");
Production SilverCustomer = new Production("Silver Customer");
SilverCustomer.AddConditionToLHS(new PositiveCondition("C1", customer, "purchases", purchases));
SilverCustomer.AddConditionToLHS(new FunctionCondition("C2", purchases, new FuncTerm("funcGreaterThan", new funcGreaterThan()), 10));
SilverCustomer.AddConditionToRHS(new AssertCondition("R1", customer, "is", "silver"));
agenda.AddProduction(SilverCustomer);
Production GoldCustomer = new Production("Gold Customer");
GoldCustomer.AddConditionToLHS(new PositiveCondition("C1", customer, "purchases", purchases));
GoldCustomer.AddConditionToLHS(new FunctionCondition("C2", purchases, new FuncTerm("funcGreaterThan", new funcGreaterThan()), 25));
GoldCustomer.AddConditionToRHS(new AssertCondition("R1", customer, "is", "gold"));
agenda.AddProduction(GoldCustomer);
Production PlatinumCustomer = new Production("Platinum Customer");
PlatinumCustomer.AddConditionToLHS(new PositiveCondition("C1", customer, "purchases", purchases));
PlatinumCustomer.AddConditionToLHS(new FunctionCondition("C2", purchases, new FuncTerm("funcGreaterThan", new funcGreaterThan()), 50));
PlatinumCustomer.AddConditionToRHS(new AssertCondition("R1", customer, "is", "platinum"));
agenda.AddProduction(PlatinumCustomer);
Production SilverDiscount = new Production("Silver Discount");
SilverDiscount.AddConditionToLHS(new PositiveCondition("C1", customer, "is", "silver"));
SilverDiscount.AddConditionToRHS(new AssertCondition("R1", customer, "give discount", 5));
agenda.AddProduction(SilverDiscount);
Production GoldDiscount = new Production("Gold Discount");
GoldDiscount.AddConditionToLHS(new PositiveCondition("C1", customer, "is", "gold"));
GoldDiscount.AddConditionToRHS(new AssertCondition("R1", customer, "give discount", 10));
agenda.AddProduction(GoldDiscount);
Production PlatinumDiscount = new Production("Platinum Discount");
PlatinumDiscount.AddConditionToLHS(new PositiveCondition("C1", customer, "is", "platinum"));
PlatinumDiscount.AddConditionToRHS(new AssertCondition("R1", customer, "give discount", 15));
agenda.AddProduction(PlatinumDiscount);
Mutex BestDiscount = new Mutex("Best Discount");
//BestDiscount.AddAggregator(new Max(), customer, new StringTerm("give discount"), discount);
BestDiscount.AddConditionToLHS(new PositiveCondition("C1", customer, "give discount", discount));
//BestDiscount.AddConditionToLHS(new condition("C2", ConditionType.Function, customer, "funcMax", discount));
BestDiscount.AddConditionToRHS(new InvokeCondition("R1", customer, "Customer.GiveDiscount", discount));
//BestDiscount.AddEvaluator(new Max(), customer, new StringTerm("give discount"), discount);
BestDiscount.Evaluator = new Max(customer, new StringTerm("give discount"), discount);
agenda.AddMutex(BestDiscount);
WME wme1 = new WME("W1");
wme1.Fields[0] = "joe";
wme1.Fields[1] = "purchases";
wme1.Fields[2] = "1";
agenda.AddFact(wme1);
WME wme2 = new WME("W2");
wme2.Fields[0] = "ted";
wme2.Fields[1] = "purchases";
wme2.Fields[2] = "10";
agenda.AddFact(wme2);
WME wme3 = new WME("W3");
wme3.Fields[0] = "ed";
wme3.Fields[1] = "purchases";
wme3.Fields[2] = "11";
agenda.AddFact(wme3);
WME wme4 = new WME("W4");
wme4.Fields[0] = "phil";
wme4.Fields[1] = "purchases";
wme4.Fields[2] = "18";
agenda.AddFact(wme4);
WME wme5 = new WME("W5");
wme5.Fields[0] = "mary";
wme5.Fields[1] = "purchases";
wme5.Fields[2] = "22";
agenda.AddFact(wme5);
WME wme6 = new WME("W6");
wme6.Fields[0] = "jane";
wme6.Fields[1] = "purchases";
wme6.Fields[2] = "25";
agenda.AddFact(wme6);
WME wme7 = new WME("W7");
wme7.Fields[0] = "fred";
wme7.Fields[1] = "purchases";
wme7.Fields[2] = "50";
agenda.AddFact(wme7);
WME wme8 = new WME("W8");
wme8.Fields[0] = "harry";
wme8.Fields[1] = "purchases";
wme8.Fields[2] = "55";
agenda.AddFact(wme8);
WME wme9 = new WME("W9");
//.........这里部分代码省略.........
示例9: ReteWithHash
public void ReteWithHash()
{
Production prod = new Production();
prod.Label = "ReteWithHash";
Variable a = new Variable("a");
Variable b = new Variable("b");
Variable c = new Variable("c");
Variable d = new Variable("d");
Variable s = new Variable("s");
Variable x = new Variable("x");
Variable y = new Variable("y");
Variable z = new Variable("z");
prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y));
prod.AddConditionToLHS(new PositiveCondition("C2", y, "left of", z));
prod.AddConditionToLHS(new PositiveCondition("C3", z, "color", "red"));
prod.AddConditionToLHS(new PositiveCondition("C4", a, "color", "maize"));
prod.AddConditionToLHS(new PositiveCondition("C5", b, "color", "blue"));
prod.AddConditionToLHS(new PositiveCondition("C6", c, "color", "green"));
prod.AddConditionToLHS(new PositiveCondition("C7", d, "color", "white"));
prod.AddConditionToLHS(new PositiveCondition("C8", s, "on", "table"));
prod.AddConditionToLHS(new PositiveCondition("C9", z, a, b));
prod.AddConditionToLHS(new PositiveCondition("C10", a, "left of", d));
prod.AddConditionToRHS(new AssertCondition("C4", x, "is", "on top"));
Rete rete = new Rete();
rete.AddProduction(prod);
NetworkPrinter printer = new NetworkPrinter();
rete.DummyTopNode.Accept(printer);
using (StreamWriter writer = new StreamWriter(@"C:\Temp\ReteWithHash-Pre.log", false))
{
writer.Write(printer.Output);
writer.Flush();
}
WME wme1 = new WME("W1");
wme1.Fields[0] = "B1";
wme1.Fields[1] = "on";
wme1.Fields[2] = "B2";
rete.AddWME(wme1);
WME wme2 = new WME("W2");
wme2.Fields[0] = "B1";
wme2.Fields[1] = "on";
wme2.Fields[2] = "B3";
rete.AddWME(wme2);
WME wme3 = new WME("W3");
wme3.Fields[0] = "B1";
wme3.Fields[1] = "color";
wme3.Fields[2] = "red";
rete.AddWME(wme3);
WME wme4 = new WME("W4");
wme4.Fields[0] = "B2";
wme4.Fields[1] = "on";
wme4.Fields[2] = "table";
rete.AddWME(wme4);
WME wme5 = new WME("W5");
wme5.Fields[0] = "B2";
wme5.Fields[1] = "left of";
wme5.Fields[2] = "B3";
rete.AddWME(wme5);
WME wme6 = new WME("W6");
wme6.Fields[0] = "B2";
wme6.Fields[1] = "color";
wme6.Fields[2] = "blue";
rete.AddWME(wme6);
WME wme7 = new WME("W7");
wme7.Fields[0] = "B3";
wme7.Fields[1] = "left of";
wme7.Fields[2] = "B4";
rete.AddWME(wme7);
WME wme8 = new WME("W8");
wme8.Fields[0] = "B3";
wme8.Fields[1] = "on";
wme8.Fields[2] = "table";
rete.AddWME(wme8);
WME wme9 = new WME("W9");
wme9.Fields[0] = "B3";
wme9.Fields[1] = "color";
wme9.Fields[2] = "red";
rete.AddWME(wme9);
printer = new NetworkPrinter();
rete.DummyTopNode.Accept(printer);
using (StreamWriter writer = new StreamWriter(@"C:\Temp\ReteWithHash.log", false))
{
writer.Write(printer.Output);
writer.Flush();
//.........这里部分代码省略.........
示例10: RemoveWME
public void RemoveWME()
{
Production prod = new Production();
prod.Label = "find-stack-of-two-blocks-to-the-left-of-a-red-block";
Variable x = new Variable("x");
Variable y = new Variable("y");
Variable z = new Variable("z");
prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y));
prod.AddConditionToLHS(new PositiveCondition("C2", y, "left of", z));
prod.AddConditionToLHS(new PositiveCondition("C3", z, "color", "red"));
AssertCondition rhs = new AssertCondition("C4", x, "is", "on top");
rhs.ConditionType = ConditionType.Assert;
prod.AddConditionToRHS(rhs);
Rete rete = new Rete();
rete.AddProduction(prod);
WME wme1 = new WME("W1");
wme1.Fields[0] = "B1";
wme1.Fields[1] = "on";
wme1.Fields[2] = "B2";
rete.AddWME(wme1);
WME wme2 = new WME("W2");
wme2.Fields[0] = "B1";
wme2.Fields[1] = "on";
wme2.Fields[2] = "B3";
rete.AddWME(wme2);
WME wme3 = new WME("W3");
wme3.Fields[0] = "B1";
wme3.Fields[1] = "color";
wme3.Fields[2] = "red";
rete.AddWME(wme3);
WME wme4 = new WME("W4");
wme4.Fields[0] = "B2";
wme4.Fields[1] = "on";
wme4.Fields[2] = "table";
rete.AddWME(wme4);
WME wme5 = new WME("W5");
wme5.Fields[0] = "B2";
wme5.Fields[1] = "left of";
wme5.Fields[2] = "B3";
rete.AddWME(wme5);
WME wme6 = new WME("W6");
wme6.Fields[0] = "B2";
wme6.Fields[1] = "color";
wme6.Fields[2] = "blue";
rete.AddWME(wme6);
WME wme7 = new WME("W7");
wme7.Fields[0] = "B3";
wme7.Fields[1] = "left of";
wme7.Fields[2] = "B4";
rete.AddWME(wme7);
WME wme8 = new WME("W8");
wme8.Fields[0] = "B3";
wme8.Fields[1] = "on";
wme8.Fields[2] = "table";
rete.AddWME(wme8);
WME wme9 = new WME("W9");
wme9.Fields[0] = "B3";
wme9.Fields[1] = "color";
wme9.Fields[2] = "red";
rete.AddWME(wme9);
Assert.IsTrue(prod.InferredFacts.Count == 1, "Wrong number of conclusions");
Assert.IsTrue(rete.WorkingMemory.Count == 9, "Bad");
rete.RemoveWME(wme9);
Assert.IsTrue(prod.InferredFacts.Count == 0, "Wrong number of conclusions");
Assert.IsTrue(rete.WorkingMemory.Count == 8, "Bad");
}
示例11: NegativeConditionTest
public void NegativeConditionTest()
{
Production prod = new Production();
prod.Label = "find-stack-of-two-blocks-to-the-left-of-a-red-block";
Variable x = new Variable("x");
Variable y = new Variable("y");
Variable z = new Variable("z");
//Variable c = new Variable("c");
prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y));
prod.AddConditionToLHS(new PositiveCondition("C2", y, "left of", z));
//prod.AddConditionToLHS(new condition("C3", z, "color", c));
NegativeCondition neg = new NegativeCondition("C3", z, "color", "blue");
neg.ConditionType = ConditionType.Negative;
//neg.IsPositive = false;
//neg.IsNegative = true;
prod.AddConditionToLHS(neg);
AssertCondition rhs = new AssertCondition("C4", x, "is", "on top");
rhs.ConditionType = ConditionType.Assert;
prod.AddConditionToRHS(rhs);
Rete rete = new Rete();
rete.AddProduction(prod);
WME wme1 = new WME("W1");
wme1.Fields[0] = "B1";
wme1.Fields[1] = "on";
wme1.Fields[2] = "B2";
rete.AddWME(wme1);
WME wme2 = new WME("W2");
wme2.Fields[0] = "B1";
wme2.Fields[1] = "on";
wme2.Fields[2] = "B3";
rete.AddWME(wme2);
WME wme3 = new WME("W3");
wme3.Fields[0] = "B1";
wme3.Fields[1] = "color";
wme3.Fields[2] = "red";
rete.AddWME(wme3);
WME wme4 = new WME("W4");
wme4.Fields[0] = "B2";
wme4.Fields[1] = "on";
wme4.Fields[2] = "table";
rete.AddWME(wme4);
WME wme5 = new WME("W5");
wme5.Fields[0] = "B2";
wme5.Fields[1] = "left of";
wme5.Fields[2] = "B3";
rete.AddWME(wme5);
WME wme6 = new WME("W6");
wme6.Fields[0] = "B2";
wme6.Fields[1] = "color";
wme6.Fields[2] = "blue";
rete.AddWME(wme6);
WME wme7 = new WME("W7");
wme7.Fields[0] = "B3";
wme7.Fields[1] = "left of";
wme7.Fields[2] = "B4";
rete.AddWME(wme7);
WME wme8 = new WME("W8");
wme8.Fields[0] = "B3";
wme8.Fields[1] = "on";
wme8.Fields[2] = "table";
rete.AddWME(wme8);
WME wme9 = new WME("W9");
wme9.Fields[0] = "B3";
wme9.Fields[1] = "color";
wme9.Fields[2] = "red";
rete.AddWME(wme9);
//WME wme10 = new WME("W10");
//wme10.fields[0] = "B4";
//wme10.fields[1] = "color";
//wme10.fields[2] = "green";
//rete.add_wme(wme10);
//rete_node dummy = rete.DummyTopNode;
NetworkPrinter printer = new NetworkPrinter();
rete.DummyTopNode.Accept(printer);
using (StreamWriter writer = new StreamWriter(@"C:\Temp\NegativeConditionTest.log", false))
{
writer.Write(printer.Output);
writer.Flush();
}
//Assert.IsTrue(rete.RulesThatFired.Count == 1, "Rule did not fire.");
Assert.IsTrue(prod.InferredFacts.Count == 1, "Wrong number of conclusions");
//.........这里部分代码省略.........
示例12: MultiBuiltinTest
public void MultiBuiltinTest()
{
Production prod = new Production();
prod.Label = "find-stack-of-two-blocks-to-the-left-of-a-red-block";
Variable x = new Variable("x");
Variable y = new Variable("y");
//Variable z = new Variable("z");
Variable c = new Variable("c");
prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y));
//prod.AddConditionToLHS(new condition("C2", y, "left of", z));
prod.AddConditionToLHS(new PositiveCondition("C3", x, "color", c));
FunctionCondition funCond = new FunctionCondition("F4", c, new FuncTerm("funcNotEquals", new funcNotEquals()), new StringTerm("blue"));
funCond.ConditionType = ConditionType.Function;
prod.AddConditionToLHS(funCond);
prod.AddConditionToRHS(new AssertCondition("C4", x, "is", c));
Rete rete = new Rete();
rete.AddProduction(prod);
NetworkPrinter printer = new NetworkPrinter();
rete.DummyTopNode.Accept(printer);
using (StreamWriter writer = new StreamWriter(@"C:\Temp\MultiBuiltinTest.log", false))
{
writer.Write(printer.Output);
writer.WriteLine();
writer.WriteLine();
writer.WriteLine();
writer.WriteLine();
writer.WriteLine("-----------------------------------------------");
writer.Flush();
}
WME wme1 = new WME("W1");
wme1.Fields[0] = "B1";
wme1.Fields[1] = "on";
wme1.Fields[2] = "B2";
rete.AddWME(wme1);
WME wme2 = new WME("W2");
wme2.Fields[0] = "B1";
wme2.Fields[1] = "on";
wme2.Fields[2] = "B3";
rete.AddWME(wme2);
WME wme3 = new WME("W3");
wme3.Fields[0] = "B1";
wme3.Fields[1] = "color";
wme3.Fields[2] = "red";
rete.AddWME(wme3);
WME wme4 = new WME("W4");
wme4.Fields[0] = "B2";
wme4.Fields[1] = "on";
wme4.Fields[2] = "table";
rete.AddWME(wme4);
WME wme5 = new WME("W5");
wme5.Fields[0] = "B2";
wme5.Fields[1] = "left of";
wme5.Fields[2] = "B3";
rete.AddWME(wme5);
WME wme6 = new WME("W6");
wme6.Fields[0] = "B2";
wme6.Fields[1] = "color";
wme6.Fields[2] = "blue";
rete.AddWME(wme6);
WME wme7 = new WME("W7");
wme7.Fields[0] = "B3";
wme7.Fields[1] = "left of";
wme7.Fields[2] = "B4";
rete.AddWME(wme7);
WME wme8 = new WME("W8");
wme8.Fields[0] = "B3";
wme8.Fields[1] = "on";
wme8.Fields[2] = "table";
rete.AddWME(wme8);
WME wme9 = new WME("W9");
wme9.Fields[0] = "B3";
wme9.Fields[1] = "color";
wme9.Fields[2] = "red";
rete.AddWME(wme9);
printer = new NetworkPrinter();
rete.DummyTopNode.Accept(printer);
using (StreamWriter writer = new StreamWriter(@"C:\Temp\MultiBuiltinTest.log", true))
{
writer.WriteLine();
writer.WriteLine();
writer.WriteLine();
writer.WriteLine();
writer.Write(printer.Output);
writer.Flush();
//.........这里部分代码省略.........
示例13: GrandParents
public void GrandParents()
{
Rete rete = new Rete();
Production prod = new Production();
prod.Label = "Whose your daddy";
Variable x = new Variable("x");
Variable y = new Variable("y");
Variable z = new Variable("z");
prod.AddConditionToLHS(new PositiveCondition(x, "parent", y));
prod.AddConditionToRHS(new AssertCondition(y, "child", x));
rete.AddProduction(prod);
Production prod1 = new Production();
prod1.Label = "Whose your grand daddy";
prod1.AddConditionToLHS(new PositiveCondition(x, "parent", y));
prod1.AddConditionToLHS(new PositiveCondition(y, "parent", z));
prod1.AddConditionToRHS(new AssertCondition(x, "gparent", z));
rete.AddProduction(prod1);
Production prod2 = new Production();
prod2.Label = "Whose your grand child";
prod2.AddConditionToLHS(new PositiveCondition(x, "gparent", y));
prod2.AddConditionToRHS(new AssertCondition(y, "gchild", x));
rete.AddProduction(prod2);
Production prod3 = new Production();
prod3.Label = "Whose your great grand daddy";
prod3.AddConditionToLHS(new PositiveCondition(x, "parent", y));
prod3.AddConditionToLHS(new PositiveCondition(y, "gparent", z));
prod3.AddConditionToRHS(new AssertCondition(x, "ggparent", z));
rete.AddProduction(prod3);
List<WME> wmes = new List<WME>();
wmes.Add(new WME("george", "gchild", "kendall"));
wmes.Add(new WME("kendall", "parent", "immanuel"));
wmes.Add(new WME("louis", "gparent", "richard"));
wmes.Add(new WME("jacques", "parent", "jean-francois"));
wmes.Add(new WME("friedrich", "parent", "louis"));
wmes.Add(new WME("louis", "gparent", "willard"));
wmes.Add(new WME("willard", "gchild", "ludwig"));
wmes.Add(new WME("miles", "parent", "ludwig"));
wmes.Add(new WME("ludwig", "gchild", "noam"));
wmes.Add(new WME("miles", "gparent", "wilhelm"));
wmes.Add(new WME("friedrich", "parent", "jean-francois"));
wmes.Add(new WME("bijan", "gchild", "george"));
wmes.Add(new WME("wilhelm", "gparent", "bertrand"));
wmes.Add(new WME("alan", "parent", "bijan"));
wmes.Add(new WME("kendall", "parent", "gottlob"));
wmes.Add(new WME("david", "gchild", "bertrand"));
wmes.Add(new WME("alan", "gchild", "henry"));
wmes.Add(new WME("kendall", "gparent", "louis"));
wmes.Add(new WME("willard", "gchild", "willard"));
wmes.Add(new WME("richard", "gchild", "pat"));
wmes.Add(new WME("miles", "parent", "friedrich"));
wmes.Add(new WME("noam", "gparent", "ludwig"));
wmes.Add(new WME("jean-francois", "gchild", "bertrand"));
wmes.Add(new WME("louis", "parent", "bijan"));
wmes.Add(new WME("willard", "parent", "kendall"));
wmes.Add(new WME("gottlob", "gparent", "kendall"));
wmes.Add(new WME("immanuel", "gchild", "wilhelm"));
wmes.Add(new WME("george", "parent", "drew"));
wmes.Add(new WME("friedrich", "gchild", "david"));
wmes.Add(new WME("gottlob", "gchild", "bertrand"));
wmes.Add(new WME("wilhelm", "parent", "ludwig"));
wmes.Add(new WME("henry", "gchild", "willard"));
wmes.Add(new WME("alan", "gchild", "richard"));
wmes.Add(new WME("george", "gchild", "miles"));
wmes.Add(new WME("george", "gparent", "willard"));
wmes.Add(new WME("alasdair", "gparent", "willard"));
wmes.Add(new WME("willard", "gparent", "immanuel"));
wmes.Add(new WME("jacques", "gparent", "george"));
wmes.Add(new WME("henry", "gchild", "rudolf"));
wmes.Add(new WME("wilhelm", "gparent", "miles"));
wmes.Add(new WME("noam", "gparent", "jean-francois"));
wmes.Add(new WME("pat", "gchild", "friedrich"));
wmes.Add(new WME("rudolf", "gchild", "david"));
wmes.Add(new WME("john", "gchild", "stanley"));
wmes.Add(new WME("jacques", "gchild", "bijan"));
wmes.Add(new WME("george", "parent", "miles"));
wmes.Add(new WME("louis", "parent", "drew"));
wmes.Add(new WME("rudolf", "parent", "jacques"));
wmes.Add(new WME("bertrand", "gparent", "ludwig"));
wmes.Add(new WME("gottlob", "parent", "john"));
wmes.Add(new WME("miles", "gchild", "miles"));
wmes.Add(new WME("bijan", "gchild", "noam"));
wmes.Add(new WME("jean-francois", "gparent", "george"));
wmes.Add(new WME("miles", "gparent", "henry"));
wmes.Add(new WME("kendall", "gchild", "ludwig"));
wmes.Add(new WME("louis", "gparent", "david"));
wmes.Add(new WME("noam", "parent", "george"));
//.........这里部分代码省略.........
示例14: EvaluatorTest
public void EvaluatorTest()
{
Production prod = new Production();
prod.Label = "find-stack-of-two-blocks-to-the-left-of-a-red-block";
Variable x = new Variable("x");
Variable y = new Variable("y");
Variable z = new Variable("z");
//Variable c = new Variable("c");
prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y));
prod.AddConditionToLHS(new PositiveCondition("C2", y, "left of", z));
//prod.AddConditionToLHS(new condition("C3", z, "color", "red"));
PositiveCondition noteq = new PositiveCondition("NOT BLUE", x, "color", "blue");
noteq.Evaluator = EvaluatorManager.Instance.Evaluators["NotEquals"];
prod.AddConditionToLHS(noteq);
prod.AddConditionToRHS(new AssertCondition("C5", x, "calls", z));
Rete rete = new Rete();
rete.AddProduction(prod);
WME wme1 = new WME("W1");
wme1.Fields[0] = "B1";
wme1.Fields[1] = "on";
wme1.Fields[2] = "B2";
rete.AddWME(wme1);
WME wme2 = new WME("W2");
wme2.Fields[0] = "B1";
wme2.Fields[1] = "on";
wme2.Fields[2] = "B3";
rete.AddWME(wme2);
WME wme3 = new WME("W3");
wme3.Fields[0] = "B1";
wme3.Fields[1] = "color";
wme3.Fields[2] = "red";
rete.AddWME(wme3);
WME wme4 = new WME("W4");
wme4.Fields[0] = "B2";
wme4.Fields[1] = "on";
wme4.Fields[2] = "table";
rete.AddWME(wme4);
WME wme5 = new WME("W5");
wme5.Fields[0] = "B2";
wme5.Fields[1] = "left of";
wme5.Fields[2] = "B3";
rete.AddWME(wme5);
WME wme6 = new WME("W6");
wme6.Fields[0] = "B2";
wme6.Fields[1] = "color";
wme6.Fields[2] = "blue";
rete.AddWME(wme6);
WME wme7 = new WME("W7");
wme7.Fields[0] = "B3";
wme7.Fields[1] = "left of";
wme7.Fields[2] = "B4";
rete.AddWME(wme7);
WME wme8 = new WME("W8");
wme8.Fields[0] = "B3";
wme8.Fields[1] = "on";
wme8.Fields[2] = "table";
rete.AddWME(wme8);
WME wme9 = new WME("W9");
wme9.Fields[0] = "B3";
wme9.Fields[1] = "color";
wme9.Fields[2] = "red";
rete.AddWME(wme9);
NetworkPrinter printer = new NetworkPrinter();
rete.DummyTopNode.Accept(printer);
using (StreamWriter writer = new StreamWriter(@"C:\Temp\EvaluatorTest.log", false))
{
writer.Write(printer.Output);
writer.Flush();
}
Assert.IsTrue(prod.InferredFacts.Count == 2, "Wrong number of conclusions");
Assert.IsTrue(rete.WorkingMemory.Count == 9, "Bad");
}
示例15: Test2
public void Test2()
{
CustomerFactory factory = new CustomerFactory(new ObjectContext(CreateDataStore()));
ObjectList<Customer> customers = factory.Find("Status.Name = {0}", "Active");
Assert.IsNotNull(customers.Count >= 2, "Should not be at least 2.");
Agenda agenda = new Agenda();
agenda.ConflictResolutionStrategy = new SalienceResolver();
agenda.LoadRulesFromAssemblies = false;
agenda.AddObjects(customers);
Production WhatsMyName = new Production("Whats My Name");
WhatsMyName.Salience = 1;
Variable customer_var = new Variable("Customer");
Variable customer_name = new Variable("Name");
WhatsMyName.AddConditionToLHS(new PositiveCondition("C2", customer_var, "$Customer.Name", customer_name));
WhatsMyName.AddConditionToLHS(new FunctionCondition("C3", customer_name, new FuncTerm("funcEquals", new funcEquals()), "Joe Blow"));
WhatsMyName.AddConditionToRHS(new InvokeCondition("R1", customer_var, "Shout", customer_name));
WhatsMyName.AddConditionToRHS(new SetCondition("R2", customer_var, "Remarks", "Hello from Expergent."));
agenda.AddProduction(WhatsMyName);
Production WhatsMyName1 = new Production();
WhatsMyName1.Salience = 10;
WhatsMyName1.AddConditionToLHS(new PositiveCondition(customer_var, "$Customer.Name", customer_name));
WhatsMyName1.AddConditionToRHS(new InvokeCondition(customer_var, "Shout", "Squid"));
WhatsMyName1.AddConditionToRHS(new SetCondition(customer_var, "Remarks", "Squid Text"));
agenda.AddProduction(WhatsMyName1);
agenda.Run();
agenda.VisualizeNetworkToFile(@"C:\Temp\NeoTest2.log", false);
Assert.IsTrue(agenda.TotalFacts == 22, "Bad");
Assert.IsTrue(agenda.ActionsTaken.Count == 6, "Bad");
Assert.IsTrue(agenda.ActionsSkipped.Count == 0, "Bad");
Assert.IsTrue(agenda.ActivatedRuleCount == 2, "Bad");
Assert.IsTrue(customers.FindFirst("Name = {0}", "Joe Blow").Result != null && customers.FindFirst("Name = {0}", "Joe Blow").Result.Contains("Squid"), "Did not invoke method.");
Assert.IsTrue(customers.FindFirst("Name = {0}", "Joe Blow").Remarks != null && customers.FindFirst("Name = {0}", "Joe Blow").Remarks.Contains("Squid Text"), "Did not invoke method.");
}