예제 #1
0
 public Level(LevelDataModel dataModel)
 {
     if (!dataModel.Check())
     {
         throw new CustomeExcetpion("数据不符合要求!");
     }
     _parent = dataModel.Parent;
     _factors = dataModel.Factors;
     _relationMatrix = dataModel.RelationMatrix;
     _judgeMatrices = dataModel.JudgeMatrices;
 }
예제 #2
0
        //为传入的AhpModel加入一个层次
        private static Level InsertLevel(AhpModel model)
        {
            //创建一个Level所必须的数据
            LevelDataModel dataModel = new LevelDataModel();

            //循环输入因素
            while (true)
            {
                foreach (var factor in GetFactors())
                {
                    dataModel.Factors.Add(factor);
                }

                var ifAddFactor = DataHelper.ReadBool("是否继续添加因素");
                if (!ifAddFactor)
                    break;
            }
            //读入并设置指标的方向
            while (true)
            {
                //首先读入一定数量的数据
                var tags = DataHelper.ReadValus<string>("请输入指标各个指标的方向,+ 代表正向,- 代表逆向", dataModel.Factors.Count);
                //表示是否获得真确的
                bool readSuccess = true;

                //依次设置Factor的正向还是逆向
                for (int i = 0; i < tags.Count; i++)
                {
                    //如果是正向,就继续,因为默认是正向
                    if (tags[i] == "+")
                        continue;
                    //如果是逆向,就设置
                    if (tags[i] == "-")
                    {
                        dataModel.Factors[i].Direction = FactorDirection.Negative;
                    }
                    //如果到这一步,说明有 +/- 以外的字符,则表示读入的数据错误,报错,并跳出循环,再重新读
                    else
                    {
                        readSuccess = false;
                        break;
                    }
                }
                if (readSuccess)
                    break;

                Console.WriteLine("输入的数据中包含无法识别的字符,请重新输入");
            }

            //输入关系矩阵
            //设置当前model中的最后一个层次为新插入层次的Parent
            dataModel.Parent = model.GetLastLevel();
            Matrix relationMatrix = new Matrix(dataModel.Factors.Count, dataModel.Parent.Factors.Count);
            Console.WriteLine("请输入关系矩阵");
            relationMatrix.InsertMatrix(DataHelper.ConsoleArrayInput);
            //relationMatrix.InsertMatrix(DataHelper.ConsoloInput);
            dataModel.RelationMatrix = relationMatrix;

            //设置判断矩阵
            Dictionary<Factor, JudgeMatrix> judgeMatrices = new Dictionary<Factor, JudgeMatrix>();
            //此处可以选择使用那种方式输入判断矩阵
            var judges = GetJudgeMatrices(relationMatrix, dataModel.Parent.Factors, dataModel.Factors);
            //var judges = GetJudgeMatrices(relationMatrix);
            for (int i = 0; i < relationMatrix.Y; i++)
            {
                judgeMatrices.Add(model.GetLastLevel().Factors[i], judges[i]);
            }
            dataModel.JudgeMatrices = judgeMatrices;

            //创建一个新的层次,并加入层次结构模型中
            Level newLevel = new Level(dataModel);
            model.PushLevel(newLevel);

            return model.GetLastLevel();
        }