public RuleWindow( Rule rule )
 {
     InitializeComponent();
     PEFunctionControl.SetValues(rule.F1);
     CPEFunctionControl.SetValues(rule.F2);
     DHFunctionControl.SetValues(rule.Output);
     FunctionNameTextBox.Text = rule.Label;
     TitleTextBlock.Text = "Edit Rule";
     CreateButton.Content = "Apply Changes";
 }
        //adds a new rule to the fuzzy logic controller
        public void AddRule(Rule rule)
        {
            if (rule.F1.Max != max || rule.F1.Min != min || rule.F1.Samples != samples)
                throw new InvalidRangeException("The membership functions must be defined on the same domain");

            if (rule.F2.Max != max || rule.F2.Min != min || rule.F2.Samples != samples)
                throw new InvalidRangeException("The membership functions must be defined on the same domain");

            rules.Add(rule);
        }
 private void CreateButton_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         Result = new Rule(FunctionNameTextBox.Text, PEFunctionControl.CreateMembershipFunction(41, -5, 5),
                                                     CPEFunctionControl.CreateMembershipFunction(41, -5, 5),
                                                     DHFunctionControl.CreateMembershipFunction(41, -5, 5));
         this.Close();
     }
     catch (FormatException exception)
     {
         MessageBox.Show("The values you have given are invalid. Plese recheck them");
         Console.Out.WriteLine(exception);
     }
 }
        public void DrawLine(Rule rule)
        {
            int to = getIndex(rule.Label);

            if (to >= Rules.Length)
                return;

            Rectangle toRect = Rules[to];
            double multX = ColumnWidth;
            double multY = RowHeight;

            Point point = new Point();
            point.X = Grid.GetColumn(toRect) *multX + Grid.GetColumnSpan(toRect) * multX / 2;
            point.Y = Grid.GetRow(toRect) *multY + Grid.GetRowSpan(toRect) *multY / 2;

            RulePolygon.Points.Add(point);
        }
 //gets the minimum y value from the two input rules
 private double getOutputValue(Rule rule, double value1, double value2)
 {
     return Math.Min(rule.F1.getValue(value1), rule.F2.getValue(value2));
 }
 private void EditRule(int index, Rule rule)
 {
     CheckBox checkbox = new CheckBox();
     checkbox.Content = rule.Label;
     checkbox.IsChecked = true;
     checkbox.Tag = rule;
     RulesListBox.SelectedIndex = -1;
     RulesListBox.Items[index] = checkbox;
     RulesListBox.SelectedIndex = index;
 }
 private void AddRule(Rule rule)
 {
     CheckBox checkbox = new CheckBox();
     checkbox.Content = rule.Label;
     checkbox.IsChecked = true;
     checkbox.Tag = rule;
     RulesListBox.Items.Add(checkbox);
 }