示例#1
0
 /// <summary>
 /// 初始化模型,插入目标层
 /// </summary>
 private void InitModel()
 {
     //创建第一层
     Factor factor = new Factor("Z");
     Level toplevel = new Level(null, new List<Factor>() { factor }, null, null);
     //设置初始化的模型
     ahpModel = new AhpModel(toplevel);
 }
示例#2
0
 //在层次结构模型中定位某个因素在某一层
 public Level LocateFactor(Factor toFind)
 {
     Level locatedLevel = null;
     foreach (var level in Levels)
     {
         foreach (var factor in level.Factors)
         {
             if (factor == toFind)
             {
                 locatedLevel = level;
             }
         }
     }
     return locatedLevel;
 }
示例#3
0
        /// <summary>
        /// 初始化决策模型
        /// </summary>
        private void InitModel()
        {
            //创建第一层
            Factor factor = new Factor("Z");
            Level toplevel = new Level(null, new List<Factor>() { factor }, null, null);
            //设置初始化的模型
            _ahpModel = new AhpModel(toplevel);

            //构造第二层
            //第二层因素
            IList<Factor> factors2 = new List<Factor>
                {
                    new Factor("A1"),
                    new Factor("A2"),
                    new Factor("A3"),
                    new Factor("A4"),
                };
            //第二层关系矩阵
            Matrix level2Relation = new Matrix(4, 1);
            level2Relation.InsertDataFromList(new List<double> { 1, 1, 1, 1 });
            //第二层判断矩阵,初始化为空
            JudgeMatrix level2JudugeMatrix1 = new JudgeMatrix(4);
            //加入到判断矩阵序列
            Dictionary<Factor, JudgeMatrix> level2Judges = new Dictionary<Factor, JudgeMatrix>();
            level2Judges.Add(toplevel.Factors[0], level2JudugeMatrix1);
            Level level2 = new Level(toplevel, factors2, level2Relation, level2Judges);
            //加入到模型中
            _ahpModel.PushLevel(level2);

            //构造第三层次
            IList<Factor> factors3 = new List<Factor>
                {
                    new Factor("B1"){Direction = FactorDirection.Negative},
                    new Factor("B2"),
                    new Factor("B3"),
                    new Factor("B4"),
                    new Factor("B5"),
                    new Factor("B6"),
                    new Factor("B7"),
                    new Factor("B8"){Direction = FactorDirection.Negative},
                    new Factor("B9"),
                    new Factor("B10"),
                    new Factor("B11"),
                    new Factor("B12"),
                    new Factor("B13"),
                    new Factor("B14"),
                };
            //第三层关系矩阵
            Matrix level3Relation = new Matrix(14, 4);
            level3Relation.InsertDataFromList(new List<double>
                {
                    1,
                    0,
                    0,
                    0,
                    1,
                    0,
                    0,
                    0,
                    1,
                    0,
                    0,
                    0,
                    0,
                    1,
                    0,
                    0,
                    0,
                    1,
                    0,
                    0,
                    0,
                    1,
                    0,
                    0,
                    0,
                    1,
                    0,
                    0,
                    0,
                    0,
                    1,
                    0,
                    0,
                    0,
                    1,
                    0,
                    0,
                    0,
                    1,
                    0,
                    0,
                    0,
                    0,
                    1,
                    0,
                    0,
                    0,
                    1,
                    0,
                    0,
                    0,
                    1,
                    0,
                    0,
                    0,
                    1
                });
            //第三层判断矩阵
            JudgeMatrix level3JudugeMatrix1 = new JudgeMatrix(3);
            JudgeMatrix level3JudugeMatrix2 = new JudgeMatrix(4);
            JudgeMatrix level3JudugeMatrix3 = new JudgeMatrix(3);
            JudgeMatrix level3JudugeMatrix4 = new JudgeMatrix(4);
            //加入到判断矩阵序列
            Dictionary<Factor, JudgeMatrix> level3Judges = new Dictionary<Factor, JudgeMatrix>();
            level3Judges.Add(level2.Factors[0], level3JudugeMatrix1);
            level3Judges.Add(level2.Factors[1], level3JudugeMatrix2);
            level3Judges.Add(level2.Factors[2], level3JudugeMatrix3);
            level3Judges.Add(level2.Factors[3], level3JudugeMatrix4);
            Level level3 = new Level(level2, factors3, level3Relation, level3Judges);
            //加入到模型中
            _ahpModel.PushLevel(level3);
        }
示例#4
0
 //根据被影响因素和当前的模式,返回判断矩阵
 private JudgeMatrix GetJudgeMatrix(Factor factor)
 {
     if (isApproved)
         return _judgeMatrixPairs.Single(x => x.AffectedFactor == factor).ApprovedGen;
     return _judgeMatrixPairs.Single(x => x.AffectedFactor == factor).NormalGen;
 }
示例#5
0
 public FactorChangedEventArgs(string propertyName, ChangeType factorChangeType, Factor changedFactor)
 {
     this._propertyName = propertyName;
     _factorChangeType = factorChangeType;
     _changedFactor = changedFactor;
 }
示例#6
0
 public LevelJudgeMatrixInvaliException(string message, Exception innerException, Factor affectedFactor)
     : base(message, innerException)
 {
     _affectedFactor = affectedFactor;
 }
示例#7
0
 /// <summary>
 /// 设置本层次相对于上一层次中某个因素的的判断矩阵
 /// </summary>
 /// <param name="parentFactor"></param>
 /// <param name="judgeMatrix"></param>
 private void SetJudgeMatrix(Factor parentFactor, JudgeMatrix judgeMatrix)
 {
     //检查parentFactor是否为上一层次总的因素
     if (!Parent.Factors.Contains(parentFactor))
     {
         throw new CustomeExcetpion("上一层不包含指定的因素");
     }
     //检查传入的判断矩阵是否符合要求
     judgeMatrix.CheckJudgeMatrix();
     //设置
     JudgeMatrices.Add(parentFactor, judgeMatrix);
 }
示例#8
0
        /// <summary>
        /// 删除指定的Factor
        /// </summary>
        /// <param name="factor">要删除的因素</param>
        /// <returns>是否成功删除</returns>
        private bool RemoveFactor(Factor factor)
        {
            var index = Factors.IndexOf(factor);
            if (index != -1)
                return false;

            //先移除因素
            Factors.Remove(factor);
            //修改关系矩阵

            //刷新判断矩阵序列
            UpdateJudgeMatrices();
            return true;
        }
示例#9
0
        /// <summary>
        /// 为本层次添加因素
        /// </summary>
        /// <param name="factor">加入到本层次的因素</param>
        private void AddFactor(Factor factor)
        {
            _factors.Add(factor);

            //添加一个因素之后,修改本层次的关系矩阵
            //如果关系矩阵为空,说明还没有初始化过
            if (_relationMatrix == null)
                _relationMatrix = new Matrix(1, Parent.FactorCount);
            else
            {
                //如果不为空,但是没有元素,说明全部都被移除了
                //因为矩阵是不可变的,所以不能通过矩阵的方法来进行插入行,只能通过重新构造一个关系矩阵,并将原来的数据复制进去
                var relationData = _relationMatrix.ExportToList();
                Matrix newRelationMatrix = new Matrix(_relationMatrix.X + 1, _relationMatrix.Y);
                newRelationMatrix.InsertDataFromList(relationData);
            }
            //todo:因为加入的新的元素并没有跟上下层建立关系,所以不需要更新相关属性
            //同时重新生成判断矩阵序列
            //UpdateJudgeMatrices();
            //通知下一层更改
            //OnFactorChanged("Factors", FactorChangedEventArgs.ChangeType.Add, factor);
        }
示例#10
0
 /// <summary>
 /// 获取指定上一层元素控制的因素
 /// </summary>
 /// <param name="parentFactor">指定的的上一层因素</param>
 /// <returns>本层次中被控制的因素</returns>
 public IList<Factor> GetAffectFactor(Factor parentFactor)
 {
     IList<Factor> affectFactors=new List<Factor>();
     //表示上一层中的控制因素的索引值
     int parendIndex = Parent.Factors.IndexOf(parentFactor);
     for (int i = 0; i < _relationMatrix.X; i++)
     {
         if (_relationMatrix[i,parendIndex]!=0)
         {
             affectFactors.Add(Factors[i]);
         }
     }
     return affectFactors;
 }