public virtual ActionResult GenerateWeights(int id, WeightGenerationMethod method, GenerateWeightsRequestModel viewModel) { Project project = _projectService.Get(id); WeightGenerationResult result = project.WeightGenerationResults.SingleOrDefault(x => x.GenerationMethod == method); viewModel.ExistingResult = result; if (ModelState.IsValid) { WeightGenerationResult weightGenerationResult = result ?? new WeightGenerationResult() { GenerationMethod = viewModel.Method }; var alfa = Convert.ToDecimal(viewModel.Alfa, CultureInfo.InvariantCulture); weightGenerationResult.Alfa = alfa; weightGenerationResult.Items = weightGenerationResult.Items ?? new List<WeightGenerationResultItem>(); ClearExistingWeights(weightGenerationResult); switch (viewModel.Method) { case WeightGenerationMethod.Method1: case WeightGenerationMethod.Method2: case WeightGenerationMethod.Method3: var finalAssessmentMatrix = project.FinalAssessment.ToMatrix(); List<List<decimal>> weights = GenerateWeightWithA.GenerateWeight(alfa, finalAssessmentMatrix, viewModel.Method); for (int i = 0; i < weights.Count; i++) { for (int j = 0; j < weights[i].Count; j++) { WeightGenerationResultItem item = new WeightGenerationResultItem(); item.AlternativeId = project.Alternatives.ElementAt(i).AlternativeId; item.FactorId = project.Factors.ElementAt(j).FactorId; item.Weight = Convert.ToDecimal(weights[i][j]); weightGenerationResult.Items.Add(item); } } break; case WeightGenerationMethod.Orness: var orness = DMS.Domain.GenerateWeights.SearchSolutionOress.GenerateWeight(Convert.ToDouble(viewModel.Alfa, CultureInfo.InvariantCulture), project.Factors.Count); foreach (var alternative in project.Alternatives) { for (int i = 0; i < orness.Count; i++) { WeightGenerationResultItem item = new WeightGenerationResultItem(); item.Weight = Convert.ToDecimal(orness[i]); item.Factor = project.Factors.ElementAt(i); item.Alternative = alternative; weightGenerationResult.Items.Add(item); } } break; case WeightGenerationMethod.Quantifier: var quantifier = DMS.Domain.GenerateWeights.WeightGeneratorQuantifier.GenerateWeights(Convert.ToDouble(viewModel.Alfa, CultureInfo.InvariantCulture), project.Factors.Count); foreach (var alternative in project.Alternatives) { for (int i = 0; i < quantifier.Count; i++) { WeightGenerationResultItem item = new WeightGenerationResultItem(); item.Weight = Convert.ToDecimal(quantifier[i]); item.Factor = project.Factors.ElementAt(i); item.Alternative = alternative; weightGenerationResult.Items.Add(item); } } break; } project.WeightGenerationResults.Add(weightGenerationResult); _projectService.Update(project); viewModel.ExistingResult = weightGenerationResult; } return PartialView(viewModel); }
public virtual ActionResult GenerateWeights(int id, WeightGenerationMethod method) { Project project = _projectService.Get(id); WeightGenerationResult result = project.WeightGenerationResults.SingleOrDefault(x => x.GenerationMethod == method); var viewModel = new GenerateWeightsRequestModel(); viewModel.Id = id; viewModel.Method = method; viewModel.ExistingResult = result; return PartialView(viewModel); }