/// <summary> /// Creates new instance of the TreeSource for the specifed relation /// </summary> /// <param name="deffuzification">Relation wrapped in a deffuzification. In this case, the hierarchy will also contain information about applied deffuzification.</param> public TreeSource(Defuzzification deffuzification) { _relation = deffuzification.Relation; _deffuzification = deffuzification; _inputs = deffuzification.Inputs; _variableDimension = deffuzification.OutputDimension; }
public void T8Defuzzify() { LinguisticVariable = LinguisticVariable.fromJson(JsonLingVar); LinguisticVariable.RangeCalibration(1, 0.01); ExternalLVSetUp(); LinguisticVariable.ApplyRule(LingVars); LinguisticVariable.Implicate(1); Debug.Log( "[Defuzzification Test Result]\n" + "Method : " + Defuzzification.nameOf(dfuzz) + " | Result : " + dfuzz.defuzzify(LinguisticVariable.linguisticRules)); }
protected void buildRelationNow(bool initial) { if (!_ready) { return; } _waitingForBuild = false; _building = true; bool _expressionChanged = false; decimal inputProduct = ddlProduct.SelectedIndex + 1; decimal inputPrice = txtPrice.Value; #region Realtime expression evaluation by means of C# parser string strExpression = txtExpression.Text; prependFullName(ref strExpression, "cheap"); prependFullName(ref strExpression, "fruits"); prependFullName(ref strExpression, "buyIt"); object obj = Evaluator.Eval(strExpression); if (obj != null) { if (!(obj is FuzzyRelation)) { MessageBox.Show(String.Format("ERROR: Object of type FuzzyRelation expected as the result of the expression.\r\nThis object is type {0}.", obj.GetType().FullName), "Error evaluating expression", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { _relation = (FuzzyRelation)obj; if (_expression != txtExpression.Text) { _expressionChanged = true; } _expression = txtExpression.Text; } } #endregion #region Defuzzification DefuzzificationFactory.DefuzzificationMethod method = (DefuzzificationFactory.DefuzzificationMethod)ddlDefuzMethod.SelectedIndex; _defuzzification = DefuzzificationFactory.GetDefuzzification( _relation, new Dictionary <IDimension, decimal> { { product, inputProduct }, { price, inputPrice } }, method ); _defuzzMethod = method; #endregion #region Output value string unit = ((IContinuousDimension)_defuzzification.OutputDimension).Unit; lblOutput.Text = _defuzzification.CrispValue.ToString("F5") + (string.IsNullOrEmpty(unit) ? "" : " " + unit); #endregion Cursor.Current = Cursors.WaitCursor; #region storing TreeView selection //Store information about currenlty selected node. It will become handy //when selecting the same node after the refresh (if applicable) List <int> selectedNodePath = new List <int>(); if (treeViewRelation.SelectedNode != null) { TreeNode pointer = treeViewRelation.SelectedNode; while (pointer != null) { selectedNodePath.Add(pointer.Index); pointer = pointer.Parent; } } else if (initial) { selectedNodePath.Add(0); } #endregion TreeSource ts = new TreeSource(_defuzzification); ts.DrawImageOnNodeSelect = false; ts.BuildTree(treeViewRelation, pictureBoxGraph, lblGraphCaption); //Cursor.Current = Cursors.Default; #region restoring TreeView selection if ((!_expressionChanged || initial) && selectedNodePath.Count() > 0 && selectedNodePath[selectedNodePath.Count() - 1] < treeViewRelation.Nodes.Count) { //We will now try to restore the selection TreeNode pointer = treeViewRelation.Nodes[selectedNodePath[selectedNodePath.Count() - 1]]; for (int i = selectedNodePath.Count() - 2; i >= 0; i--) { if (selectedNodePath[i] >= pointer.Nodes.Count) { pointer = null; break; } pointer = pointer.Nodes[selectedNodePath[i]]; } if (pointer != null) { treeViewRelation.SelectedNode = pointer; ts.DrawDetailImage(pointer); } } Cursor.Current = Cursors.Default; ts.DrawImageOnNodeSelect = true; #endregion _building = false; }