public void TestPOWA() { //Test weights List <decimal> weights = new List <decimal>() { 0.2M, 0.2M, 0.2M, 0.4M }; List <decimal> p = new List <decimal>() { 0.4M, 0.2M, 0.3M, 0.1M }; decimal beta = 0.5M; //Create Aggregation IAggregation aggregation = AggregationFactory.CreateParamAggregation(AggregationType.POWA, weights, p, beta); //Test Values List <decimal> values = new List <decimal>() { 20, 40, 50, 30 }; decimal result = aggregation.Calc(values); Assert.AreEqual(33M, Math.Round(result, 1)); }
public void TestIOWG() { //Test weights List <decimal> weights = new List <decimal>() { 0.5M, 0.5M, 0, 0 }; List <decimal> rating = new List <decimal>() { 7, 2, 10, 3 }; //Create Aggregation IAggregation aggregation = AggregationFactory.CreateParamAggregation(AggregationType.IOWG, weights, rating); //Test Values List <decimal> values = new List <decimal>() { 1, 1, 1, 1 }; decimal result = aggregation.Calc(values); Assert.AreEqual(4M, result); }
public void TestASPOWA() { //Test weights List <decimal> weights = new List <decimal>() { 0.5M, 0.3M, 0.2M }; List <decimal> p = new List <decimal>() { 0.7M, 1M, 0.5M }; decimal beta = 0.3M; //Create Aggregationk IAggregation aggregation = AggregationFactory.CreateParamAggregation(AggregationType.ASPOWA_MIN, weights, p, beta); //Test Values List <decimal> values = new List <decimal>() { 70M, 50M, 60M }; decimal result = aggregation.Calc(values); Assert.AreEqual(53.90M, result); }
public void TestIGOWA() { //Test weights List <decimal> weights = new List <decimal>() { 0.2M, 0.2M, 0.3M, 0.3M }; List <decimal> rating = new List <decimal>() { 7, 2, 10, 3 }; decimal alfa = 1; //Create Aggregation IAggregation aggregation = AggregationFactory.CreateParamAggregation(AggregationType.IGOWA, weights, rating, alfa); //Test Values List <decimal> values = new List <decimal>() { 25, 40, 20, 60 }; decimal result = aggregation.Calc(values); Assert.AreEqual(39, Math.Round(result, 1)); }
public void TestIOWA() { //Test weights List <decimal> weights = new List <decimal>() { 0.4M, 0.3M, 0.2M, 0.1M }; List <decimal> rating = new List <decimal>() { 0.5M, 0.5M, 0.2M, 0.7M }; //Create Aggregation IAggregation aggregation = AggregationFactory.CreateParamAggregation(AggregationType.IOWA, weights, rating); //Test Values List <decimal> values = new List <decimal>() { 0.8M, 0.2M, 0.9M, 0.9M }; decimal result = aggregation.Calc(values); Assert.AreEqual(0.7M, Math.Round(result, 1)); }
public void TestAverage() { //Create Aggregation IAggregation aggregation = AggregationFactory.CreateSimpleAggregation(AggregationType.AVERAGE); //Test Values List <decimal> values = new List <decimal>() { 1.0M, 0.6M, 0.5M, 0.3M }; decimal result = aggregation.Calc(values); Assert.AreEqual(0.6M, result); }
public void TestOWA() { //Test weights List <decimal> weights = new List <decimal>() { 0.2M, 0.3M, 0.1M, 0.4M }; //Create Aggregation IAggregation aggregation = AggregationFactory.CreateWeightAggregation(AggregationType.OWA, weights); //Test Values List <decimal> values = new List <decimal>() { 1.0M, 0.6M, 0.5M, 0.3M }; decimal result = aggregation.Calc(values); Assert.AreEqual(0.55M, result); }
public void TestOWG() { //Test weights List <decimal> weights = new List <decimal>() { 0.5M, 0.5M, 0, 0 }; //Create Aggregation IAggregation aggregation = AggregationFactory.CreateWeightAggregation(AggregationType.OWG, weights); //Test Values List <decimal> values = new List <decimal>() { 1, 1, 1, 1 }; decimal result = aggregation.Calc(values); Assert.AreEqual(4M, result); }
public void TestGOWA() { //Test weights List <decimal> weights = new List <decimal>() { 0.5M, 0.3M, 0.2M }; decimal param = 2; //Create Aggregation IAggregation aggregation = AggregationFactory.CreateParamAggregation(AggregationType.GOWA, weights, param); //Test Values List <decimal> values = new List <decimal>() { 0.6M, 0.45M, 0.5M }; decimal result = aggregation.Calc(values); Assert.AreEqual(0.5436M, Math.Round(result, 4)); }
public override decimal Calc(List <decimal> values) { List <int> indexes = new List <int>(); for (int i = 0; i < values.Count; i++) { indexes.Add(i); } AggrerationUtil au = new AggrerationUtil(); IEnumerable <IEnumerable <int> > permutationResult = au.Permutation <int>(indexes); decimal globalK = 0M; bool initGlobal = false; foreach (IEnumerable <int> e in permutationResult) { List <int> curentPermutation = e.ToList(); List <decimal> curentPermutationP = new List <decimal>(); foreach (int i in e) { curentPermutationP.Add(p[i]); } // First max Aggregation // Result is pSigma List <decimal> pSigma = new List <decimal>(); decimal lastMax = 0m; for (int i = 0; i < curentPermutationP.Count; i++) { decimal curentPValue = curentPermutationP[i]; if (i > 0) { decimal max = Math.Max(curentPValue, lastMax); curentPValue = max - lastMax; lastMax = max; } else { lastMax = curentPValue; } pSigma.Add(curentPValue); } List <decimal> permValues = new List <decimal>(); foreach (int i in e) { permValues.Add(values[i]); } //Calculate local K decimal localK = 0; for (int i = 0; i < pSigma.Count; i++) { localK += pSigma[i] * permValues[i]; } //Ckeck initial if (!initGlobal) { initGlobal = true; globalK = localK; } globalK = checkASPOWAAggregationType(this.type, globalK, localK); } IAggregation aggregation = AggregationFactory.CreateWeightAggregation(AggregationType.OWA, this.weights); decimal owaValue = aggregation.Calc(values); return(this.beta * owaValue + (1 - this.beta) * globalK); }
private IEnumerable <AggregationResult> GetAggregationResult(Project project, AggregationType aggregationType, decimal?lambda = null) { var aggregationResult = new AggregationResult(); aggregationResult.Items = new List <AggregationResultItem>(); aggregationResult.Project = project; IAggregation aggregation = null; switch (aggregationType) { case AggregationType.MIN: case AggregationType.MAX: case AggregationType.AVERAGE: aggregation = AggregationFactory.CreateSimpleAggregation(aggregationType); foreach (var alternative in project.Alternatives.OrderBy(x => x.AlternativeId)) { var row = project.FinalAssessment.Items.Where(x => x.AlternativeId == alternative.AlternativeId) .OrderBy(x => x.FactorId).ToList(); var points = row.Select(x => x.Points).ToList(); var calculatedAggregation = aggregation.Calc(points); aggregationResult.Items.Add(new AggregationResultItem() { Alternative = alternative, Aggregation = calculatedAggregation, }); } break; case AggregationType.OWA: case AggregationType.OWG: foreach (var weight in project.WeightGenerationResults) { aggregationResult = new AggregationResult(); aggregationResult.Items = new List <AggregationResultItem>(); aggregationResult.Project = project; aggregationResult.Weight = weight; foreach (var alternative in project.Alternatives.OrderBy(x => x.AlternativeId)) { var row = project.FinalAssessment.Items.Where(x => x.AlternativeId == alternative.AlternativeId) .OrderBy(x => x.FactorId).ToList(); var points = row.Select(x => x.Points).ToList(); List <decimal> weights = weight.GetWeights(alternative); aggregation = AggregationFactory.CreateWeightAggregation(aggregationType, weights.ToList()); var calculatedAggregation = aggregation.Calc(points); aggregationResult.Items.Add(new AggregationResultItem() { Alternative = alternative, Aggregation = calculatedAggregation }); } yield return(aggregationResult); } break; case AggregationType.IOWA: case AggregationType.IOWG: foreach (var weight in project.WeightGenerationResults) { aggregationResult = new AggregationResult(); aggregationResult.Items = new List <AggregationResultItem>(); aggregationResult.Project = project; aggregationResult.Weight = weight; foreach (var alternative in project.Alternatives.OrderBy(x => x.AlternativeId)) { var row = project.FinalAssessment.Items.Where(x => x.AlternativeId == alternative.AlternativeId) .OrderBy(x => x.FactorId).ToList(); var points = row.Select(x => x.Points).ToList(); List <decimal> weights = weight.GetWeights(alternative); List <decimal> ratings = weight.GetRatings(alternative); aggregation = AggregationFactory.CreateParamAggregation(aggregationType, weights.ToList(), ratings); var calculatedAggregation = aggregation.Calc(points); aggregationResult.Items.Add(new AggregationResultItem() { Alternative = alternative, Aggregation = calculatedAggregation }); } yield return(aggregationResult); } break; case AggregationType.IGOWA: foreach (var weight in project.WeightGenerationResults) { aggregationResult = new AggregationResult(); aggregationResult.Items = new List <AggregationResultItem>(); aggregationResult.Project = project; aggregationResult.Weight = weight; foreach (var alternative in project.Alternatives.OrderBy(x => x.AlternativeId)) { var row = project.FinalAssessment.Items.Where(x => x.AlternativeId == alternative.AlternativeId) .OrderBy(x => x.FactorId).ToList(); var points = row.Select(x => x.Points).ToList(); List <decimal> weights = weight.GetWeights(alternative); List <decimal> ratings = weight.GetRatings(alternative); aggregation = AggregationFactory.CreateParamAggregation(aggregationType, weights.ToList(), ratings, lambda.Value); var calculatedAggregation = aggregation.Calc(points); aggregationResult.Items.Add(new AggregationResultItem() { Alternative = alternative, Aggregation = calculatedAggregation }); } yield return(aggregationResult); } break; case AggregationType.GOWA: foreach (var weight in project.WeightGenerationResults) { aggregationResult = new AggregationResult(); aggregationResult.Items = new List <AggregationResultItem>(); aggregationResult.Project = project; aggregationResult.Weight = weight; aggregationResult.Lambda = lambda; foreach (var alternative in project.Alternatives.OrderBy(x => x.AlternativeId)) { var row = project.FinalAssessment.Items.Where(x => x.AlternativeId == alternative.AlternativeId) .OrderBy(x => x.FactorId).ToList(); var points = row.Select(x => x.Points).ToList(); List <decimal> weights = weight.GetWeights(alternative); aggregation = AggregationFactory.CreateParamAggregation(aggregationType, weights.ToList(), lambda.Value); var calculatedAggregation = aggregation.Calc(points); aggregationResult.Items.Add(new AggregationResultItem() { Alternative = alternative, Aggregation = calculatedAggregation }); } yield return(aggregationResult); } break; case AggregationType.POWA: foreach (var weight in project.WeightGenerationResults) { aggregationResult = new AggregationResult(); aggregationResult.Items = new List <AggregationResultItem>(); aggregationResult.Project = project; aggregationResult.Weight = weight; aggregationResult.Lambda = lambda; foreach (var alternative in project.Alternatives.OrderBy(x => x.AlternativeId)) { var row = project.FinalAssessment.Items.Where(x => x.AlternativeId == alternative.AlternativeId) .OrderBy(x => x.FactorId).ToList(); var points = row.Select(x => x.Points).ToList(); List <decimal> weights = weight.GetWeights(alternative); List <decimal> probabilities = weight.GetProbabilities(alternative); aggregation = AggregationFactory.CreateParamAggregation(aggregationType, weights.ToList(), probabilities, lambda); var calculatedAggregation = aggregation.Calc(points); aggregationResult.Items.Add(new AggregationResultItem() { Alternative = alternative, Aggregation = calculatedAggregation }); } yield return(aggregationResult); } break; case AggregationType.ASPOWA_MIN: case AggregationType.ASPOWA_MAX: case AggregationType.ASPOWA_MEAN: foreach (var weight in project.WeightGenerationResults) { aggregationResult = new AggregationResult(); aggregationResult.Items = new List <AggregationResultItem>(); aggregationResult.Project = project; aggregationResult.Weight = weight; aggregationResult.Lambda = lambda; foreach (var alternative in project.Alternatives.OrderBy(x => x.AlternativeId)) { var row = project.FinalAssessment.Items.Where(x => x.AlternativeId == alternative.AlternativeId) .OrderBy(x => x.FactorId).ToList(); var points = row.Select(x => x.Points).ToList(); List <decimal> weights = weight.GetWeights(alternative); List <decimal> possibilities = weight.GetPossibilities(alternative); aggregation = AggregationFactory.CreateParamAggregation(aggregationType, weights.ToList(), possibilities, lambda); var calculatedAggregation = aggregation.Calc(points); aggregationResult.Items.Add(new AggregationResultItem() { Alternative = alternative, Aggregation = calculatedAggregation }); } yield return(aggregationResult); } break; } yield return(aggregationResult); }