/// <summary> /// Several commutative operands of same type from different nested levels will be joined in a single list /// </summary> /// <param name="relation"></param> /// <param name="foundNestedSubrelations"></param> protected void findNestedOperands(NodeFuzzyRelation relation, List <FuzzyRelation> foundNestedSubrelations) { if (relation.Subrelation1 is NodeFuzzyRelation && ((NodeFuzzyRelation)relation.Subrelation1).Operator.GetType() == relation.Operator.GetType()) { findNestedOperands((NodeFuzzyRelation)relation.Subrelation1, foundNestedSubrelations); } else { foundNestedSubrelations.Add(relation.Subrelation1); } if (relation.Subrelation2 != null) { if (relation.Subrelation2 is NodeFuzzyRelation && ((NodeFuzzyRelation)relation.Subrelation2).Operator.GetType() == relation.Operator.GetType()) { findNestedOperands((NodeFuzzyRelation)relation.Subrelation2, foundNestedSubrelations); } else { foundNestedSubrelations.Add(relation.Subrelation2); } } }
/// <summary> /// Several commutative operands of same type from different nested levels will be joined in a single list /// </summary> /// <param name="relation"></param> /// <param name="foundNestedSubrelations"></param> protected void findNestedOperands(NodeFuzzyRelation relation, List<FuzzyRelation> foundNestedSubrelations) { if (relation.Subrelation1 is NodeFuzzyRelation && ((NodeFuzzyRelation)relation.Subrelation1).Operator.GetType() == relation.Operator.GetType()) { findNestedOperands((NodeFuzzyRelation)relation.Subrelation1, foundNestedSubrelations); } else { foundNestedSubrelations.Add(relation.Subrelation1); } if (relation.Subrelation2 != null) { if (relation.Subrelation2 is NodeFuzzyRelation && ((NodeFuzzyRelation)relation.Subrelation2).Operator.GetType() == relation.Operator.GetType()) { findNestedOperands((NodeFuzzyRelation)relation.Subrelation2, foundNestedSubrelations); } else { foundNestedSubrelations.Add(relation.Subrelation2); } } }
/// <summary> /// Method to be invoked recursively to build the whole tree /// </summary> /// <param name="nodeCollection"></param> /// <param name="pictureBox"></param> /// <param name="label"></param> protected void buildSubTree(FuzzyRelation subrelation, TreeNodeCollection nodeCollection, PictureBox pictureBox, Label label) { TreeNode tnThis; if (subrelation is FuzzySet) { FuzzySet fs = (FuzzySet)subrelation; tnThis = new TreeNode(); if (!String.IsNullOrEmpty(fs.Caption)) { tnThis.Text = fs.Caption; } else { tnThis.Text = "Fuzzy Set"; } tnThis.ImageKey = "fuzzySet"; tnThis.SelectedImageKey = "fuzzySet"; TreeNode tnDimType = new TreeNode("Type: " + (fs.Dimensions[0] is IContinuousDimension ? "Continuous" : "Discrete")); tnDimType.ImageKey = "dimensionType"; tnDimType.SelectedImageKey = "dimensionType"; tnThis.Nodes.Add(tnDimType); } else { NodeFuzzyRelation nfr = (NodeFuzzyRelation)subrelation; tnThis = new TreeNode("Multidimensional Relation"); tnThis.ImageKey = "nodeFuzzyRelation"; tnThis.SelectedImageKey = "nodeFuzzyRelation"; TreeNode tnSubrelations = new TreeNode(nfr.Operator.Caption); tnSubrelations.ImageKey = "subrelations"; tnSubrelations.SelectedImageKey = "subrelations"; tnSubrelations.ForeColor = OperatorFontColor; tnThis.Nodes.Add(tnSubrelations); //Find all operands. Several commutative operands of same type from different nested levels will be displayed together List <FuzzyRelation> nestedSubrelations = new List <FuzzyRelation>(); findNestedOperands(nfr, nestedSubrelations); foreach (FuzzyRelation nestedSubrelation in nestedSubrelations) { buildSubTree(nestedSubrelation, tnSubrelations.Nodes, pictureBox, label); } } #region Dimensions TreeNode tnDimensions = new TreeNode("Dimension" + ((subrelation.Dimensions.Count() > 1) ? "s" : "")); tnDimensions.ImageKey = "dimensions"; tnDimensions.SelectedImageKey = "dimensions"; tnThis.Nodes.Add(tnDimensions); foreach (IDimension dimension in subrelation.Dimensions) { bool blnKnown = _inputs.ContainsKey(dimension); bool blnContinuous = dimension is IContinuousDimension; Color fontColor; string strDimCaption = String.IsNullOrEmpty(dimension.Name) ? "Dimension" : dimension.Name; if (blnKnown) { if (blnContinuous) { strDimCaption += String.Format("={0:F5} {1}", _inputs[dimension], ((IContinuousDimension)dimension).Unit); } else { IDiscreteDimension discreteDim = (IDiscreteDimension)dimension; if (discreteDim.DefaultSet != null) { strDimCaption += "=" + discreteDim.DefaultSet.GetMember(_inputs[dimension]).Caption; } else { strDimCaption += String.Format("=#{0:F0}", _inputs[dimension]); } } fontColor = SpecifiedDimensionFontColor; } else { fontColor = UnspecifiedDimensionFontColor; } if (dimension == _variableDimension) { fontColor = VariableDimensionFontColor; } string imageKey = String.Format("dimension{0}{1}", blnContinuous ? "Continuous" : "Discrete", blnKnown ? "Known" : "Unknown"); TreeNode tnDimension = new TreeNode(strDimCaption); tnDimension.ImageKey = imageKey; tnDimension.SelectedImageKey = imageKey; tnDimension.ForeColor = fontColor; addToolTip(tnDimension, dimension.Description); tnDimensions.Nodes.Add(tnDimension); } #endregion #region Function if (allInputDimensionsAvailable(subrelation)) { IDimension realVariableDimension; if (subrelation.Dimensions.Count() == 1) { realVariableDimension = subrelation.Dimensions[0]; } else { realVariableDimension = _variableDimension; } Dictionary <IDimension, decimal> copyInputs = new Dictionary <IDimension, decimal>(_inputs); foreach (KeyValuePair <IDimension, decimal> item in _inputs) { if (!subrelation.Dimensions.Contains(item.Key)) { copyInputs.Remove(item.Key); } } if (copyInputs.ContainsKey(realVariableDimension)) { copyInputs.Remove(realVariableDimension); } if (subrelation.Dimensions.Count() > copyInputs.Count()) { IntervalSet intervals = subrelation.GetFunction(copyInputs); string strIntervals = intervals.ToString(); string[] arrLines = strIntervals.Split(new char[] { '\n' }); TreeNode tnFunction = new TreeNode("Function"); tnFunction.ImageKey = "function"; tnFunction.SelectedImageKey = "function"; foreach (string line in arrLines) { if (!String.IsNullOrWhiteSpace(line)) { TreeNode tnLine = new TreeNode(line); tnLine.ImageKey = "spacer"; tnLine.SelectedImageKey = "spacer"; tnFunction.Nodes.Add(tnLine); } } tnThis.Nodes.Add(tnFunction); } } #endregion tnThis.ForeColor = MainNodeFontColor; tnThis.Tag = subrelation; nodeCollection.Add(tnThis); }
/// <summary> /// Method to be invoked recursively to build the whole tree /// </summary> /// <param name="nodeCollection"></param> /// <param name="pictureBox"></param> /// <param name="label"></param> protected void buildSubTree(FuzzyRelation subrelation, TreeNodeCollection nodeCollection, PictureBox pictureBox, Label label) { TreeNode tnThis; if (subrelation is FuzzySet) { FuzzySet fs = (FuzzySet)subrelation; tnThis = new TreeNode(); if (!String.IsNullOrEmpty(fs.Caption)) { tnThis.Text = fs.Caption; } else { tnThis.Text = "Fuzzy Set"; tnThis.ForeColor = UnnamedNodeFontColor; } tnThis.ImageKey = "fuzzySet"; tnThis.SelectedImageKey = "fuzzySet"; TreeNode tnDimType = new TreeNode("Type: " + (fs.Dimensions[0] is IContinuousDimension ? "Continuous" : "Discrete")); tnDimType.ImageKey = "dimensionType"; tnDimType.SelectedImageKey = "dimensionType"; tnThis.Nodes.Add(tnDimType); } else { NodeFuzzyRelation nfr = (NodeFuzzyRelation)subrelation; tnThis = new TreeNode("Multidimensional Relation"); tnThis.ForeColor = UnnamedNodeFontColor; tnThis.ImageKey = "nodeFuzzyRelation"; tnThis.SelectedImageKey = "nodeFuzzyRelation"; TreeNode tnSubrelations = new TreeNode(nfr.Operator.Caption); tnSubrelations.ImageKey = "subrelations"; tnSubrelations.SelectedImageKey = "subrelations"; tnSubrelations.ForeColor = OperatorFontColor; tnThis.Nodes.Add(tnSubrelations); //Find all operands. Several commutative operands of same type from different nested levels will be displayed together List <FuzzyRelation> nestedSubrelations = new List <FuzzyRelation>(); findNestedOperands(nfr, nestedSubrelations); foreach (FuzzyRelation nestedSubrelation in nestedSubrelations) { buildSubTree(nestedSubrelation, tnSubrelations.Nodes, pictureBox, label); } } #region Dimensions; TreeNode tnDimensions = new TreeNode("Dimension" + ((subrelation.Dimensions.Count() > 1) ? "s" : "")); tnDimensions.ImageKey = "dimensions"; tnDimensions.SelectedImageKey = "dimensions"; tnThis.Nodes.Add(tnDimensions); foreach (IDimension dimension in subrelation.Dimensions) { bool blnKnown = _inputs.ContainsKey(dimension); bool blnContinuous = dimension is IContinuousDimension; Color fontColor; string strDimCaption = String.IsNullOrEmpty(dimension.Name) ? "Dimension" : dimension.Name; if (blnKnown) { if (blnContinuous) { strDimCaption += String.Format("={0:F5} {1}", _inputs[dimension], ((IContinuousDimension)dimension).Unit); } else { IDiscreteDimension discreteDim = (IDiscreteDimension)dimension; if (discreteDim.DefaultSet != null) { strDimCaption += "=" + discreteDim.DefaultSet.GetMember(_inputs[dimension]); } else { strDimCaption += String.Format("=#{0:F0}", _inputs[dimension]); } } fontColor = SpecifiedDimensionFontColor; } else { fontColor = UnspecifiedDimensionFontColor; } if (dimension == _variableDimension) { fontColor = VariableDimensionFontColor; } string imageKey = String.Format("dimension{0}{1}", blnContinuous ? "Continuous" : "Discrete", blnKnown ? "Known" : "Unknown"); TreeNode tnDimension = new TreeNode(strDimCaption); tnDimension.ImageKey = imageKey; tnDimension.SelectedImageKey = imageKey; tnDimension.ForeColor = fontColor; addToolTip(tnDimension, dimension.Description); tnDimensions.Nodes.Add(tnDimension); } #endregion #region Function #endregion nodeCollection.Add(tnThis); }