public void ResultTest() { var wpe = Matrix <double> .Build.DenseOfArray(new double[, ] { { 1d, 3d, 1d / 3d }, { 1d / 3d, 1d, 1d / 5d }, { 3d, 5d, 1d }, }); var weas = new List <Matrix <double> > { Matrix <double> .Build.DenseOfArray(new double[, ] { { 1d, 5d, 1d / 3d }, { 1d / 5d, 1d, 1d / 7d }, { 3d, 7d, 1d }, }), Matrix <double> .Build.DenseOfArray(new double[, ] { { 1d, 1d / 3d, 1d / 5d }, { 3d, 1d, 1d / 3d }, { 5d, 3d, 1d }, }), Matrix <double> .Build.DenseOfArray(new double[, ] { { 1d, 1d / 5d, 1d / 3d }, { 5d, 1d, 3d }, { 3d, 1d / 3d, 1d }, }), }; var ahp = new AHP <double>(wpe, weas); var result = ahp.Result(); Assert.AreEqual(1, 1); }
public Form1() { InitializeComponent(); AHP myAHP = AHP.Instance; List <string> alternatives = new List <string>(); alternatives.Add("mBank"); alternatives.Add("Bank Milenium"); alternatives.Add("Bank BPH"); List <string> criteria = new List <string>(); criteria.Add("Sieć placówek"); criteria.Add("Oprocentowanie kredytu"); criteria.Add("Opłaty"); criteria.Add("Sieć bankomatów"); criteria.Add("Okres nieoprocentowanego kredytu"); myAHP.PrepareDataStructure(criteria, alternatives); double[][] CriteriaMatrixOfPairwiseComparison = new double[][] { new double[] { 1, 1.0 / 7.0, 1.0 / 3.0, 3, 1.0 / 5.0 }, new double[] { 7, 1, 5, 9, 3 }, new double[] { 3, 1.0 / 5.0, 1, 5, 1.0 / 3.0 }, new double[] { 1.0 / 3.0, 1.0 / 9.0, 1.0 / 5.0, 1, 1.0 / 7.0 }, new double[] { 5, 1.0 / 3.0, 3, 7, 1 } }; double[][] k1 = new double[][] { new double[] { 1.0, 1.0 / 3.0, 1.0 / 5.0 }, new double[] { 1.0, 1.0 / 3.0, 1.0 / 5.0 }, new double[] { 5.0, 3.0, 1.0 } }; double[][] k2 = new double[][] { new double[] { 1.0, 1.0 / 3.0, 3.0 }, new double[] { 3.0, 1.0, 5.0 }, new double[] { 1.0 / 3.0, 1.0 / 5.0, 1.0 } }; double[][] k3 = new double[][] { new double[] { 1.0, 1.0 / 3.0, 3.0 }, new double[] { 3.0, 1.0, 7.0 }, new double[] { 1.0 / 3.0, 1.0 / 7.0, 1.0 } }; double[][] k4 = new double[][] { new double[] { 1.0, 1.0 / 7.0, 1.0 / 3.0 }, new double[] { 7.0, 1.0, 5.0 }, new double[] { 3.0, 1.0 / 5.0, 1.0 } }; double[][] k5 = new double[][] { new double[] { 1.0, 3.0, 1.0 / 5.0 }, new double[] { 1.0 / 3.0, 1.0, 1.0 / 7.0 }, new double[] { 5.0, 7.0, 1.0 } }; try { ValidateValues.Check(CriteriaMatrixOfPairwiseComparison); ValidateValues.Check(k1); ValidateValues.Check(k2); ValidateValues.Check(k3); ValidateValues.Check(k4); ValidateValues.Check(k5); } catch (Exception e) { MessageBox.Show(e.Message); Environment.Exit(-1); } finally { myAHP.SetCriteriaPairwiseValues(CriteriaMatrixOfPairwiseComparison); myAHP.Criteria[0].SetAlternativesPairwiseValues(k1); myAHP.Criteria[1].SetAlternativesPairwiseValues(k2); myAHP.Criteria[2].SetAlternativesPairwiseValues(k3); myAHP.Criteria[3].SetAlternativesPairwiseValues(k4); myAHP.Criteria[4].SetAlternativesPairwiseValues(k5); myAHP.ComputeEvaluationOfAlternatives(); textBox1.Text = myAHP.GetNameOfBestAlternative(); textBox2.Text = myAHP.GetEvaluationOfBestAlternative().ToString(); } }
public ActionResult SetEvaluationListControl(FormCollection collection) { try { var list = new List <FormEvaluation>(); if (string.IsNullOrEmpty(collection["ControlId"])) { ShowMessage("خطایی در ذخیره اطلاعات رخ داده است", "خطا", messageIcon: MessageIcon.Error); return(Content("false")); } var dictionarymaster = new Dictionary <string, double>(); var controlsid = collection["ControlId"].Split(','); foreach (var id in controlsid) { var formEvaluation = new FormEvaluation { ControlId = id, OpinionCount = string.IsNullOrEmpty(collection["OpinionCount-" + id]) ? (int?)null : collection["OpinionCount-" + id].ToInt(), MaxScale = string.IsNullOrEmpty(collection["MaxScale-" + id]) ? (int?)null : collection["MaxScale-" + id].ToInt(), MinScale = string.IsNullOrEmpty(collection["MinScale-" + id]) ? (int?)null : collection["MinScale-" + id].ToInt(), }; var enumerable = collection.AllKeys.Where(x => x.StartsWith("EV-" + id)); foreach (var controlId in enumerable) { var textBox = new TextBox { Id = controlId, Name = controlId, Caption = string.Format("نظر {0}", collection["Order-" + controlId]), Order = collection["Order-" + controlId].ToInt() }; formEvaluation.Controls.Add(textBox); } var dictionary = new Dictionary <string, double>(); foreach (var controlId in enumerable) { if (string.IsNullOrEmpty(controlId)) { continue; } dictionary.Add(controlId, collection[controlId].ToFloat()); formEvaluation.GetFormControl.Add(controlId, collection[controlId]); } dictionarymaster.Add(id, AHP.GetWeight(dictionary)); list.Add(formEvaluation); } var calculation = AHP.Calculation(dictionarymaster); var obj = new List <Object>(); foreach (var f in calculation) { var firstOrDefault = list.FirstOrDefault(x => x.ControlId == f.Key); if (firstOrDefault == null) { continue; } firstOrDefault.Weight = Math.Round(f.Value, 6); obj.Add(new { controlId = firstOrDefault.ControlId, value = firstOrDefault.Weight }); } if (FormGeneratorComponent.Instance.FormEvaluationFacade.ModifyEvaluation(list, collection["LanguageId"])) { ShowMessage("اطلاعات با موفقیت ثبت شد", "موفق", messageIcon: MessageIcon.Succeed); return(Json(obj, JsonRequestBehavior.AllowGet)); } ShowMessage("خطایی در ذخیره اطلاعات رخ داده است", "خطا", messageIcon: MessageIcon.Error); return(Json(obj, JsonRequestBehavior.AllowGet)); } catch (Exception exception) { ShowMessage("خطایی در ذخیره اطلاعات رخ داده است" + exception.Message, "خطا", messageIcon: MessageIcon.Error); return(Content("false")); } }