Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/26/17 14:12:39 (8 years ago)
Author:
jkarder
Message:

#2205: worked on optimization networks

  • added abstract base classes for ttp networks/orchestrators
  • removed ttp networks/orchestrators from HeuristicLab.Networks.IntegratedOptimization
  • runs can now be cleared when preparing OrchestratedAlgorithmNodes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.TravelingThief/3.3/TtpNetwork3.cs

    r14604 r14610  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    2422using HeuristicLab.Algorithms.CMAEvolutionStrategy;
    2523using HeuristicLab.Algorithms.LocalSearch;
     
    2725using HeuristicLab.Common;
    2826using HeuristicLab.Core;
    29 using HeuristicLab.Core.Networks;
    3027using HeuristicLab.Optimization;
    3128using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3532  [Creatable("Optimization Networks")]
    3633  [StorableClass]
    37   public sealed class TtpNetwork3 : Network, IOptimizer {
    38     #region Nodes
    39     public TtpOrchestratorNode1 Orchestrator {
    40       get { return (TtpOrchestratorNode1)Nodes["Orchestrator"]; }
    41     }
    42 
    43     public OrchestratedAlgorithmNode MetaSolver {
    44       get { return (OrchestratedAlgorithmNode)Nodes["MetaSolver"]; }
    45     }
    46 
    47     public OrchestratedAlgorithmNode TspSolver {
    48       get { return (OrchestratedAlgorithmNode)Nodes["TspSolver"]; }
    49     }
    50 
    51     public OrchestratedAlgorithmNode KspSolver {
    52       get { return (OrchestratedAlgorithmNode)Nodes["KspSolver"]; }
    53     }
    54     #endregion
    55 
     34  public sealed class TtpNetwork3 : TtpNetwork, IOptimizer {
    5635    [StorableConstructor]
    5736    private TtpNetwork3(bool deserializing) : base(deserializing) { }
    58     private TtpNetwork3(TtpNetwork3 original, Cloner cloner) : base(original, cloner) {
    59       RegisterEvents();
    60     }
    61 
    62     private void RegisterEvents() {
    63       MetaSolver.Algorithm.ExecutionStateChanged += OnExecutionStateChanged;
    64       MetaSolver.Algorithm.ExecutionTimeChanged += OnExecutionTimeChanged;
    65       MetaSolver.Algorithm.Prepared += OnPrepared;
    66       MetaSolver.Algorithm.Started += OnStarted;
    67       MetaSolver.Algorithm.Paused += OnPaused;
    68       MetaSolver.Algorithm.Stopped += OnStopped;
    69       MetaSolver.Algorithm.ExceptionOccurred += OnExceptionOccurred;
    70     }
    71 
    72     public TtpNetwork3() : base("TtpNetwork3") {
    73       var orchestratorNode = new TtpOrchestratorNode3("Orchestrator");
    74       Nodes.Add(orchestratorNode);
    75 
    76       var metaSolverNode = new OrchestratedAlgorithmNode("MetaSolver");
     37    private TtpNetwork3(TtpNetwork3 original, Cloner cloner) : base(original, cloner) { }
     38    public TtpNetwork3() : this("TtpNetwork3") { }
     39    public TtpNetwork3(string name) : base(name) {
    7740      var cmaes = new CMAEvolutionStrategy();
    7841      cmaes.Problem = new VariegationProblem();
    7942      cmaes.MaximumGenerations = 80;
    80       metaSolverNode.Algorithm = cmaes;
    81       orchestratorNode.MetaSolverOrchestrationPort.ConnectedPort = metaSolverNode.OrchestrationPort;
    82       Nodes.Add(metaSolverNode);
     43      MetaSolver.Algorithm = cmaes;
     44      Orchestrator.MetaSolverOrchestrationPort.ConnectedPort = MetaSolver.OrchestrationPort;
    8345
    84       var tspSolverNode = new OrchestratedAlgorithmNode("TspSolver");
    8546      var ls = new LocalSearch();
    86       ls.Problem = orchestratorNode.KspParameter.Value;
     47      ls.Problem = Orchestrator.KspParameter.Value;
    8748      ls.MaximumIterations.Value = 100;
    8849      ls.SampleSize.Value = 2000;
    89       tspSolverNode.Algorithm = ls;
    90       orchestratorNode.TspSolverOrchestrationPort.ConnectedPort = tspSolverNode.OrchestrationPort;
    91       Nodes.Add(tspSolverNode);
     50      TspSolver.Algorithm = ls;
     51      Orchestrator.TspSolverOrchestrationPort.ConnectedPort = TspSolver.OrchestrationPort;
    9252
    93       var kspSolverNode = new OrchestratedAlgorithmNode("KspSolver");
    9453      var p3 = new ParameterlessPopulationPyramid();
    95       p3.Problem = orchestratorNode.KspParameter.Value;
     54      p3.Problem = Orchestrator.KspParameter.Value;
    9655      p3.MaximumRuntime = 3;
    97       kspSolverNode.Algorithm = p3;
    98       orchestratorNode.KspSolverOrchestrationPort.ConnectedPort = kspSolverNode.OrchestrationPort;
    99       Nodes.Add(kspSolverNode);
    100 
    101       RegisterEvents();
     56      KspSolver.Algorithm = p3;
     57      Orchestrator.KspSolverOrchestrationPort.ConnectedPort = KspSolver.OrchestrationPort;
    10258    }
    10359
     
    10561      return new TtpNetwork3(this, cloner);
    10662    }
    107 
    108     [StorableHook(HookType.AfterDeserialization)]
    109     private void AfterDeserialization() {
    110       RegisterEvents();
    111     }
    112 
    113     #region IOptimizer Members
    114     public RunCollection Runs { get { return MetaSolver.Algorithm.Runs; } }
    115     public IEnumerable<IOptimizer> NestedOptimizers { get { yield break; } }
    116     public ExecutionState ExecutionState { get { return MetaSolver.Algorithm.ExecutionState; } }
    117     public TimeSpan ExecutionTime { get { return MetaSolver.Algorithm.ExecutionTime; } }
    118 
    119     public void Prepare(bool clearRuns) { Prepare(); }
    120     public void Prepare() { Orchestrator.Prepare(); }
    121     public void Start() {
    122       if (MetaSolver.Algorithm.ExecutionState == ExecutionState.Prepared)
    123         Orchestrator.Prepare();
    124       Orchestrator.StartAsync();
    125     }
    126     public void Pause() { Orchestrator.Pause(); }
    127     public void Stop() { Orchestrator.Stop(); }
    128     #endregion
    129 
    130     private void OnExecutionStateChanged(object sender, EventArgs e) { OnExecutionStateChanged(); }
    131     private void OnExecutionTimeChanged(object sender, EventArgs e) { OnExecutionTimeChanged(); }
    132     private void OnPrepared(object sender, EventArgs e) { OnPrepared(); }
    133     private void OnStarted(object sender, EventArgs e) { OnStarted(); }
    134     private void OnPaused(object sender, EventArgs e) { OnPaused(); }
    135     private void OnStopped(object sender, EventArgs e) { OnStopped(); }
    136     private void OnExceptionOccurred(object sender, EventArgs<Exception> e) { OnExceptionOccurred(e.Value); }
    137 
    138     public event EventHandler ExecutionStateChanged;
    139     private void OnExecutionStateChanged() {
    140       var handler = ExecutionStateChanged;
    141       if (handler != null) handler(this, EventArgs.Empty);
    142     }
    143 
    144     public event EventHandler ExecutionTimeChanged;
    145     private void OnExecutionTimeChanged() {
    146       var handler = ExecutionTimeChanged;
    147       if (handler != null) handler(this, EventArgs.Empty);
    148     }
    149 
    150     public event EventHandler Prepared;
    151     private void OnPrepared() {
    152       var handler = Prepared;
    153       if (handler != null) handler(this, EventArgs.Empty);
    154     }
    155 
    156     public event EventHandler Started;
    157     private void OnStarted() {
    158       var handler = Started;
    159       if (handler != null) handler(this, EventArgs.Empty);
    160     }
    161 
    162     public event EventHandler Paused;
    163     private void OnPaused() {
    164       var handler = Paused;
    165       if (handler != null) handler(this, EventArgs.Empty);
    166     }
    167 
    168     public event EventHandler Stopped;
    169     private void OnStopped() {
    170       var handler = Stopped;
    171       if (handler != null) handler(this, EventArgs.Empty);
    172     }
    173 
    174     public event EventHandler<EventArgs<Exception>> ExceptionOccurred;
    175     private void OnExceptionOccurred(Exception exception) {
    176       var handler = ExceptionOccurred;
    177       if (handler != null) handler(this, new EventArgs<Exception>(exception));
    178     }
    17963  }
    18064}
Note: See TracChangeset for help on using the changeset viewer.