Пример #1
0
 private void HandleAlternativeAdded(Alternative alternative)
 {
     foreach (CriterionNode lowestCriterionNode in goalNode.GetLowestCriterionNodes())
     {
         lowestCriterionNode.AlternativeNodes.Add(new AlternativeNode(alternative));
     }
 }
Пример #2
0
        public void RefreshAlternativeNodes()
        {
            foreach (CriterionNode criterionNode in GoalNode.GetLowestCriterionNodes())
            {
                foreach (Alternative alternative in Alternatives)
                {
                    if (!criterionNode.AlternativeNodes.Contains(alternative))
                    {
                        criterionNode.AlternativeNodes.Add(new AlternativeNode(alternative));
                    }
                }

                AlternativeNodeCollection toBeRemoved = new AlternativeNodeCollection();
                foreach (AlternativeNode alternativeNode in criterionNode.AlternativeNodes)
                {
                    if (!this.Alternatives.Contains(alternativeNode.Alternative))
                    {
                        toBeRemoved.Add(alternativeNode);
                    }
                }

                foreach (AlternativeNode alternativeNode in toBeRemoved)
                {
                    criterionNode.AlternativeNodes.Remove(alternativeNode);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Returns AlternativeNode object by Alternative and CriterionNode objects
        /// </summary>
        /// <param name="alternative"></param>
        /// <param name="criterion"></param>
        /// <returns></returns>
        public AlternativeNode this[Alternative alternative, CriterionNode criterion]
        {
            get
            {
                if (!Alternatives.Contains(alternative))
                {
                    throw new KeyNotFoundException(String.Format("Alternative '{0}' not found in the Altenatives collection of the hierarchy", alternative.Name));
                }

                ICollection <CriterionNode> nodes = GoalNode.GetLowestCriterionNodes();
                if (!nodes.Contains(criterion))
                {
                    throw new KeyNotFoundException(String.Format("Criterion node '{0}' not found in the criterion nodes which are at lowest level of the hierarchy", criterion.Name));
                }

                RefreshAlternativeNodes();

                AlternativeNode result = null;
                foreach (CriterionNode node in nodes)
                {
                    foreach (AlternativeNode alternativeNode in node.AlternativeNodes)
                    {
                        if (Object.ReferenceEquals(node, criterion) &&
                            Object.ReferenceEquals(alternativeNode.Alternative, alternative))
                        {
                            result = alternativeNode;
                        }
                    }
                }

                return(result);
            }
        }