Example #1
0
 public void CopyFrom(Consideration other)
 {
     ReadableName = other.ReadableName;
     Input        = other.Input;
     Curve.CopyFrom(other.Curve);
     ParameterValues = other.ParameterValues;
 }
        internal void Attach(Project project, Consideration editConsideration)
        {
            if (EditingConsideration != null)
            {
                EditingConsideration.DialogRebuildNeeded -= Rebuild;
            }

            EditingConsideration = editConsideration;
            EditingProject       = project;

            EditingConsideration.DialogRebuildNeeded += Rebuild;

            NameEditWidget.Attach("Consideration", EditingConsideration, project);

            InputAxisDropdown.Items.Clear();
            foreach (InputAxis axis in project.Inputs)
            {
                InputAxisDropdown.Items.Add(axis);
            }

            InputAxisDropdown.SelectedItem = EditingConsideration.Input;
            ResponseCurveEditor.AttachCurve(EditingConsideration.Curve, EditingProject);

            WrapInputCheckBox.Checked = EditingConsideration.WrapInput;
        }
Example #3
0
        public double GetInputValue(Consideration consideration, Scenario.Context context)
        {
            if (context == null)
            {
                return(GetInputValue(consideration));
            }

            throw new NotImplementedException();
        }
Example #4
0
        public void Delete(Consideration consideration)
        {
            foreach (var behavior in Behaviors)
            {
                behavior.Considerations.Remove(consideration);
            }

            MarkDirty();
            ItemDelete(this, new DeletionEventArgs {
                DeletedObject = consideration
            });
        }
Example #5
0
        public CurveWizardForm(Project project, Consideration consideration)
        {
            InitializeComponent();
            EditConsideration = consideration;
            EditProject       = project;

            foreach (InputAxis axis in EditProject.Inputs)
            {
                InputComboBox.Items.Add(axis);
            }

            InputComboBox.SelectedItem = EditConsideration.Input;

            ConsiderationNameEditBox.Text = EditConsideration.ReadableName;

            ResponseCurveEditor.AttachCurve(EditConsideration.Curve);
        }
Example #6
0
        private void AddConsiderationButton_Click(object sender, EventArgs e)
        {
            if (BehaviorsListView.SelectedItems.Count <= 0)
            {
                return;
            }

            var behavior      = BehaviorsListView.SelectedItems[0].Tag as Behavior;
            var consideration = new Consideration("New consideration");

            if ((new CurveWizardForm(EditingProject, consideration)).ShowDialog() == DialogResult.OK)
            {
                behavior.Considerations.Add(consideration);
            }

            RefreshConsiderationControls();
        }
        private void CurveWizardButton_Click(object sender, EventArgs e)
        {
            var prev = new Consideration(EditingConsideration.GetName());

            prev.CopyFrom(EditingConsideration);

            var result = (new CurveWizardForm(EditingProject, EditingConsideration)).ShowDialog();

            if (result == DialogResult.OK)
            {
                EditingProject.MarkDirty();
                Rebuild();
            }
            else
            {
                EditingConsideration.CopyFrom(prev);
            }
        }
Example #8
0
        internal void Attach(Project project, Consideration editConsideration)
        {
            EditConsideration = editConsideration;
            EditProject       = project;

            EditConsideration.DialogRebuildNeeded += Rebuild;

            NameEditWidget.Attach("Consideration", EditConsideration);

            InputAxisDropdown.Items.Clear();
            foreach (InputAxis axis in project.Inputs)
            {
                InputAxisDropdown.Items.Add(axis);
            }

            InputAxisDropdown.SelectedItem = EditConsideration.Input;
            ResponseCurveEditor.AttachCurve(EditConsideration.Curve);
        }
Example #9
0
        public double GetInputValue(Consideration consideration)
        {
            foreach (EditWidgetConsiderationInput input in InputFlowPanel.Controls)
            {
                if (input.Tag == consideration.Input)
                {
                    if (consideration.Input.KBRec.Params == KnowledgeBase.Record.Parameterization.Enumeration)
                    {
                        var p          = consideration.Input.Parameters[0] as InputParameterEnumeration;
                        var v          = consideration.ParameterValues[0] as InputParameterValueEnumeration;
                        var comparison = string.Compare(v.Key, input.GetStringValue(), StringComparison.CurrentCultureIgnoreCase);

                        if (p.ScoreOnMatch)
                        {
                            if (comparison == 0)
                            {
                                return(1.0);
                            }

                            return(0.0);
                        }
                        else
                        {
                            if (comparison != 0)
                            {
                                return(1.0);
                            }

                            return(0.0);
                        }
                    }

                    return(input.GetRawValue());
                }
            }

            return(0.0);
        }
        internal EditWidgetConsiderationScore(Consideration consideration, IInputBroker broker)
        {
            InitializeComponent();
            EditConsideration = consideration;
            InputBroker       = broker;

            ConsiderationNameLabel.Text = EditConsideration.ReadableName + " (0.0) x";

            ResponseCurvePictureBox.Paint += (e, args) =>
            {
                Point previousPoint = ConvertXYToPoint(0.0, EditConsideration.Curve.ComputeValue(0.0));

                for (double x = 0.0; x <= 1.0; x += 0.001)
                {
                    double y = EditConsideration.Curve.ComputeValue(x);
                    Point  p = ConvertXYToPoint(x, y);

                    args.Graphics.DrawLine(Pens.Blue, previousPoint, p);
                    previousPoint = p;
                }

                double inputX = InputBroker.GetInputValue(EditConsideration.Input);
                inputX = EditConsideration.NormalizeInput(inputX);
                double inputY = EditConsideration.Curve.ComputeValue(inputX);

                string name = EditConsideration.ReadableName;
                ConsiderationNameLabel.Text = $"{name} ({inputX:f3}) x";
                ScoreLabel.Text             = $"= {inputY:f3}";

                Point offsetPoint = ConvertXYToPoint(inputX, inputY);
                offsetPoint.X -= 4;
                offsetPoint.Y -= 4;

                args.Graphics.FillEllipse(Brushes.Blue, new Rectangle(offsetPoint, new Size(8, 8)));
            };
        }
Example #11
0
        public double GetInputValue(Consideration consideration, Context context)
        {
            double raw = 0.0;

            if (consideration == null || consideration.Input == null)
            {
                return(raw);
            }

            switch (consideration.Input.Origin)
            {
            case InputAxis.OriginType.ComputedValue:
                switch (consideration.Input.KBRec.Prefab)
                {
                case KnowledgeBase.Record.Prefabs.Distance:
                    raw = Distance(context.ThinkingAgent.GetPosition(), context.Target.GetPosition());
                    break;

                case KnowledgeBase.Record.Prefabs.SimulationTime:
                    raw = SimulationTime;
                    break;

                default:
                    return(raw);
                }
                break;

            case InputAxis.OriginType.PropertyOfSelf:
                if (consideration.Input.KBRec.Params == KnowledgeBase.Record.Parameterization.Enumeration)
                {
                    int comparison = string.Compare((consideration.ParameterValues[0] as InputParameterValueEnumeration).Key, (string)context.ThinkingAgent.GetProperty(consideration.Input.KBRec));

                    if ((consideration.Input.Parameters[0] as InputParameterEnumeration).ScoreOnMatch)
                    {
                        if (comparison == 0)
                        {
                            return(1.0);
                        }

                        return(0.0);
                    }
                    else
                    {
                        if (comparison != 0)
                        {
                            return(1.0);
                        }

                        return(0.0);
                    }
                }
                else
                {
                    raw = (double)context.ThinkingAgent.GetProperty(consideration.Input.KBRec);
                }

                break;

            case InputAxis.OriginType.PropertyOfTarget:
                if (consideration.Input.KBRec.Params == KnowledgeBase.Record.Parameterization.Enumeration)
                {
                    int comparison = string.Compare((consideration.ParameterValues[0] as InputParameterValueEnumeration).Key, (string)context.Target.GetProperty(consideration.Input.KBRec));

                    if ((consideration.Input.Parameters[0] as InputParameterEnumeration).ScoreOnMatch)
                    {
                        if (comparison == 0)
                        {
                            return(1.0);
                        }

                        return(0.0);
                    }
                    else
                    {
                        if (comparison != 0)
                        {
                            return(1.0);
                        }

                        return(0.0);
                    }
                }
                else
                {
                    raw = (double)context.Target.GetProperty(consideration.Input.KBRec);
                }
                break;
            }

            return(raw);
        }
Example #12
0
 public double GetInputValue(Consideration consideration)
 {
     return(0.0);
 }