Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2205_OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.SurrogateModeling/3.3/SurrogateModelingNetwork.cs @ 17701

Last change on this file since 17701 was 15896, checked in by jkarder, 7 years ago

#2205: added surrogate modeling network

File size: 6.6 KB
Line 
1using System;
2using HeuristicLab.Algorithms.ALPS;
3using HeuristicLab.Algorithms.DataAnalysis;
4using HeuristicLab.Algorithms.RandomSearch;
5using HeuristicLab.Common;
6using HeuristicLab.Core;
7using HeuristicLab.Core.Networks;
8using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
9using HeuristicLab.Problems.DataAnalysis;
10
11namespace HeuristicLab.Networks.IntegratedOptimization.SurrogateModeling {
12  [Item("Surrogate Modeling Network", "")]
13  [Creatable("Optimization Networks")]
14  [StorableClass]
15  public sealed class SurrogateModelingNetwork : Network {
16    #region Nodes
17    [Storable]
18    private SurrogateModelingOrchestrator orchestrator;
19    private SurrogateModelingOrchestrator Orchestrator {
20      get { return orchestrator; }
21      set {
22        if (orchestrator != null)
23          throw new InvalidOperationException("Orchestrator has already been initialized.");
24        orchestrator = value;
25      }
26    }
27
28    [Storable]
29    private FullEvaluatorNode fullEvaluatorNode;
30    private FullEvaluatorNode FullEvaluatorNode {
31      get { return fullEvaluatorNode; }
32      set {
33        if (fullEvaluatorNode != null)
34          throw new InvalidOperationException("FullEvaluatorNode has already been initialized.");
35        fullEvaluatorNode = value;
36      }
37    }
38
39    [Storable]
40    private OrchestratedAlgorithmNode pointGeneratorNode;
41    private OrchestratedAlgorithmNode PointGeneratorNode {
42      get { return pointGeneratorNode; }
43      set {
44        if (pointGeneratorNode != null)
45          throw new InvalidOperationException("PointGeneratorNode has already been initialized.");
46        pointGeneratorNode = value;
47      }
48    }
49
50    [Storable]
51    private OrchestratedAlgorithmNode modelBuilderNode;
52    private OrchestratedAlgorithmNode ModelBuilderNode {
53      get { return modelBuilderNode; }
54      set {
55        if (modelBuilderNode != null)
56          throw new InvalidOperationException("ModelBuilderNode has already been initialized.");
57        modelBuilderNode = value;
58      }
59    }
60
61    [Storable]
62    private OrchestratedAlgorithmNode assistedOptimizerNode;
63    private OrchestratedAlgorithmNode AssistedOptimizerNode {
64      get { return assistedOptimizerNode; }
65      set {
66        if (assistedOptimizerNode != null)
67          throw new InvalidOperationException("AssistedOptimizerNode has already been initialized.");
68        assistedOptimizerNode = value;
69      }
70    }
71    #endregion
72
73    #region Constructors & Cloning
74    [StorableConstructor]
75    private SurrogateModelingNetwork(bool deserializing) : base(deserializing) { }
76    private SurrogateModelingNetwork(SurrogateModelingNetwork original, Cloner cloner) : base(original, cloner) { }
77    public SurrogateModelingNetwork() : this("Surrogate Modeling Network") { }
78    public SurrogateModelingNetwork(string name) : this(name, "") { }
79    public SurrogateModelingNetwork(string name, string description) : base(name, description) {
80      ConfigureOrchestrator();
81      ConfigureFullEvaluator();
82      ConfigurePointGenerator();
83      ConfigureModelBuilder();
84      ConfigureAssistedOptimizer();
85
86      Orchestrator.Prepare();
87    }
88
89    public override IDeepCloneable Clone(Cloner cloner) {
90      return new SurrogateModelingNetwork(this, cloner);
91    }
92    #endregion
93
94    private void ConfigureOrchestrator() {
95      Orchestrator = new SurrogateModelingOrchestrator();
96      Nodes.Add(Orchestrator);
97    }
98
99    private void ConfigureFullEvaluator() {
100      FullEvaluatorNode = new FullEvaluatorNode();
101      Nodes.Add(FullEvaluatorNode);
102
103      Orchestrator.FullEvaluatorOrchPort.ConnectedPort = FullEvaluatorNode.OrchestrationPort;
104      Orchestrator.FullEvaluatorExploitationEvalPort.ConnectedPort = FullEvaluatorNode.ExploitationFullEvalRequestPort;
105      Orchestrator.FullEvaluatorExplorationEvalPort.ConnectedPort = FullEvaluatorNode.ExplorationFullEvalRequestPort;
106      Orchestrator.FullEvaluatorUpdatePort.ConnectedPort = FullEvaluatorNode.UpdateRegressionSolutionPort;
107      FullEvaluatorNode.EvaluationPort.CloneParametersFromPort(Orchestrator.FullEvaluatorEvalPort);
108      FullEvaluatorNode.EvaluationPort.ConnectedPort = Orchestrator.FullEvaluatorEvalPort;
109    }
110
111    private void ConfigurePointGenerator() {
112      PointGeneratorNode = new OrchestratedAlgorithmNode("Point Generator") {
113        Algorithm = new RandomSearchAlgorithm {
114          MaximumEvaluatedSolutions = int.MaxValue
115        }
116      };
117      Nodes.Add(PointGeneratorNode);
118
119      Orchestrator.PointGeneratorOrchPort.ConnectedPort = PointGeneratorNode.OrchestrationPort;
120      PointGeneratorNode.EvaluationPort.CloneParametersFromPort(Orchestrator.PointGeneratorEvalPort);
121      PointGeneratorNode.EvaluationPort.ConnectedPort = Orchestrator.PointGeneratorEvalPort;
122    }
123
124    private void ConfigureModelBuilder() {
125      ModelBuilderNode = new OrchestratedAlgorithmNode("Model Builder") {
126        Algorithm = new GaussianProcessRegression()
127      };
128      var updatePort = new ConfigurationPort("Update ProblemData") {
129        Parameters = {
130          new PortParameter<IRegressionProblemData>("ProblemData") {
131            Type = PortParameterType.Input
132          }
133        }
134      };
135      ModelBuilderNode.Ports.Add(updatePort);
136      Nodes.Add(ModelBuilderNode);
137
138      Orchestrator.ModelBuilderOrchPort.ConnectedPort = ModelBuilderNode.OrchestrationPort;
139      Orchestrator.ModelBuilderUpdatePort.ConnectedPort = updatePort;
140      ModelBuilderNode.EvaluationPort.CloneParametersFromPort(Orchestrator.ModelBuilderEvalPort);
141      ModelBuilderNode.EvaluationPort.ConnectedPort = Orchestrator.ModelBuilderEvalPort;
142    }
143
144    private void ConfigureAssistedOptimizer() {
145      AssistedOptimizerNode = new OrchestratedAlgorithmNode("Assisted Optimizer") {
146        Algorithm = new AlpsGeneticAlgorithm {
147          MaximumGenerations = 250,
148          ReevaluteElites = true
149        }
150      };
151      var updatePort = new ConfigurationPort("Update RegressionSolution") {
152        Parameters = {
153          new PortParameter<IRegressionSolution>("RegressionSolution") {
154            Type = PortParameterType.Input
155          }
156        }
157      };
158      AssistedOptimizerNode.Ports.Add(updatePort);
159      Nodes.Add(AssistedOptimizerNode);
160
161      Orchestrator.AssistedOptimizerOrchPort.ConnectedPort = AssistedOptimizerNode.OrchestrationPort;
162      Orchestrator.AssistedOptimizerUpdatePort.ConnectedPort = updatePort;
163      AssistedOptimizerNode.EvaluationPort.CloneParametersFromPort(Orchestrator.AssistedOptimizerEvalPort);
164      AssistedOptimizerNode.EvaluationPort.ConnectedPort = Orchestrator.AssistedOptimizerEvalPort;
165    }
166  }
167}
Note: See TracBrowser for help on using the repository browser.