Free cookie consent management tool by TermsFeed Policy Generator

Changeset 14616


Ignore:
Timestamp:
01/30/17 10:28:58 (8 years ago)
Author:
jkarder
Message:

#2205: worked on optimization networks

Location:
branches/OptimizationNetworks
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.LocationRouting/3.3/LrpOrchestratorNode1.cs

    r14610 r14616  
    134134
    135135      #region Configure Ports
    136       AddOrchestrationPort<VariegationProblem>(MetaSolverName);
    137       AddEvaluationPort<RealVector>(MetaSolverName, "RealVector", "Quality");
    138       AddOrchestrationPort<VehicleRoutingProblem>(VrpSolverName);
    139       AddEvaluationPort<Permutation>(VrpSolverName, "TSPTour", "TSPTourLength");
    140       AddOrchestrationPort<FacilityLocationProblem>(FlpSolverName);
    141       AddEvaluationPort<BinaryVector>(FlpSolverName, "KnapsackSolution", "Quality");
     136      Ports.Add(CreateOrchestrationPort<VariegationProblem>(MetaSolverName));
     137      Ports.Add(CreateEvaluationPort<RealVector>(MetaSolverName, "RealVector", "Quality"));
     138      Ports.Add(CreateOrchestrationPort<VehicleRoutingProblem>(VrpSolverName));
     139      Ports.Add(CreateEvaluationPort<Permutation>(VrpSolverName, "TSPTour", "TSPTourLength"));
     140      Ports.Add(CreateOrchestrationPort<FacilityLocationProblem>(FlpSolverName));
     141      Ports.Add(CreateEvaluationPort<BinaryVector>(FlpSolverName, "KnapsackSolution", "Quality"));
    142142
    143143      RegisterEvents();
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.TravelingThief/3.3/TtpNetwork.cs

    r14613 r14616  
    3131  [Item("TtpNetwork", "An abstract base class for TTP optimization networks.")]
    3232  [StorableClass]
    33   public abstract class TtpNetwork : Network, IOptimizer {
     33  public abstract class TtpNetwork : Network {
     34    #region Constants
     35    protected const string OrchestratorNodeName = "Orchestrator";
     36    protected const string MetaSolverNodeName = "MetaSolver";
     37    protected const string TspSolverNodeName = "TspSolver";
     38    protected const string KspSolverNodeName = "KspSolver";
     39    #endregion
     40
    3441    #region Nodes
    35     public TtpOrchestratorNode1 Orchestrator {
    36       get { return (TtpOrchestratorNode1)Nodes["Orchestrator"]; }
     42    public TtpOrchestratorNode Orchestrator {
     43      get { return (TtpOrchestratorNode)Nodes[OrchestratorNodeName]; }
     44      protected set {
     45        if (Nodes.ContainsKey(OrchestratorNodeName))
     46          throw new InvalidOperationException("Orchestrator already set.");
     47        Nodes.Add(value);
     48      }
    3749    }
    3850
    3951    public OrchestratedAlgorithmNode MetaSolver {
    40       get { return (OrchestratedAlgorithmNode)Nodes["MetaSolver"]; }
     52      get { return (OrchestratedAlgorithmNode)Nodes[MetaSolverNodeName]; }
     53      protected set {
     54        if (Nodes.ContainsKey(MetaSolverNodeName))
     55          throw new InvalidOperationException("MetaSolver already set.");
     56        Nodes.Add(value);
     57        RegisterEvents();
     58      }
    4159    }
    4260
    4361    public OrchestratedAlgorithmNode TspSolver {
    44       get { return (OrchestratedAlgorithmNode)Nodes["TspSolver"]; }
     62      get { return (OrchestratedAlgorithmNode)Nodes[TspSolverNodeName]; }
     63      protected set {
     64        if (Nodes.ContainsKey(TspSolverNodeName))
     65          throw new InvalidOperationException("TspSolver already set.");
     66        Nodes.Add(value);
     67      }
    4568    }
    4669
    4770    public OrchestratedAlgorithmNode KspSolver {
    48       get { return (OrchestratedAlgorithmNode)Nodes["KspSolver"]; }
     71      get { return (OrchestratedAlgorithmNode)Nodes[KspSolverNodeName]; }
     72      protected set {
     73        if (Nodes.ContainsKey(KspSolverNodeName))
     74          throw new InvalidOperationException("KspSolver already set.");
     75        Nodes.Add(value);
     76      }
    4977    }
    5078    #endregion
     
    5684    }
    5785    protected TtpNetwork() : this("TtpNetwork") { }
    58     protected TtpNetwork(string name) : base(name) {
    59       Nodes.Add(new TtpOrchestratorNode1("Orchestrator"));
    60       Nodes.Add(new OrchestratedAlgorithmNode("MetaSolver"));
    61       Nodes.Add(new OrchestratedAlgorithmNode("TspSolver"));
    62       Nodes.Add(new OrchestratedAlgorithmNode("KspSolver"));
    63 
    64       RegisterEvents();
    65     }
     86    protected TtpNetwork(string name) : base(name) { }
    6687
    6788    [StorableHook(HookType.AfterDeserialization)]
     
    7091    }
    7192
    72     protected virtual void RegisterEvents() {
     93    private void RegisterEvents() {
    7394      MetaSolver.AlgorithmChanged += MetaSolver_AlgorithmChanged;
    7495      RegisterAlgorithmEvents();
    7596    }
    7697
    77     protected virtual void RegisterAlgorithmEvents() {
     98    private void MetaSolver_AlgorithmChanged(object sender, EventArgs e) {
     99      RegisterAlgorithmEvents();
     100    }
     101
     102    private void RegisterAlgorithmEvents() {
    78103      var algorithm = MetaSolver.Algorithm;
    79104      if (algorithm == null) return;
     
    86111      algorithm.Stopped += OnStopped;
    87112      algorithm.ExceptionOccurred += OnExceptionOccurred;
    88     }
    89 
    90     protected virtual void MetaSolver_AlgorithmChanged(object sender, EventArgs e) {
    91       RegisterAlgorithmEvents();
    92113    }
    93114
     
    103124    public void Pause() { Orchestrator.Pause(); }
    104125    public void Stop() { Orchestrator.Stop(); }
    105     #endregion
    106 
    107     private void OnExecutionStateChanged(object sender, EventArgs e) { OnExecutionStateChanged(); }
    108     private void OnExecutionTimeChanged(object sender, EventArgs e) { OnExecutionTimeChanged(); }
    109     private void OnPrepared(object sender, EventArgs e) { OnPrepared(); }
    110     private void OnStarted(object sender, EventArgs e) { OnStarted(); }
    111     private void OnPaused(object sender, EventArgs e) { OnPaused(); }
    112     private void OnStopped(object sender, EventArgs e) { OnStopped(); }
    113     private void OnExceptionOccurred(object sender, EventArgs<Exception> e) { OnExceptionOccurred(e.Value); }
    114126
    115127    public event EventHandler ExecutionStateChanged;
     
    154166      if (handler != null) handler(this, new EventArgs<Exception>(exception));
    155167    }
     168    #endregion
     169
     170    protected void OnExecutionStateChanged(object sender, EventArgs e) { OnExecutionStateChanged(); }
     171    protected void OnExecutionTimeChanged(object sender, EventArgs e) { OnExecutionTimeChanged(); }
     172    protected void OnPrepared(object sender, EventArgs e) { OnPrepared(); }
     173    protected void OnStarted(object sender, EventArgs e) { OnStarted(); }
     174    protected void OnPaused(object sender, EventArgs e) { OnPaused(); }
     175    protected void OnStopped(object sender, EventArgs e) { OnStopped(); }
     176    protected void OnExceptionOccurred(object sender, EventArgs<Exception> e) { OnExceptionOccurred(e.Value); }
    156177  }
    157178}
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.TravelingThief/3.3/TtpNetwork1.cs

    r14610 r14616  
    3838    public TtpNetwork1() : this("TtpNetwork1") { }
    3939    public TtpNetwork1(string name) : base(name) {
     40      Orchestrator = new TtpOrchestratorNode1(OrchestratorNodeName);
     41      MetaSolver = new OrchestratedAlgorithmNode(MetaSolverNodeName);
     42      TspSolver = new OrchestratedAlgorithmNode(TspSolverNodeName);
     43      KspSolver = new OrchestratedAlgorithmNode(KspSolverNodeName);
     44
    4045      var cmaes = new CMAEvolutionStrategy();
    4146      cmaes.Problem = new VariegationProblem();
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.TravelingThief/3.3/TtpNetwork2.cs

    r14610 r14616  
    3838    public TtpNetwork2() : this("TtpNetwork2") { }
    3939    public TtpNetwork2(string name) : base(name) {
     40      Orchestrator = new TtpOrchestratorNode2(OrchestratorNodeName);
     41      MetaSolver = new OrchestratedAlgorithmNode(MetaSolverNodeName);
     42      TspSolver = new OrchestratedAlgorithmNode(TspSolverNodeName);
     43      KspSolver = new OrchestratedAlgorithmNode(KspSolverNodeName);
     44
    4045      var cmaes = new CMAEvolutionStrategy();
    4146      cmaes.Problem = new VariegationProblem();
     
    4550
    4651      var ls = new LocalSearch();
    47       ls.Problem = Orchestrator.KspParameter.Value;
     52      ls.Problem = Orchestrator.TspParameter.Value;
    4853      ls.MaximumIterations.Value = 100;
    4954      ls.SampleSize.Value = 2000;
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.TravelingThief/3.3/TtpNetwork3.cs

    r14610 r14616  
    3838    public TtpNetwork3() : this("TtpNetwork3") { }
    3939    public TtpNetwork3(string name) : base(name) {
     40      Orchestrator = new TtpOrchestratorNode2(OrchestratorNodeName);
     41      MetaSolver = new OrchestratedAlgorithmNode(MetaSolverNodeName);
     42      TspSolver = new OrchestratedAlgorithmNode(TspSolverNodeName);
     43      KspSolver = new OrchestratedAlgorithmNode(KspSolverNodeName);
     44
    4045      var cmaes = new CMAEvolutionStrategy();
    4146      cmaes.Problem = new VariegationProblem();
     
    4550
    4651      var ls = new LocalSearch();
    47       ls.Problem = Orchestrator.KspParameter.Value;
     52      ls.Problem = Orchestrator.TspParameter.Value;
    4853      ls.MaximumIterations.Value = 100;
    4954      ls.SampleSize.Value = 2000;
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.TravelingThief/3.3/TtpOrchestratorNode.cs

    r14610 r14616  
    2727using HeuristicLab.Core.Networks;
    2828using HeuristicLab.Data;
    29 using HeuristicLab.Encodings.BinaryVectorEncoding;
    30 using HeuristicLab.Encodings.PermutationEncoding;
    3129using HeuristicLab.Encodings.RealVectorEncoding;
    3230using HeuristicLab.Operators;
     
    4139  public abstract class TtpOrchestratorNode : OrchestratorNode {
    4240    #region Constants
    43     private const string InstanceParameterName = "Instance";
    44     private const string TspParameterName = "TSP";
    45     private const string KspParameterName = "KSP";
    46     private const string AvailabilityParameterName = "Availability";
    47     private const string MinSpeedParameterName = "MinSpeed";
    48     private const string MaxSpeedParameterName = "MaxSpeed";
    49     private const string RentingRatioParameterName = "RentingRatio";
    50     private const string MetaSolverName = "MetaSolver";
    51     private const string TspSolverName = "TspSolver";
    52     private const string KspSolverName = "KspSolver";
     41    protected const string InstanceParameterName = "Instance";
     42    protected const string TspParameterName = "TSP";
     43    protected const string KspParameterName = "KSP";
     44    protected const string AvailabilityParameterName = "Availability";
     45    protected const string MinSpeedParameterName = "MinSpeed";
     46    protected const string MaxSpeedParameterName = "MaxSpeed";
     47    protected const string RentingRatioParameterName = "RentingRatio";
     48    protected const string MetaSolverName = "MetaSolver";
     49    protected const string TspSolverName = "TspSolver";
     50    protected const string KspSolverName = "KspSolver";
    5351    #endregion
    5452
     
    10098    public IMessagePort MetaSolverOrchestrationPort {
    10199      get { return (IMessagePort)Ports[MetaSolverName + OrchestrationPortNameSuffix]; }
     100      protected set {
     101        string portName = MetaSolverName + OrchestrationPortNameSuffix;
     102        if (Ports.ContainsKey(portName))
     103          throw new InvalidOperationException(portName + " already set.");
     104        Ports.Add(value);
     105        value.ConnectedPortChanged += MetaSolverOrchestrationPort_ConnectedPortChanged;
     106      }
    102107    }
    103108
    104109    public IMessagePort MetaSolverEvaluationPort {
    105110      get { return (IMessagePort)Ports[MetaSolverName + EvaluationPortNameSuffix]; }
     111      protected set {
     112        string portName = MetaSolverName + EvaluationPortNameSuffix;
     113        if (Ports.ContainsKey(portName))
     114          throw new InvalidOperationException(portName + " already set.");
     115        Ports.Add(value);
     116      }
    106117    }
    107118
    108119    public IMessagePort TspSolverOrchestrationPort {
    109120      get { return (IMessagePort)Ports[TspSolverName + OrchestrationPortNameSuffix]; }
     121      protected set {
     122        string portName = TspSolverName + OrchestrationPortNameSuffix;
     123        if (Ports.ContainsKey(portName))
     124          throw new InvalidOperationException(portName + " already set.");
     125        Ports.Add(value);
     126        value.ConnectedPortChanged += TspSolverOrchestrationPort_ConnectedPortChanged;
     127      }
    110128    }
    111129
    112130    public IMessagePort TspSolverEvaluationPort {
    113131      get { return (IMessagePort)Ports[TspSolverName + EvaluationPortNameSuffix]; }
     132      protected set {
     133        string portName = TspSolverName + EvaluationPortNameSuffix;
     134        if (Ports.ContainsKey(portName))
     135          throw new InvalidOperationException(portName + " already set.");
     136        Ports.Add(value);
     137      }
    114138    }
    115139
    116140    public IMessagePort KspSolverOrchestrationPort {
    117141      get { return (IMessagePort)Ports[KspSolverName + OrchestrationPortNameSuffix]; }
     142      protected set {
     143        string portName = KspSolverName + OrchestrationPortNameSuffix;
     144        if (Ports.ContainsKey(portName))
     145          throw new InvalidOperationException(portName + " already set.");
     146        Ports.Add(value);
     147        value.ConnectedPortChanged += KspSolverOrchestrationPort_ConnectedPortChanged;
     148      }
    118149    }
    119150
    120151    public IMessagePort KspSolverEvaluationPort {
    121152      get { return (IMessagePort)Ports[KspSolverName + EvaluationPortNameSuffix]; }
     153      protected set {
     154        string portName = KspSolverName + EvaluationPortNameSuffix;
     155        if (Ports.ContainsKey(portName))
     156          throw new InvalidOperationException(portName + " already set.");
     157        Ports.Add(value);
     158      }
    122159    }
    123160    #endregion
     
    139176    protected TtpOrchestratorNode() : this("TtpOrchestratorNode") { }
    140177    protected TtpOrchestratorNode(string name) : base(name) {
    141       #region Configure Parameters
    142178      Parameters.Add(new FixedValueParameter<TextFileValue>(InstanceParameterName));
    143179      Parameters.Add(new ValueParameter<TravelingSalesmanProblem>(TspParameterName, new TravelingSalesmanProblem()));
     
    147183      Parameters.Add(new ValueParameter<DoubleValue>(MaxSpeedParameterName, new DoubleValue(1.0)));
    148184      Parameters.Add(new ValueParameter<DoubleValue>(RentingRatioParameterName, new DoubleValue(0.5)));
    149       #endregion
    150 
    151       #region Configure Ports
    152       AddOrchestrationPort<VariegationProblem>(MetaSolverName);
    153       AddEvaluationPort<RealVector>(MetaSolverName, "RealVector", "Quality");
    154       AddOrchestrationPort<TourProfitProblem>(TspSolverName);
    155       AddEvaluationPort<Permutation>(TspSolverName, "TSPTour", "TSPTourLength");
    156       AddOrchestrationPort<BinaryKnapsackProblem>(KspSolverName);
    157       AddEvaluationPort<BinaryVector>(KspSolverName, "KnapsackSolution", "Quality");
    158 
    159       RegisterEvents();
    160       #endregion
     185
     186      InstanceParameter.Value.ToStringChanged += InstanceParameter_Value_ToStringChanged;
    161187    }
    162188
     
    166192    }
    167193
    168     protected virtual void RegisterEvents() {
     194    private void RegisterEvents() {
    169195      InstanceParameter.Value.ToStringChanged += InstanceParameter_Value_ToStringChanged;
    170196      MetaSolverOrchestrationPort.ConnectedPortChanged += MetaSolverOrchestrationPort_ConnectedPortChanged;
     
    173199    }
    174200
    175     private void InstanceParameter_Value_ToStringChanged(object sender, EventArgs e) {
     201    protected void InstanceParameter_Value_ToStringChanged(object sender, EventArgs e) {
    176202      string filePath = InstanceParameter.Value.Value;
    177203      TtpUtils.Import(filePath, out tspCoordinates, out distanceType,
     
    196222    }
    197223
     224    protected virtual void MetaSolverOrchestrationPort_ConnectedPortChanged(object sender, EventArgs e) {
     225      if (MetaSolverOrchestrationPort.ConnectedPort == null) return;
     226
     227      var node = MetaSolverOrchestrationPort.ConnectedPort.Parent as OrchestratedAlgorithmNode;
     228      if (node == null) return;
     229
     230      var hook = new HookOperator { Name = "Meta Eval Hook" };
     231      hook.Parameters.Add(new LookupParameter<RealVector>("RealVector") { Hidden = true });
     232      hook.Parameters.Add(new LookupParameter<DoubleValue>("Quality") { Hidden = true });
     233      node.EvalHook = hook;
     234
     235      node.OrchestrationPort.CloneParametersFromPort(MetaSolverOrchestrationPort);
     236      node.EvaluationPort.CloneParametersFromPort(MetaSolverEvaluationPort);
     237      node.EvaluationPort.ConnectedPort = MetaSolverEvaluationPort;
     238    }
     239
     240    protected virtual void TspSolverOrchestrationPort_ConnectedPortChanged(object sender, EventArgs e) {
     241      if (TspSolverOrchestrationPort.ConnectedPort == null) return;
     242
     243      var node = TspSolverOrchestrationPort.ConnectedPort.Parent as OrchestratedAlgorithmNode;
     244      if (node == null) return;
     245
     246      node.OrchestrationPort.CloneParametersFromPort(TspSolverOrchestrationPort);
     247    }
     248
     249    protected virtual void KspSolverOrchestrationPort_ConnectedPortChanged(object sender, EventArgs e) {
     250      if (KspSolverOrchestrationPort.ConnectedPort == null) return;
     251
     252      var node = KspSolverOrchestrationPort.ConnectedPort.Parent as OrchestratedAlgorithmNode;
     253      if (node == null) return;
     254
     255      node.OrchestrationPort.CloneParametersFromPort(KspSolverOrchestrationPort);
     256    }
     257
    198258    public override void Prepare(bool clearRuns = false) {
    199259      Results.Clear();
    200 
    201       var metaMsg = MetaSolverOrchestrationPort.PrepareMessage();
    202       var msgFlags = OrchestrationMessage.Prepare | OrchestrationMessage.SetEvalHook;
    203       if (clearRuns) msgFlags |= OrchestrationMessage.ClearRuns;
    204       metaMsg["OrchestrationMessage"] = new EnumValue<OrchestrationMessage>(msgFlags);
    205       var problem = new VariegationProblem();
    206       problem.Encoding.Length = KspParameter.Value.Length;
    207       problem.Encoding.Bounds = new DoubleMatrix(new[,] { { -1.0, 1.0 } });
    208       metaMsg["Problem"] = problem;
    209       MetaSolverOrchestrationPort.SendMessage(metaMsg);
    210260    }
    211261
     
    255305      messageActions.Add(MetaSolverEvaluationPort, MetaSolverEvaluationPortMessage);
    256306      messageActions.Add(TspSolverOrchestrationPort, TspSolverOrchestrationPortMessage);
    257       messageActions.Add(TspSolverEvaluationPort, TspSolverEvaluationPortMessage);
    258307      messageActions.Add(KspSolverOrchestrationPort, KspSolverOrchestrationPortMessage);
    259       messageActions.Add(KspSolverEvaluationPort, KspSolverEvaluationPortMessage);
    260308
    261309      messageActions[port](message);
     
    291339    private void KspSolverEvaluationPortMessage(IMessage message) { }
    292340    #endregion
    293 
    294     #region Event Handlers
    295     private void MetaSolverOrchestrationPort_ConnectedPortChanged(object sender, EventArgs e) {
    296       if (MetaSolverOrchestrationPort.ConnectedPort == null) return;
    297 
    298       var node = MetaSolverOrchestrationPort.ConnectedPort.Parent as OrchestratedAlgorithmNode;
    299       if (node == null) return;
    300 
    301       var hook = new HookOperator { Name = "Meta Eval Hook" };
    302       hook.Parameters.Add(new LookupParameter<RealVector>("RealVector") { Hidden = true });
    303       hook.Parameters.Add(new LookupParameter<DoubleValue>("Quality") { Hidden = true });
    304       node.EvalHook = hook;
    305 
    306       node.OrchestrationPort.CloneParametersFromPort(MetaSolverOrchestrationPort);
    307       node.EvaluationPort.CloneParametersFromPort(MetaSolverEvaluationPort);
    308       node.EvaluationPort.ConnectedPort = MetaSolverEvaluationPort;
    309     }
    310 
    311     private void TspSolverOrchestrationPort_ConnectedPortChanged(object sender, EventArgs e) {
    312       if (TspSolverOrchestrationPort.ConnectedPort == null) return;
    313 
    314       var node = TspSolverOrchestrationPort.ConnectedPort.Parent as OrchestratedAlgorithmNode;
    315       if (node == null) return;
    316 
    317       var hook = new HookOperator { Name = "TSP Eval Hook" };
    318       hook.Parameters.Add(new LookupParameter<Permutation>("TSPTour") { Hidden = true });
    319       hook.Parameters.Add(new LookupParameter<DoubleValue>("TSPTourLength") { Hidden = true });
    320       node.EvalHook = hook;
    321 
    322       node.OrchestrationPort.CloneParametersFromPort(TspSolverOrchestrationPort);
    323       node.EvaluationPort.CloneParametersFromPort(TspSolverEvaluationPort);
    324       node.EvaluationPort.ConnectedPort = TspSolverEvaluationPort;
    325     }
    326 
    327     private void KspSolverOrchestrationPort_ConnectedPortChanged(object sender, EventArgs e) {
    328       if (KspSolverOrchestrationPort.ConnectedPort == null) return;
    329 
    330       var node = KspSolverOrchestrationPort.ConnectedPort.Parent as OrchestratedAlgorithmNode;
    331       if (node == null) return;
    332 
    333       var hook = new HookOperator { Name = "KSP Eval Hook" };
    334       hook.Parameters.Add(new LookupParameter<BinaryVector>("KnapsackSolution") { Hidden = true });
    335       hook.Parameters.Add(new LookupParameter<DoubleValue>("Quality") { Hidden = true });
    336       node.EvalHook = hook;
    337 
    338       node.OrchestrationPort.CloneParametersFromPort(KspSolverOrchestrationPort);
    339       node.EvaluationPort.CloneParametersFromPort(KspSolverEvaluationPort);
    340       node.EvaluationPort.ConnectedPort = KspSolverEvaluationPort;
    341     }
    342     #endregion
    343341  }
    344342}
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.TravelingThief/3.3/TtpOrchestratorNode1.cs

    r14610 r14616  
    4242    private TtpOrchestratorNode1(TtpOrchestratorNode1 original, Cloner cloner) : base(original, cloner) { }
    4343    public TtpOrchestratorNode1() : this("TtpOrchestratorNode1") { }
    44     public TtpOrchestratorNode1(string name) : base(name) { }
     44    public TtpOrchestratorNode1(string name) : base(name) {
     45      MetaSolverOrchestrationPort = CreateOrchestrationPort<VariegationProblem>(MetaSolverName);
     46      MetaSolverEvaluationPort = CreateEvaluationPort<RealVector>(MetaSolverName, "RealVector", "Quality");
     47      TspSolverOrchestrationPort = CreateOrchestrationPort<TourProfitProblem>(TspSolverName);
     48      KspSolverOrchestrationPort = CreateOrchestrationPort<BinaryKnapsackProblem>(KspSolverName);
     49    }
    4550
    4651    public override IDeepCloneable Clone(Cloner cloner) {
    4752      return new TtpOrchestratorNode1(this, cloner);
     53    }
     54
     55    public override void Prepare(bool clearRuns = false) {
     56      base.Prepare(clearRuns);
     57
     58      var metaMsg = MetaSolverOrchestrationPort.PrepareMessage();
     59      var msgFlags = OrchestrationMessage.Prepare | OrchestrationMessage.SetEvalHook;
     60      if (clearRuns) msgFlags |= OrchestrationMessage.ClearRuns;
     61      metaMsg["OrchestrationMessage"] = new EnumValue<OrchestrationMessage>(msgFlags);
     62      var problem = new VariegationProblem();
     63      problem.Encoding.Length = KspParameter.Value.Length;
     64      problem.Encoding.Bounds = new DoubleMatrix(new[,] { { -1.0, 1.0 } });
     65      metaMsg["Problem"] = problem;
     66      MetaSolverOrchestrationPort.SendMessage(metaMsg);
    4867    }
    4968
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.TravelingThief/3.3/TtpOrchestratorNode2.cs

    r14610 r14616  
    4141    private TtpOrchestratorNode2(TtpOrchestratorNode2 original, Cloner cloner) : base(original, cloner) { }
    4242    public TtpOrchestratorNode2() : this("TtpOrchestratorNode2") { }
    43     public TtpOrchestratorNode2(string name) : base(name) { }
     43    public TtpOrchestratorNode2(string name) : base(name) {
     44      MetaSolverOrchestrationPort = CreateOrchestrationPort<VariegationProblem>(MetaSolverName);
     45      MetaSolverEvaluationPort = CreateEvaluationPort<RealVector>(MetaSolverName, "RealVector", "Quality");
     46      TspSolverOrchestrationPort = CreateOrchestrationPort<TravelingSalesmanProblem>(TspSolverName);
     47      KspSolverOrchestrationPort = CreateOrchestrationPort<LootProfitProblem>(KspSolverName);
     48    }
    4449
    4550    public override IDeepCloneable Clone(Cloner cloner) {
    4651      return new TtpOrchestratorNode2(this, cloner);
     52    }
     53
     54    public override void Prepare(bool clearRuns = false) {
     55      base.Prepare(clearRuns);
     56
     57      var metaMsg = MetaSolverOrchestrationPort.PrepareMessage();
     58      var msgFlags = OrchestrationMessage.Prepare | OrchestrationMessage.SetEvalHook;
     59      if (clearRuns) msgFlags |= OrchestrationMessage.ClearRuns;
     60      metaMsg["OrchestrationMessage"] = new EnumValue<OrchestrationMessage>(msgFlags);
     61      var problem = new VariegationProblem();
     62      problem.Encoding.Length = TspParameter.Value.Coordinates.Rows * 2;
     63      problem.Encoding.Bounds = new DoubleMatrix(new[,] { { -1.0, 1.0 } });
     64      metaMsg["Problem"] = problem;
     65      MetaSolverOrchestrationPort.SendMessage(metaMsg);
    4766    }
    4867
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.TravelingThief/3.3/TtpOrchestratorNode3.cs

    r14610 r14616  
    4242    private TtpOrchestratorNode3(TtpOrchestratorNode3 original, Cloner cloner) : base(original, cloner) { }
    4343    public TtpOrchestratorNode3() : this("TtpOrchestratorNode3") { }
    44     public TtpOrchestratorNode3(string name) : base(name) { }
     44    public TtpOrchestratorNode3(string name) : base(name) {
     45      MetaSolverOrchestrationPort = CreateOrchestrationPort<VariegationProblem>(MetaSolverName);
     46      MetaSolverEvaluationPort = CreateEvaluationPort<RealVector>(MetaSolverName, "RealVector", "Quality");
     47      TspSolverOrchestrationPort = CreateOrchestrationPort<TravelingSalesmanProblem>(TspSolverName);
     48      KspSolverOrchestrationPort = CreateOrchestrationPort<BinaryKnapsackProblem>(KspSolverName);
     49    }
    4550
    4651    public override IDeepCloneable Clone(Cloner cloner) {
    4752      return new TtpOrchestratorNode3(this, cloner);
     53    }
     54
     55    public override void Prepare(bool clearRuns = false) {
     56      base.Prepare(clearRuns);
     57
     58      var metaMsg = MetaSolverOrchestrationPort.PrepareMessage();
     59      var msgFlags = OrchestrationMessage.Prepare | OrchestrationMessage.SetEvalHook;
     60      if (clearRuns) msgFlags |= OrchestrationMessage.ClearRuns;
     61      metaMsg["OrchestrationMessage"] = new EnumValue<OrchestrationMessage>(msgFlags);
     62      var problem = new VariegationProblem();
     63      problem.Encoding.Length = KspParameter.Value.Length + TspParameter.Value.Coordinates.Rows * 2;
     64      problem.Encoding.Bounds = new DoubleMatrix(new[,] { { -1.0, 1.0 } });
     65      metaMsg["Problem"] = problem;
     66      MetaSolverOrchestrationPort.SendMessage(metaMsg);
    4867    }
    4968
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization/3.3/OrchestratorNode.cs

    r14610 r14616  
    3636  public abstract class OrchestratorNode : Node, IOrchestratorNode {
    3737    #region Constants
    38     private const string OrchestrationMessageParameterName = "OrchestrationMessage";
     38    protected const string OrchestrationMessageParameterName = "OrchestrationMessage";
    3939    protected const string OrchestrationPortNameSuffix = "OrchestrationPort";
    4040    protected const string EvaluationPortNameSuffix = "EvaluationPort";
     
    9797    }
    9898
    99     protected void AddOrchestrationPort<T>(string solverName)
    100         where T : class, IProblem {
     99    protected IMessagePort CreateOrchestrationPort<T>(string solverName) where T : class, IProblem {
    101100      var orchestrationPort = new MessagePort(solverName + OrchestrationPortNameSuffix);
    102101      orchestrationPort.Parameters.Add(new PortParameter<EnumValue<OrchestrationMessage>>("OrchestrationMessage") {
     
    109108        Type = PortParameterType.Input
    110109      });
    111       Ports.Add(orchestrationPort);
     110      return orchestrationPort;
    112111    }
    113112
    114     protected void AddEvaluationPort<T>(string solverName, string solutionName, string qualityName) where T : class, IItem {
     113    protected IMessagePort CreateEvaluationPort<T>(string solverName, string solutionName, string qualityName) where T : class, IItem {
    115114      var evaluationPort = new MessagePort(solverName + EvaluationPortNameSuffix);
    116115      evaluationPort.Parameters.Add(new PortParameter<T>(solutionName) {
     
    120119        Type = PortParameterType.Input | PortParameterType.Output
    121120      });
    122       Ports.Add(evaluationPort);
     121      return evaluationPort;
    123122    }
    124123
Note: See TracChangeset for help on using the changeset viewer.