Free cookie consent management tool by TermsFeed Policy Generator

Changeset 14628 for branches


Ignore:
Timestamp:
01/31/17 16:54:03 (7 years ago)
Author:
jkarder
Message:

#2205: worked on optimization networks

  • added variegation problem for minimization and maximization
  • refactored some classes
Location:
branches/OptimizationNetworks
Files:
2 added
1 deleted
16 edited
1 moved

Legend:

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

    r14621 r14628  
    2626using HeuristicLab.Common;
    2727using HeuristicLab.Core;
     28using HeuristicLab.Encodings.RealVectorEncoding;
    2829using HeuristicLab.Optimization;
    2930using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    5051
    5152      var cmaes = new CMAEvolutionStrategy();
    52       var vp = new VariegationProblem();
    53       vp.SetMaximization(false);
     53      var vp = new MinimizationVariegationProblem<RealVectorEncoding>();
    5454      cmaes.Problem = vp;
    5555      cmaes.MaximumGenerations = 80;
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.LocationRouting/3.3/LrpNetwork2.cs

    r14621 r14628  
    2626using HeuristicLab.Common;
    2727using HeuristicLab.Core;
     28using HeuristicLab.Encodings.RealVectorEncoding;
    2829using HeuristicLab.Optimization;
    2930using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    5051
    5152      var cmaes = new CMAEvolutionStrategy();
    52       var vp = new VariegationProblem();
    53       vp.SetMaximization(false);
     53      var vp = new MinimizationVariegationProblem<RealVectorEncoding>();
    5454      cmaes.Problem = vp;
    5555      cmaes.MaximumGenerations = 80;
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.LocationRouting/3.3/LrpOrchestratorNode.cs

    r14621 r14628  
    5050    protected const string FlpSolverName = "FlpSolver";
    5151    protected const string VrpSolverName = "VrpSolver";
     52    protected const string OrchestrationPortNameSuffix = "OrchestrationPort";
     53    protected const string EvaluationPortNameSuffix = "EvaluationPort";
    5254    #endregion
    5355
    5456    protected CancellationTokenSource cts;
    55     protected ResultCollection flpResults, vrpResults;
    5657
    5758    [Storable]
     
    309310
    310311    #region FlpSolver Message Handling
    311     protected virtual void FlpSolverOrchestrationPortMessage(IMessage message) {
    312       var results = (ResultCollection)message["Results"];
    313       if (results.ContainsKey("Best Solution")) {
    314         flpResults = results;
    315       }
    316     }
     312    protected virtual void FlpSolverOrchestrationPortMessage(IMessage message) { }
    317313
    318314    protected virtual void FlpSolverEvaluationPortMessage(IMessage message) { }
     
    320316
    321317    #region VrpSolver Message Handling
    322     protected virtual void VrpSolverOrchestrationPortMessage(IMessage message) {
    323       var results = (ResultCollection)message["Results"];
    324       if (results.ContainsKey("Best valid VRP Solution")) {
    325         vrpResults = results;
    326       }
    327     }
     318    protected virtual void VrpSolverOrchestrationPortMessage(IMessage message) { }
    328319
    329320    private void VrpSolverEvaluationPortMessage(IMessage message) { }
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.LocationRouting/3.3/LrpOrchestratorNode1.cs

    r14621 r14628  
    4343    public LrpOrchestratorNode1() : this("LrpOrchestratorNode1") { }
    4444    public LrpOrchestratorNode1(string name) : base(name) {
    45       MetaSolverOrchestrationPort = CreateOrchestrationPort<VariegationProblem>(MetaSolverName);
    46       MetaSolverEvaluationPort = CreateEvaluationPort<RealVector>(MetaSolverName, "RealVector", "Quality");
    47       FlpSolverOrchestrationPort = CreateOrchestrationPort<FacilityLocationProblem>(FlpSolverName);
    48       VrpSolverOrchestrationPort = CreateOrchestrationPort<VehicleRoutingProblem>(VrpSolverName);
     45      MetaSolverOrchestrationPort = CreateOrchestrationPort<MinimizationVariegationProblem<RealVectorEncoding>>(MetaSolverName + OrchestrationPortNameSuffix);
     46      MetaSolverEvaluationPort = CreateEvaluationPort<RealVector>(MetaSolverName + EvaluationPortNameSuffix, "RealVector", "Quality");
     47      FlpSolverOrchestrationPort = CreateOrchestrationPort<FacilityLocationProblem>(FlpSolverName + OrchestrationPortNameSuffix);
     48      VrpSolverOrchestrationPort = CreateOrchestrationPort<VehicleRoutingProblem>(VrpSolverName + OrchestrationPortNameSuffix);
    4949    }
    5050
     
    6060      if (clearRuns) msgFlags |= OrchestrationMessage.ClearRuns;
    6161      metaMsg["OrchestrationMessage"] = new EnumValue<OrchestrationMessage>(msgFlags);
    62       var problem = new VariegationProblem();
     62      var problem = new MinimizationVariegationProblem<RealVectorEncoding>();
    6363      problem.Encoding.Length = nrOfCustomers * 2;
    6464      problem.Encoding.Bounds = new DoubleMatrix(new[,] { { -1.0, 1.0 } });
     
    8585      cts.Token.ThrowIfCancellationRequested();
    8686
     87      var flpResults = (ResultCollection)flpMsg["Results"];
    8788      var bestFlpSolution = (IntegerVector)flpResults["Best Solution"].Value;
    8889      var flpSolution = FlpParameter.Value.GetSolution(bestFlpSolution);
     
    109110        cts.Token.ThrowIfCancellationRequested();
    110111
     112        var vrpResults = (ResultCollection)vrpMsg["Results"];
    111113        var bestVrpSolution = (VRPSolution)vrpResults["Best valid VRP Solution"].Value.Clone();
    112114        vrpSolutions.Add(new Result("Depot " + depot.Key, bestVrpSolution));
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.LocationRouting/3.3/LrpOrchestratorNode2.cs

    r14621 r14628  
    4343    public LrpOrchestratorNode2() : this("LrpOrchestratorNode2") { }
    4444    public LrpOrchestratorNode2(string name) : base(name) {
    45       MetaSolverOrchestrationPort = CreateOrchestrationPort<VariegationProblem>(MetaSolverName);
    46       MetaSolverEvaluationPort = CreateEvaluationPort<RealVector>(MetaSolverName, "RealVector", "Quality");
    47       FlpSolverOrchestrationPort = CreateOrchestrationPort<FacilityLocationProblem>(FlpSolverName);
    48       VrpSolverOrchestrationPort = CreateOrchestrationPort<VehicleRoutingProblem>(VrpSolverName);
     45      MetaSolverOrchestrationPort = CreateOrchestrationPort<MinimizationVariegationProblem<RealVectorEncoding>>(MetaSolverName + OrchestrationPortNameSuffix);
     46      MetaSolverEvaluationPort = CreateEvaluationPort<RealVector>(MetaSolverName + EvaluationPortNameSuffix, "RealVector", "Quality");
     47      FlpSolverOrchestrationPort = CreateOrchestrationPort<FacilityLocationProblem>(FlpSolverName + OrchestrationPortNameSuffix);
     48      VrpSolverOrchestrationPort = CreateOrchestrationPort<VehicleRoutingProblem>(VrpSolverName + OrchestrationPortNameSuffix);
    4949    }
    5050
     
    6060      if (clearRuns) msgFlags |= OrchestrationMessage.ClearRuns;
    6161      metaMsg["OrchestrationMessage"] = new EnumValue<OrchestrationMessage>(msgFlags);
    62       var problem = new VariegationProblem();
     62      var problem = new MinimizationVariegationProblem<RealVectorEncoding>();
    6363      problem.Encoding.Length = nrOfDepots * 2;
    6464      problem.Encoding.Bounds = new DoubleMatrix(new[,] { { -1.0, 1.0 } });
     
    8585      cts.Token.ThrowIfCancellationRequested();
    8686
     87      var flpResults = (ResultCollection)flpMsg["Results"];
    8788      var bestFlpSolution = (IntegerVector)flpResults["Best Solution"].Value;
    8889      var flpSolution = FlpParameter.Value.GetSolution(bestFlpSolution);
     
    109110        cts.Token.ThrowIfCancellationRequested();
    110111
     112        var vrpResults = (ResultCollection)vrpMsg["Results"];
    111113        var bestVrpSolution = (VRPSolution)vrpResults["Best valid VRP Solution"].Value.Clone();
    112114        vrpSolutions.Add(new Result("Depot " + depot.Key, bestVrpSolution));
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.MachineLearning/HeuristicLab.Networks.IntegratedOptimization.MachineLearning-3.3.csproj

    r14625 r14628  
    111111      <Private>False</Private>
    112112    </Reference>
    113     <Reference Include="HeuristicLab.Networks.IntegratedOptimization-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    114       <SpecificVersion>False</SpecificVersion>
    115       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Networks.IntegratedOptimization-3.3.dll</HintPath>
    116       <Private>False</Private>
    117     </Reference>
    118113    <Reference Include="HeuristicLab.Operators-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    119114      <SpecificVersion>False</SpecificVersion>
     
    189184    <None Include="HeuristicLab.snk" />
    190185    <None Include="Plugin.cs.frame" />
    191     <None Include="Properties\AssemblyInfo.frame" />
     186    <None Include="Properties\AssemblyInfo.cs.frame" />
     187  </ItemGroup>
     188  <ItemGroup>
     189    <ProjectReference Include="..\HeuristicLab.Networks.IntegratedOptimization\3.3\HeuristicLab.Networks.IntegratedOptimization-3.3.csproj">
     190      <Project>{b6263d3e-dcaf-42b0-a440-3deef1ff0429}</Project>
     191      <Name>HeuristicLab.Networks.IntegratedOptimization-3.3</Name>
     192      <Private>False</Private>
     193    </ProjectReference>
    192194  </ItemGroup>
    193195  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.MachineLearning/Properties/AssemblyInfo.cs.frame

    r14627 r14628  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.TravelingThief/3.3/TtpNetwork1.cs

    r14621 r14628  
    2525using HeuristicLab.Common;
    2626using HeuristicLab.Core;
     27using HeuristicLab.Encodings.RealVectorEncoding;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2829
     
    4344
    4445      var cmaes = new CMAEvolutionStrategy();
    45       cmaes.Problem = new VariegationProblem();
     46      cmaes.Problem = new MaximizationVariegationProblem<RealVectorEncoding>();
    4647      cmaes.MaximumGenerations = 80;
    4748      MetaSolver.Algorithm = cmaes;
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.TravelingThief/3.3/TtpNetwork2.cs

    r14621 r14628  
    2525using HeuristicLab.Common;
    2626using HeuristicLab.Core;
     27using HeuristicLab.Encodings.RealVectorEncoding;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2829
     
    4344
    4445      var cmaes = new CMAEvolutionStrategy();
    45       cmaes.Problem = new VariegationProblem();
     46      cmaes.Problem = new MaximizationVariegationProblem<RealVectorEncoding>();
    4647      cmaes.MaximumGenerations = 80;
    4748      MetaSolver.Algorithm = cmaes;
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.TravelingThief/3.3/TtpNetwork3.cs

    r14621 r14628  
    2525using HeuristicLab.Common;
    2626using HeuristicLab.Core;
     27using HeuristicLab.Encodings.RealVectorEncoding;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2829
     
    4344
    4445      var cmaes = new CMAEvolutionStrategy();
    45       cmaes.Problem = new VariegationProblem();
     46      cmaes.Problem = new MaximizationVariegationProblem<RealVectorEncoding>();
    4647      cmaes.MaximumGenerations = 80;
    4748      MetaSolver.Algorithm = cmaes;
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.TravelingThief/3.3/TtpOrchestratorNode.cs

    r14621 r14628  
    2929using HeuristicLab.Encodings.RealVectorEncoding;
    3030using HeuristicLab.Operators;
    31 using HeuristicLab.Optimization;
    3231using HeuristicLab.Parameters;
    3332using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    4948    protected const string TspSolverName = "TspSolver";
    5049    protected const string KspSolverName = "KspSolver";
     50    protected const string OrchestrationPortNameSuffix = "OrchestrationPort";
     51    protected const string EvaluationPortNameSuffix = "EvaluationPort";
    5152    #endregion
    5253
    5354    protected CancellationTokenSource cts;
    54     protected ResultCollection tspResults, kspResults;
    5555
    5656    [Storable]
     
    319319
    320320    #region TspSolver Message Handling
    321     protected virtual void TspSolverOrchestrationPortMessage(IMessage message) {
    322       var results = (ResultCollection)message["Results"];
    323       if (results.ContainsKey("Best TSP Solution")) {
    324         tspResults = results;
    325       }
    326     }
     321    protected virtual void TspSolverOrchestrationPortMessage(IMessage message) { }
    327322
    328323    protected virtual void TspSolverEvaluationPortMessage(IMessage message) { }
     
    330325
    331326    #region KspSolver Message Handling
    332     protected virtual void KspSolverOrchestrationPortMessage(IMessage message) {
    333       var results = (ResultCollection)message["Results"];
    334       if (results.ContainsKey("Best Solution")) {
    335         kspResults = results;
    336       }
    337     }
     327    protected virtual void KspSolverOrchestrationPortMessage(IMessage message) { }
    338328
    339329    private void KspSolverEvaluationPortMessage(IMessage message) { }
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.TravelingThief/3.3/TtpOrchestratorNode1.cs

    r14616 r14628  
    4343    public TtpOrchestratorNode1() : this("TtpOrchestratorNode1") { }
    4444    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);
     45      MetaSolverOrchestrationPort = CreateOrchestrationPort<MaximizationVariegationProblem<RealVectorEncoding>>(MetaSolverName + OrchestrationPortNameSuffix);
     46      MetaSolverEvaluationPort = CreateEvaluationPort<RealVector>(MetaSolverName + EvaluationPortNameSuffix, "RealVector", "Quality");
     47      TspSolverOrchestrationPort = CreateOrchestrationPort<TourProfitProblem>(TspSolverName + OrchestrationPortNameSuffix);
     48      KspSolverOrchestrationPort = CreateOrchestrationPort<BinaryKnapsackProblem>(KspSolverName + OrchestrationPortNameSuffix);
    4949    }
    5050
     
    6060      if (clearRuns) msgFlags |= OrchestrationMessage.ClearRuns;
    6161      metaMsg["OrchestrationMessage"] = new EnumValue<OrchestrationMessage>(msgFlags);
    62       var problem = new VariegationProblem();
     62      var problem = new MaximizationVariegationProblem<RealVectorEncoding>();
    6363      problem.Encoding.Length = KspParameter.Value.Length;
    6464      problem.Encoding.Bounds = new DoubleMatrix(new[,] { { -1.0, 1.0 } });
     
    8181      cts.Token.ThrowIfCancellationRequested();
    8282
     83      var kspResults = (ResultCollection)kspMsg["Results"];
    8384      var bestKspSolution = (BinaryVector)kspResults["Best Solution"].Value.Clone();
    8485      var kspCapacity = (IntValue)KspParameter.Value.KnapsackCapacity.Clone();
     
    106107      cts.Token.ThrowIfCancellationRequested();
    107108
     109      var tspResults = (ResultCollection)tspMsg["Results"];
    108110      var bestTspSolution = (Permutation)tspResults["Best TSP Solution"].Value.Clone();
    109111      var coordinates = (DoubleMatrix)TspParameter.Value.Coordinates.Clone();
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.TravelingThief/3.3/TtpOrchestratorNode2.cs

    r14616 r14628  
    4242    public TtpOrchestratorNode2() : this("TtpOrchestratorNode2") { }
    4343    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);
     44      MetaSolverOrchestrationPort = CreateOrchestrationPort<MaximizationVariegationProblem<RealVectorEncoding>>(MetaSolverName + OrchestrationPortNameSuffix);
     45      MetaSolverEvaluationPort = CreateEvaluationPort<RealVector>(MetaSolverName + EvaluationPortNameSuffix, "RealVector", "Quality");
     46      TspSolverOrchestrationPort = CreateOrchestrationPort<TravelingSalesmanProblem>(TspSolverName + OrchestrationPortNameSuffix);
     47      KspSolverOrchestrationPort = CreateOrchestrationPort<LootProfitProblem>(KspSolverName + OrchestrationPortNameSuffix);
    4848    }
    4949
     
    5959      if (clearRuns) msgFlags |= OrchestrationMessage.ClearRuns;
    6060      metaMsg["OrchestrationMessage"] = new EnumValue<OrchestrationMessage>(msgFlags);
    61       var problem = new VariegationProblem();
     61      var problem = new MaximizationVariegationProblem<RealVectorEncoding>();
    6262      problem.Encoding.Length = TspParameter.Value.Coordinates.Rows * 2;
    6363      problem.Encoding.Bounds = new DoubleMatrix(new[,] { { -1.0, 1.0 } });
     
    8282      cts.Token.ThrowIfCancellationRequested();
    8383
     84      var tspResults = (ResultCollection)tspMsg["Results"];
    8485      var bestTspSolution = (PathTSPTour)tspResults["Best TSP Solution"].Value.Clone();
    8586      var coordinates = (DoubleMatrix)TspParameter.Value.Coordinates.Clone();
     
    103104      cts.Token.ThrowIfCancellationRequested();
    104105
     106      var kspResults = (ResultCollection)kspMsg["Results"];
    105107      var bestKspSolution = (BinaryVector)kspResults["Best Solution"].Value.Clone();
    106108      var kspCapacity = (IntValue)KspParameter.Value.KnapsackCapacity.Clone();
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.TravelingThief/3.3/TtpOrchestratorNode3.cs

    r14616 r14628  
    4343    public TtpOrchestratorNode3() : this("TtpOrchestratorNode3") { }
    4444    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);
     45      MetaSolverOrchestrationPort = CreateOrchestrationPort<MaximizationVariegationProblem<RealVectorEncoding>>(MetaSolverName + OrchestrationPortNameSuffix);
     46      MetaSolverEvaluationPort = CreateEvaluationPort<RealVector>(MetaSolverName + EvaluationPortNameSuffix, "RealVector", "Quality");
     47      TspSolverOrchestrationPort = CreateOrchestrationPort<TravelingSalesmanProblem>(TspSolverName + OrchestrationPortNameSuffix);
     48      KspSolverOrchestrationPort = CreateOrchestrationPort<BinaryKnapsackProblem>(KspSolverName + OrchestrationPortNameSuffix);
    4949    }
    5050
     
    6060      if (clearRuns) msgFlags |= OrchestrationMessage.ClearRuns;
    6161      metaMsg["OrchestrationMessage"] = new EnumValue<OrchestrationMessage>(msgFlags);
    62       var problem = new VariegationProblem();
     62      var problem = new MaximizationVariegationProblem<RealVectorEncoding>();
    6363      problem.Encoding.Length = KspParameter.Value.Length + TspParameter.Value.Coordinates.Rows * 2;
    6464      problem.Encoding.Bounds = new DoubleMatrix(new[,] { { -1.0, 1.0 } });
     
    8484      cts.Token.ThrowIfCancellationRequested();
    8585
     86      var kspResults = (ResultCollection)kspMsg["Results"];
    8687      var bestKspSolution = (BinaryVector)kspResults["Best Solution"].Value.Clone();
    8788      var kspCapacity = (IntValue)KspParameter.Value.KnapsackCapacity.Clone();
     
    115116      cts.Token.ThrowIfCancellationRequested();
    116117
     118      var tspResults = (ResultCollection)tspMsg["Results"];
    117119      var bestTspSolution = (Permutation)tspResults["Best TSP Solution"].Value.Clone();
    118120      var coordinates = (DoubleMatrix)TspParameter.Value.Coordinates.Clone();
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization/3.3/HeuristicLab.Networks.IntegratedOptimization-3.3.csproj

    r14619 r14628  
    131131  <ItemGroup>
    132132    <Compile Include="IOrchestratorNode.cs" />
     133    <Compile Include="MaximizationVariegationProblem.cs" />
     134    <Compile Include="MinimizationVariegationProblem.cs" />
    133135    <Compile Include="OrchestratedAlgorithmNode.cs" />
    134136    <Compile Include="OrchestrationMessage.cs" />
    135137    <Compile Include="OrchestratorNode.cs" />
    136     <Compile Include="VariegationProblem.cs" />
    137138    <None Include="Plugin.cs.frame" />
    138139    <None Include="Properties\AssemblyInfo.cs.frame" />
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization/3.3/OrchestratedAlgorithmNode.cs

    r14624 r14628  
    6565    [StorableConstructor]
    6666    protected OrchestratedAlgorithmNode(bool deserializing) : base(deserializing) { }
    67     protected OrchestratedAlgorithmNode(OrchestratedAlgorithmNode original, Cloner cloner)
    68       : base(original, cloner) {
     67    protected OrchestratedAlgorithmNode(OrchestratedAlgorithmNode original, Cloner cloner) : base(original, cloner) {
    6968      EvalHook = cloner.Clone(original.EvalHook);
    7069      RegisterEvents();
    7170    }
    7271    public OrchestratedAlgorithmNode() : this("OrchestratedAlgorithmNode") { }
    73     public OrchestratedAlgorithmNode(string name)
    74       : base(name) {
     72    public OrchestratedAlgorithmNode(string name) : base(name) {
    7573      var orchestrationPort = new MessagePort(OrchestrationPortName);
    7674      Ports.Add(orchestrationPort);
     
    9795    #region Port Events
    9896    private void OrchestrationPort_MessageReceived(object sender, EventArgs<IMessage, CancellationToken> e) {
    99       var message = e.Value;
    100       var orchestrationMessage = ((EnumValue<OrchestrationMessage>)message["OrchestrationMessage"]).Value;
     97      var requestMessage = e.Value;
     98      var messageFlags = ((EnumValue<OrchestrationMessage>)requestMessage["OrchestrationMessage"]).Value;
    10199
    102100      #region Prepare
    103       if (orchestrationMessage.HasFlag(OrchestrationMessage.Prepare)) {
     101      if (messageFlags.HasFlag(OrchestrationMessage.Prepare)) {
    104102        switch (Algorithm.ExecutionState) {
    105103          case ExecutionState.Prepared:
     
    110108              var prob = (IHeuristicOptimizationProblem)problemMsgVal.Value.Clone();
    111109
    112               if (orchestrationMessage.HasFlag(OrchestrationMessage.SetEvalHook)) {
     110              if (messageFlags.HasFlag(OrchestrationMessage.SetEvalHook)) {
    113111                var instEval = prob.Evaluator as InstrumentedOperator;
    114112                if (instEval != null && EvalHook != null) instEval.AfterExecutionOperators.Add(EvalHook);
     
    140138              }
    141139
    142               Algorithm.Prepare(orchestrationMessage.HasFlag(OrchestrationMessage.ClearRuns));
     140              Algorithm.Prepare(messageFlags.HasFlag(OrchestrationMessage.ClearRuns));
    143141            }
    144142            break;
     
    148146
    149147      #region Start
    150       if (orchestrationMessage.HasFlag(OrchestrationMessage.Start)) {
     148      if (messageFlags.HasFlag(OrchestrationMessage.Start)) {
    151149        switch (Algorithm.ExecutionState) {
    152150          case ExecutionState.Prepared:
     
    175173
    176174            if (sendResultMessage) {
    177               message["Results"] = (ResultCollection)Algorithm.Results.Clone();
    178               var msg = OrchestrationPort.PrepareMessage();
    179               msg["Results"] = (ResultCollection)Algorithm.Results.Clone();
    180               OrchestrationPort.SendMessage(msg);
     175              requestMessage["Results"] = (ResultCollection)Algorithm.Results.Clone();
     176              var responseMessage = OrchestrationPort.PrepareMessage();
     177              responseMessage["Results"] = (ResultCollection)Algorithm.Results.Clone();
     178              OrchestrationPort.SendMessage(responseMessage);
    181179            } else sendResultMessage = true;
    182180            break;
     
    186184
    187185      #region Pause
    188       if (orchestrationMessage.HasFlag(OrchestrationMessage.Pause)) {
     186      if (messageFlags.HasFlag(OrchestrationMessage.Pause)) {
    189187        if (Algorithm.ExecutionState == ExecutionState.Started) {
    190188          sendResultMessage = false;
    191189          try {
    192190            Algorithm.Pause();
    193           }
    194           catch (InvalidOperationException) {
     191          } catch (InvalidOperationException) {
    195192            // ExecutionState might have changed since we accepted the message
    196193          }
     
    200197
    201198      #region Stop
    202       if (orchestrationMessage.HasFlag(OrchestrationMessage.Stop)) {
     199      if (messageFlags.HasFlag(OrchestrationMessage.Stop)) {
    203200        switch (Algorithm.ExecutionState) {
    204201          case ExecutionState.Started:
     
    206203            try {
    207204              Algorithm.Stop();
    208             }
    209             catch (InvalidOperationException) {
     205            } catch (InvalidOperationException) {
    210206              // ExecutionState might have changed since we accepted the message
    211             }
    212             catch (NullReferenceException) {
     207            } catch (NullReferenceException) {
    213208              // BasicAlgorithm might have stopped since we accepted the message
    214209              // CancellationTokenSource is null in this case
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization/3.3/OrchestratorNode.cs

    r14624 r14628  
    2828using HeuristicLab.Data;
    2929using HeuristicLab.Optimization;
    30 using HeuristicLab.Parameters;
    3130using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3231
     
    3534  [StorableClass]
    3635  public abstract class OrchestratorNode : Node, IOrchestratorNode {
    37     //TODO remove suffixes
    38     #region Constants
    39     protected const string OrchestrationMessageParameterName = "OrchestrationMessage";
    40     protected const string OrchestrationPortNameSuffix = "";
    41     protected const string EvaluationPortNameSuffix = "";
    42     #endregion
    43 
    4436    [Storable]
    4537    private ParameterCollection parameters;
     
    6355    [StorableConstructor]
    6456    protected OrchestratorNode(bool deserializing) : base(deserializing) { }
    65     protected OrchestratorNode(OrchestratorNode original, Cloner cloner)
    66       : base(original, cloner) {
     57    protected OrchestratorNode(OrchestratorNode original, Cloner cloner) : base(original, cloner) {
    6758      results = cloner.Clone(original.results);
    6859      parameters = cloner.Clone(original.parameters);
     
    7162    }
    7263
    73     protected OrchestratorNode()
    74       : base("OrchestratorNode") {
     64    protected OrchestratorNode() : base("OrchestratorNode") {
    7565      results = new ResultCollection();
    7666      parameters = new ParameterCollection();
    77       Parameters.Add(new ValueParameter<EnumValue<OrchestrationMessage>>("OrchestrationMessage", new EnumValue<OrchestrationMessage>()));
    7867      readOnlyParameters = null;
    7968    }
    80     protected OrchestratorNode(string name)
    81       : base(name) {
     69    protected OrchestratorNode(string name) : base(name) {
    8270      results = new ResultCollection();
    8371      parameters = new ParameterCollection();
    84       Parameters.Add(new ValueParameter<EnumValue<OrchestrationMessage>>("OrchestrationMessage", new EnumValue<OrchestrationMessage>()));
    8572      readOnlyParameters = null;
    8673    }
    87     protected OrchestratorNode(string name, string description)
    88       : base(name, description) {
     74    protected OrchestratorNode(string name, string description) : base(name, description) {
    8975      results = new ResultCollection();
    9076      parameters = new ParameterCollection();
    91       Parameters.Add(new ValueParameter<EnumValue<OrchestrationMessage>>("OrchestrationMessage", new EnumValue<OrchestrationMessage>()));
    9277      readOnlyParameters = null;
    9378    }
     
    10287    }
    10388
    104     protected IMessagePort CreateOrchestrationPort<T>(string solverName) where T : class, IProblem {
    105       var orchestrationPort = new MessagePort(solverName + OrchestrationPortNameSuffix);
     89    protected IMessagePort CreateOrchestrationPort<T>(string portName) where T : class, IProblem {
     90      var orchestrationPort = new MessagePort(portName);
    10691      orchestrationPort.Parameters.Add(new PortParameter<EnumValue<OrchestrationMessage>>("OrchestrationMessage") {
    10792        Type = PortParameterType.Output
     
    116101    }
    117102
    118     protected IMessagePort CreateEvaluationPort<T>(string solverName, string solutionName, string qualityName) where T : class, IItem {
    119       var evaluationPort = new MessagePort(solverName + EvaluationPortNameSuffix);
     103    protected IMessagePort CreateEvaluationPort<T>(string portName, string solutionName, string qualityName) where T : class, IItem {
     104      var evaluationPort = new MessagePort(portName);
    120105      evaluationPort.Parameters.Add(new PortParameter<T>(solutionName) {
    121106        Type = PortParameterType.Input
Note: See TracChangeset for help on using the changeset viewer.