using System; using System.Collections.Generic; using System.Linq; using System.Text; using HeuristicLab.Services.Optimization.ControllerService.Model; namespace HeuristicLab.Services.Optimization.ControllerService.General { public class AlgorithmHelper { public static bool HasToBeUpdated(Algorithm algo) { if (algo.Parameters != null) foreach (var param in algo.Parameters.Items) { if (RequiresUpdate(param)) return true; } if (algo.Problem != null && algo.Problem.Parameters != null) foreach (var param in algo.Problem.Parameters.Items) { if (RequiresUpdate(param)) return true; } return false; } private static bool RequiresUpdate(Parameter param) { switch (param.Type) { case ParameterType.Type: return ((TypeValue)param.Value).Options == null; default: return false; } } public static void Update(Algorithm algo, OptimizationScenario scenario) { if (algo.Parameters != null) for (var i=0; i < algo.Parameters.Items.Count; i++) { if (RequiresUpdate(algo.Parameters.Items[i])) { var otherParam = (from p in scenario.FirstAlgorithm.Parameters.Items where p.Value.Name == algo.Parameters.Items[i].Value.Name select p).FirstOrDefault(); UpdateParameter(algo.Parameters.Items[i], otherParam); } } if (algo.Problem != null && algo.Problem.Parameters != null) for (var i = 0; i < algo.Problem.Parameters.Items.Count; i++) { if (RequiresUpdate(algo.Problem.Parameters.Items[i])) { var otherParam = (from p in scenario.FirstAlgorithm.Problem.Parameters.Items where p.Value.Name == algo.Problem.Parameters.Items[i].Value.Name select p).FirstOrDefault(); UpdateParameter(algo.Problem.Parameters.Items[i], otherParam); } } } private static void UpdateParameter(Parameter param, Parameter param2) { switch (param.Type) { case ParameterType.Type: ((TypeValue)param.Value).Options = ((TypeValue)param2.Value).Options; break; } } } }