using HeuristicLab.Algorithms.CMAEvolutionStrategy; using HeuristicLab.Algorithms.LocalSearch; using HeuristicLab.Algorithms.ParameterlessPopulationPyramid; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Core.Networks; using HeuristicLab.Data; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Networks.IntegratedOptimization { [Item("TtpNetwork4", "An optimization network for the TTP.")] [Creatable("Optimization Networks")] [StorableClass] // standard ttp // cmaes variegates tsp coordinates // 1) init cmaes (length = ksp.values.length) // 2) start cmaes // 3) evaluate vector as follows: // 4) change tsp coordinates (mult by factor in vector) // 5) best tsp // 6) best ksp // 7) return ttp quality public sealed class TtpNetwork4 : Network { [StorableConstructor] private TtpNetwork4(bool deserializing) : base(deserializing) { } private TtpNetwork4(TtpNetwork4 original, Cloner cloner) : base(original, cloner) { } public TtpNetwork4() : base("TtpNetwork4") { var orchestratorNode = new TtpOrchestratorNode4(); Nodes.Add(orchestratorNode); var metaSolverNode = new OrchestratedAlgorithmNode("MetaSolver"); var cmaes = new CMAEvolutionStrategy(); cmaes.MaximumEvaluatedSolutions = 3000; cmaes.Engine = new ParallelEngine.ParallelEngine(); metaSolverNode.Algorithm = cmaes; orchestratorNode.MetaSolverOrchestrationPort.ConnectedPort = metaSolverNode.OrchestrationPort; Nodes.Add(metaSolverNode); var tspSolverNode = new OrchestratedAlgorithmNode("TspSolver") { CloneAlgorithm = true }; var ls = new LocalSearch(); ls.Problem = orchestratorNode.TspParameter.Value; ls.MaximumIterations.Value = 100; tspSolverNode.Algorithm = ls; orchestratorNode.TspSolverOrchestrationPort.ConnectedPort = tspSolverNode.OrchestrationPort; Nodes.Add(tspSolverNode); var kspSolverNode = new OrchestratedAlgorithmNode("KspSolver") { CloneAlgorithm = true }; var p3 = new ParameterlessPopulationPyramid(); p3.Problem = orchestratorNode.KspParameter.Value; p3.MaximumRuntime = 3; kspSolverNode.Algorithm = p3; orchestratorNode.KspSolverOrchestrationPort.ConnectedPort = kspSolverNode.OrchestrationPort; Nodes.Add(kspSolverNode); #region Import DoubleMatrix tspCoordinates; IntValue kspCapacity; IntArray kspItemWeights; IntArray kspItemValues; IntArray ttpAvailability; DoubleValue ttpMinSpeed; DoubleValue ttpMaxSpeed; DoubleValue ttpRentingRatio; TtpImporter.ImportTtpInstance(@"ttp-instances\berlin52-ttp\berlin52_n51_uncorr_01.ttp", out tspCoordinates, out kspCapacity, out kspItemValues, out kspItemWeights, out ttpAvailability, out ttpMinSpeed, out ttpMaxSpeed, out ttpRentingRatio); var tsp = orchestratorNode.TspParameter.Value; tsp.Coordinates = tspCoordinates; var ksp = orchestratorNode.KspParameter.Value; ksp.KnapsackCapacity = kspCapacity; ksp.Encoding.Length = kspItemValues.Length; ksp.Values = kspItemValues; ksp.Weights = kspItemWeights; orchestratorNode.AvailabilityParameter.Value = ttpAvailability; orchestratorNode.MinSpeedParameter.Value = ttpMinSpeed; orchestratorNode.MaxSpeedParameter.Value = ttpMaxSpeed; orchestratorNode.RentingRatioParameter.Value = ttpRentingRatio; #endregion } public override IDeepCloneable Clone(Cloner cloner) { return new TtpNetwork4(this, cloner); } } }