private void addOrEditButton_Click(object sender, EventArgs e) { try { var newReaction = new ActionRuleDTO { Action = textBoxAction.Value, Target = textBoxTarget.Value, Priority = textBoxPriority.Value, Layer = textBoxLayer.Value, }; if (_reactionToEdit != null) { _edmAsset.UpdateActionRule(_reactionToEdit, newReaction); } else { _edmAsset.AddActionRule(newReaction); } } catch (Exception ex) { MessageBox.Show(ex.Message, Resources.ErrorDialogTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } this.Close(); }
/// <summary> /// Adds a new reactive action to the asset. /// </summary> /// <param name="newRuleDto">The DTO containing the parameters needed to generate an action rule.</param> /// <returns>The unique identifier of the newly created action rule.</returns> public Guid AddActionRule(ActionRuleDTO newRuleDto) { var newActionRule = new ActionRule(newRuleDto); m_actionRules.Add(newActionRule); return(newActionRule.Id); }
public AddOrEditReactionForm(EmotionalDecisionMakingAsset edmAsset, ActionRuleDTO reactionToEdit = null) { InitializeComponent(); _edmAsset = edmAsset; _reactionToEdit = reactionToEdit; textBoxAction.Value = (WellFormedNames.Name) "A"; textBoxPriority.Value = (WellFormedNames.Name) "1"; //validators textBoxAction.AllowNil = false; textBoxAction.AllowUniversal = false; textBoxAction.AllowUniversalLiteral = false; textBoxTarget.AllowUniversal = false; textBoxTarget.AllowComposedName = false; textBoxPriority.OnlyIntOrVariable = true; if (reactionToEdit != null) { this.Text = Resources.EditReactionFormTitle; this.addOrEditButton.Text = Resources.UpdateButtonLabel; textBoxAction.Value = reactionToEdit.Action; textBoxTarget.Value = reactionToEdit.Target; textBoxPriority.Value = reactionToEdit.Priority; textBoxLayer.Value = reactionToEdit.Layer; } }
public void Test_EDM_UpdateActionRule() { var asset = BuildTestAsset(); Guid id = new Guid(); foreach (var rule in asset.GetAllActionRules()) { id = rule.Id; break; } var toEdit = asset.GetActionRule(id); ActionRuleDTO newAction = new ActionRuleDTO() { Action = (Name)"EnterRoom", Id = id, Target = (Name)"[x]", Conditions = new ConditionSetDTO() }; asset.UpdateActionRule(toEdit, newAction); id = new Guid(); foreach (var rule in asset.GetAllActionRules()) { id = rule.Id; break; } Assert.AreEqual(asset.GetActionRule(id).Action, (Name)"EnterRoom"); }
/// <summary> /// Updates an action rule definition. /// </summary> /// <param name="ruleToEdit">The DTO of the action rule we want to update</param> /// <param name="newRule">The DTO containing the new action rule data</param> public void UpdateActionRule(ActionRuleDTO ruleToEdit, ActionRuleDTO newRule) { newRule.Conditions = ruleToEdit.Conditions; var newAt = new ActionRule(newRule); var oldAt = m_actionRules.Where(a => a.Id == ruleToEdit.Id).FirstOrDefault(); var i = m_actionRules.IndexOf(oldAt); m_actionRules[i] = new ActionRule(newRule); }
//This is a small console program to exemplify the main functionality of the Emotional Decision Making Asset static void Main(string[] args) { //First we construct a new instance of the EmotionalDecisionMakingAsset class var edm = new EmotionalDecisionMakingAsset(); //Then, we have to register an existing knowledge base to the asset so it can check for //beliefs are true var kb = new KB((Name)"John"); kb.Tell((Name)"LikesToFight(SELF)", (Name)"True"); edm.RegisterKnowledgeBase(kb); //create an action rule var actionRule = new ActionRuleDTO { Action = Name.BuildName("Kick"), Priority = Name.BuildName("4"), Target = (Name)"Player" }; //add the reaction rule var id = edm.AddActionRule(actionRule); edm.AddRuleCondition(id, "LikesToFight(SELF) = True"); var actions = edm.Decide(Name.UNIVERSAL_SYMBOL); Console.WriteLine("Decisions: "); foreach (var a in actions) { Console.WriteLine(a.Name.ToString() + " p: " + a.Utility); } //this is how you can load the asset from a file Console.WriteLine("Loading From File: "); edm = EmotionalDecisionMakingAsset.LoadFromFile("../../../Examples/EDM-Tutorial/EDMTest.edm"); edm.RegisterKnowledgeBase(kb); actions = edm.Decide(Name.UNIVERSAL_SYMBOL); foreach (var a in actions) { Console.WriteLine(a.Name.ToString() + " p: " + a.Utility); } Console.WriteLine("Decisions: "); foreach (var a in actions) { Console.WriteLine(a.Name.ToString() + " p: " + a.Utility); } Console.ReadKey(); }
//This is a small console program to exemplify the main functionality of the Emotional Decision Making Asset static void Main(string[] args) { //First we construct a new instance of the EmotionalDecisionMakingAsset class var storage = new AssetStorage(); var edm = EmotionalDecisionMakingAsset.CreateInstance(storage); //Then, we have to register an existing knowledge base to the asset so it can check for //beliefs are true var kb = new KB((Name)"John"); kb.Tell((Name)"LikesToFight(SELF)", (Name)"True"); edm.RegisterKnowledgeBase(kb); //create an action rule var actionRule = new ActionRuleDTO { Action = Name.BuildName("Kick"), Priority = Name.BuildName("4"), Target = (Name)"Player" }; //add the reaction rule var id = edm.AddActionRule(actionRule); var rule = edm.GetActionRule(id); edm.AddRuleCondition(id, "LikesToFight(SELF) = True"); var actions = edm.Decide(Name.UNIVERSAL_SYMBOL); var ea = EmotionalAppraisalAsset.CreateInstance(storage); edm.Save(); using (var writer = File.CreateText("D:\\test2.json")) { writer.Write(storage.ToJson()); } string aux2 = File.ReadAllText("D:\\Test2.json"); var storage2 = AssetStorage.FromJson(aux2); using (var writer = File.CreateText("D:\\test3.json")) { writer.Write(storage2.ToJson()); } Console.WriteLine("Decisions: "); foreach (var a in actions) { Console.WriteLine(a.Name.ToString() + " p: " + a.Utility); } //this is how you can load the asset from a file Console.WriteLine("Loading From File: "); edm.RegisterKnowledgeBase(kb); actions = edm.Decide(Name.UNIVERSAL_SYMBOL); foreach (var a in actions) { Console.WriteLine(a.Name.ToString() + " p: " + a.Utility); } Console.WriteLine("Decisions: "); foreach (var a in actions) { Console.WriteLine(a.Name.ToString() + " p: " + a.Utility); } Console.ReadKey(); }
public ActionRule(ActionRuleDTO dto) { AssertAndInitialize(dto.Action, dto.Target, dto.Priority, dto.Layer, new ConditionSet(dto.Conditions)); }
private void UpdateConditions(ActionRuleDTO reaction) { conditionSetView.SetData(reaction?.Conditions); }