[3098] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[12009] | 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3098] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
[4068] | 25 | using HeuristicLab.Analysis;
|
---|
[3376] | 26 | using HeuristicLab.Common;
|
---|
[3098] | 27 | using HeuristicLab.Core;
|
---|
| 28 | using HeuristicLab.Data;
|
---|
[5356] | 29 | using HeuristicLab.Operators;
|
---|
[3098] | 30 | using HeuristicLab.Optimization;
|
---|
| 31 | using HeuristicLab.Optimization.Operators;
|
---|
| 32 | using HeuristicLab.Parameters;
|
---|
| 33 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 34 | using HeuristicLab.PluginInfrastructure;
|
---|
[3368] | 35 | using HeuristicLab.Random;
|
---|
[3098] | 36 |
|
---|
| 37 | namespace HeuristicLab.Algorithms.SimulatedAnnealing {
|
---|
| 38 | [Item("Simulated Annealing", "A simulated annealing algorithm.")]
|
---|
[12708] | 39 | [Creatable(CreatableAttribute.Categories.SingleSolutionAlgorithms, Priority = 140)]
|
---|
[3201] | 40 | [StorableClass]
|
---|
[5809] | 41 | public sealed class SimulatedAnnealing : HeuristicOptimizationEngineAlgorithm, IStorableContent {
|
---|
[4437] | 42 | public string Filename { get; set; }
|
---|
| 43 |
|
---|
[3098] | 44 | #region Problem Properties
|
---|
| 45 | public override Type ProblemType {
|
---|
[5809] | 46 | get { return typeof(ISingleObjectiveHeuristicOptimizationProblem); }
|
---|
[3098] | 47 | }
|
---|
[5809] | 48 | public new ISingleObjectiveHeuristicOptimizationProblem Problem {
|
---|
| 49 | get { return (ISingleObjectiveHeuristicOptimizationProblem)base.Problem; }
|
---|
[3098] | 50 | set { base.Problem = value; }
|
---|
| 51 | }
|
---|
| 52 | #endregion
|
---|
| 53 |
|
---|
| 54 | #region Parameter Properties
|
---|
| 55 | private ValueParameter<IntValue> SeedParameter {
|
---|
| 56 | get { return (ValueParameter<IntValue>)Parameters["Seed"]; }
|
---|
| 57 | }
|
---|
| 58 | private ValueParameter<BoolValue> SetSeedRandomlyParameter {
|
---|
| 59 | get { return (ValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
|
---|
| 60 | }
|
---|
[8121] | 61 | public IConstrainedValueParameter<IMultiMoveGenerator> MoveGeneratorParameter {
|
---|
| 62 | get { return (IConstrainedValueParameter<IMultiMoveGenerator>)Parameters["MoveGenerator"]; }
|
---|
[3098] | 63 | }
|
---|
[8121] | 64 | public IConstrainedValueParameter<IMoveMaker> MoveMakerParameter {
|
---|
| 65 | get { return (IConstrainedValueParameter<IMoveMaker>)Parameters["MoveMaker"]; }
|
---|
[3098] | 66 | }
|
---|
[8121] | 67 | public IConstrainedValueParameter<ISingleObjectiveMoveEvaluator> MoveEvaluatorParameter {
|
---|
| 68 | get { return (IConstrainedValueParameter<ISingleObjectiveMoveEvaluator>)Parameters["MoveEvaluator"]; }
|
---|
[3098] | 69 | }
|
---|
[8121] | 70 | public IConstrainedValueParameter<IDiscreteDoubleValueModifier> AnnealingOperatorParameter {
|
---|
| 71 | get { return (IConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["AnnealingOperator"]; }
|
---|
[3098] | 72 | }
|
---|
| 73 | private ValueParameter<IntValue> MaximumIterationsParameter {
|
---|
| 74 | get { return (ValueParameter<IntValue>)Parameters["MaximumIterations"]; }
|
---|
| 75 | }
|
---|
[3101] | 76 | private ValueParameter<IntValue> InnerIterationsParameter {
|
---|
| 77 | get { return (ValueParameter<IntValue>)Parameters["InnerIterations"]; }
|
---|
| 78 | }
|
---|
[3098] | 79 | private ValueParameter<DoubleValue> StartTemperatureParameter {
|
---|
| 80 | get { return (ValueParameter<DoubleValue>)Parameters["StartTemperature"]; }
|
---|
| 81 | }
|
---|
| 82 | private ValueParameter<DoubleValue> EndTemperatureParameter {
|
---|
| 83 | get { return (ValueParameter<DoubleValue>)Parameters["EndTemperature"]; }
|
---|
| 84 | }
|
---|
[3658] | 85 | private ValueParameter<MultiAnalyzer> AnalyzerParameter {
|
---|
| 86 | get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
|
---|
[3622] | 87 | }
|
---|
[3098] | 88 | #endregion
|
---|
| 89 |
|
---|
| 90 | #region Properties
|
---|
| 91 | public IntValue Seed {
|
---|
| 92 | get { return SeedParameter.Value; }
|
---|
| 93 | set { SeedParameter.Value = value; }
|
---|
| 94 | }
|
---|
| 95 | public BoolValue SetSeedRandomly {
|
---|
| 96 | get { return SetSeedRandomlyParameter.Value; }
|
---|
| 97 | set { SetSeedRandomlyParameter.Value = value; }
|
---|
| 98 | }
|
---|
[3101] | 99 | public IMultiMoveGenerator MoveGenerator {
|
---|
[3098] | 100 | get { return MoveGeneratorParameter.Value; }
|
---|
| 101 | set { MoveGeneratorParameter.Value = value; }
|
---|
| 102 | }
|
---|
| 103 | public IMoveMaker MoveMaker {
|
---|
| 104 | get { return MoveMakerParameter.Value; }
|
---|
| 105 | set { MoveMakerParameter.Value = value; }
|
---|
| 106 | }
|
---|
| 107 | public ISingleObjectiveMoveEvaluator MoveEvaluator {
|
---|
| 108 | get { return MoveEvaluatorParameter.Value; }
|
---|
| 109 | set { MoveEvaluatorParameter.Value = value; }
|
---|
| 110 | }
|
---|
[6476] | 111 | public IDiscreteDoubleValueModifier AnnealingOperator {
|
---|
| 112 | get { return AnnealingOperatorParameter.Value; }
|
---|
| 113 | set { AnnealingOperatorParameter.Value = value; }
|
---|
| 114 | }
|
---|
[3098] | 115 | public IntValue MaximumIterations {
|
---|
| 116 | get { return MaximumIterationsParameter.Value; }
|
---|
| 117 | set { MaximumIterationsParameter.Value = value; }
|
---|
| 118 | }
|
---|
[3101] | 119 | public IntValue InnerIterations {
|
---|
| 120 | get { return InnerIterationsParameter.Value; }
|
---|
| 121 | set { InnerIterationsParameter.Value = value; }
|
---|
| 122 | }
|
---|
| 123 | public DoubleValue StartTemperature {
|
---|
| 124 | get { return StartTemperatureParameter.Value; }
|
---|
| 125 | set { StartTemperatureParameter.Value = value; }
|
---|
| 126 | }
|
---|
| 127 | public DoubleValue EndTemperature {
|
---|
| 128 | get { return EndTemperatureParameter.Value; }
|
---|
| 129 | set { EndTemperatureParameter.Value = value; }
|
---|
| 130 | }
|
---|
[3658] | 131 | public MultiAnalyzer Analyzer {
|
---|
[3622] | 132 | get { return AnalyzerParameter.Value; }
|
---|
| 133 | set { AnalyzerParameter.Value = value; }
|
---|
| 134 | }
|
---|
[3098] | 135 | private RandomCreator RandomCreator {
|
---|
| 136 | get { return (RandomCreator)OperatorGraph.InitialOperator; }
|
---|
| 137 | }
|
---|
| 138 | private SolutionsCreator SolutionsCreator {
|
---|
| 139 | get { return (SolutionsCreator)RandomCreator.Successor; }
|
---|
| 140 | }
|
---|
| 141 | private SimulatedAnnealingMainLoop MainLoop {
|
---|
[5366] | 142 | get { return FindMainLoop(SolutionsCreator.Successor); }
|
---|
[3098] | 143 | }
|
---|
[3689] | 144 | [Storable]
|
---|
[3662] | 145 | private QualityAnalyzer qualityAnalyzer;
|
---|
[8016] | 146 | [Storable]
|
---|
| 147 | private SingleValueAnalyzer temperatureAnalyzer;
|
---|
[3098] | 148 | #endregion
|
---|
| 149 |
|
---|
[3622] | 150 | [StorableConstructor]
|
---|
| 151 | private SimulatedAnnealing(bool deserializing) : base(deserializing) { }
|
---|
[4722] | 152 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 153 | private void AfterDeserialization() {
|
---|
[8016] | 154 | if (temperatureAnalyzer == null) {
|
---|
| 155 | temperatureAnalyzer = new SingleValueAnalyzer();
|
---|
| 156 | temperatureAnalyzer.Name = "TemperatureAnalyzer";
|
---|
| 157 | temperatureAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
| 158 | temperatureAnalyzer.ValueParameter.ActualName = "Temperature";
|
---|
| 159 | temperatureAnalyzer.ValuesParameter.ActualName = "Temperature Chart";
|
---|
| 160 | Analyzer.Operators.Add(temperatureAnalyzer);
|
---|
| 161 | }
|
---|
[4722] | 162 | Initialize();
|
---|
| 163 | }
|
---|
| 164 | private SimulatedAnnealing(SimulatedAnnealing original, Cloner cloner)
|
---|
| 165 | : base(original, cloner) {
|
---|
| 166 | qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
|
---|
[8016] | 167 | temperatureAnalyzer = cloner.Clone(original.temperatureAnalyzer);
|
---|
[4722] | 168 | Initialize();
|
---|
| 169 | }
|
---|
| 170 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 171 | return new SimulatedAnnealing(this, cloner);
|
---|
| 172 | }
|
---|
[3098] | 173 | public SimulatedAnnealing()
|
---|
| 174 | : base() {
|
---|
| 175 | Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
|
---|
| 176 | Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
|
---|
[3101] | 177 | Parameters.Add(new ConstrainedValueParameter<IMultiMoveGenerator>("MoveGenerator", "The operator used to generate moves to the neighborhood of the current solution."));
|
---|
[3098] | 178 | Parameters.Add(new ConstrainedValueParameter<ISingleObjectiveMoveEvaluator>("MoveEvaluator", "The operator used to evaluate a move."));
|
---|
| 179 | Parameters.Add(new ConstrainedValueParameter<IMoveMaker>("MoveMaker", "The operator used to perform a move."));
|
---|
| 180 | Parameters.Add(new ConstrainedValueParameter<IDiscreteDoubleValueModifier>("AnnealingOperator", "The operator used to modify the temperature."));
|
---|
[3101] | 181 | Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(100)));
|
---|
| 182 | Parameters.Add(new ValueParameter<IntValue>("InnerIterations", "The amount of inner iterations (number of moves before temperature is adjusted again).", new IntValue(10)));
|
---|
[3098] | 183 | Parameters.Add(new ValueParameter<DoubleValue>("StartTemperature", "The initial temperature.", new DoubleValue(100)));
|
---|
| 184 | Parameters.Add(new ValueParameter<DoubleValue>("EndTemperature", "The final temperature which should be reached when iterations reaches maximum iterations.", new DoubleValue(1e-6)));
|
---|
[3658] | 185 | Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
|
---|
[4068] | 186 |
|
---|
[3098] | 187 | RandomCreator randomCreator = new RandomCreator();
|
---|
| 188 | SolutionsCreator solutionsCreator = new SolutionsCreator();
|
---|
[5356] | 189 | VariableCreator variableCreator = new VariableCreator();
|
---|
| 190 | ResultsCollector resultsCollector = new ResultsCollector();
|
---|
[3098] | 191 | SimulatedAnnealingMainLoop mainLoop = new SimulatedAnnealingMainLoop();
|
---|
| 192 | OperatorGraph.InitialOperator = randomCreator;
|
---|
| 193 |
|
---|
| 194 | randomCreator.RandomParameter.ActualName = "Random";
|
---|
| 195 | randomCreator.SeedParameter.ActualName = SeedParameter.Name;
|
---|
| 196 | randomCreator.SeedParameter.Value = null;
|
---|
| 197 | randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
|
---|
| 198 | randomCreator.SetSeedRandomlyParameter.Value = null;
|
---|
| 199 | randomCreator.Successor = solutionsCreator;
|
---|
| 200 |
|
---|
| 201 | solutionsCreator.NumberOfSolutions = new IntValue(1);
|
---|
[5356] | 202 | solutionsCreator.Successor = variableCreator;
|
---|
[3098] | 203 |
|
---|
[5356] | 204 | variableCreator.Name = "Initialize EvaluatedMoves";
|
---|
| 205 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("EvaluatedMoves", new IntValue()));
|
---|
[5753] | 206 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0)));
|
---|
[5356] | 207 | variableCreator.Successor = resultsCollector;
|
---|
| 208 |
|
---|
| 209 | resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Moves", null, "EvaluatedMoves"));
|
---|
| 210 | resultsCollector.ResultsParameter.ActualName = "Results";
|
---|
| 211 | resultsCollector.Successor = mainLoop;
|
---|
| 212 |
|
---|
[3098] | 213 | mainLoop.MoveGeneratorParameter.ActualName = MoveGeneratorParameter.Name;
|
---|
| 214 | mainLoop.MoveEvaluatorParameter.ActualName = MoveEvaluatorParameter.Name;
|
---|
| 215 | mainLoop.MoveMakerParameter.ActualName = MoveMakerParameter.Name;
|
---|
| 216 | mainLoop.AnnealingOperatorParameter.ActualName = AnnealingOperatorParameter.Name;
|
---|
| 217 | mainLoop.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name;
|
---|
[8016] | 218 | mainLoop.TemperatureParameter.ActualName = "Temperature";
|
---|
[3098] | 219 | mainLoop.StartTemperatureParameter.ActualName = StartTemperatureParameter.Name;
|
---|
| 220 | mainLoop.EndTemperatureParameter.ActualName = EndTemperatureParameter.Name;
|
---|
| 221 | mainLoop.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
|
---|
| 222 | mainLoop.ResultsParameter.ActualName = "Results";
|
---|
[3622] | 223 | mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
|
---|
[5356] | 224 | mainLoop.EvaluatedMovesParameter.ActualName = "EvaluatedMoves";
|
---|
[5753] | 225 | mainLoop.IterationsParameter.ActualName = "Iterations";
|
---|
[3098] | 226 |
|
---|
[3689] | 227 | foreach (IDiscreteDoubleValueModifier op in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name))
|
---|
| 228 | AnnealingOperatorParameter.ValidValues.Add(op);
|
---|
| 229 | ParameterizeAnnealingOperators();
|
---|
| 230 |
|
---|
| 231 | qualityAnalyzer = new QualityAnalyzer();
|
---|
[8016] | 232 | temperatureAnalyzer = new SingleValueAnalyzer();
|
---|
| 233 | temperatureAnalyzer.Name = "TemperatureAnalyzer";
|
---|
[3689] | 234 | ParameterizeAnalyzers();
|
---|
| 235 | UpdateAnalyzers();
|
---|
| 236 |
|
---|
[3098] | 237 | Initialize();
|
---|
| 238 | }
|
---|
| 239 |
|
---|
[3275] | 240 | public override void Prepare() {
|
---|
[3265] | 241 | if (Problem != null && MoveGenerator != null && MoveMaker != null && MoveEvaluator != null)
|
---|
[3275] | 242 | base.Prepare();
|
---|
[3189] | 243 | }
|
---|
| 244 |
|
---|
[3098] | 245 | #region Events
|
---|
| 246 | protected override void OnProblemChanged() {
|
---|
| 247 | ParameterizeStochasticOperator(Problem.SolutionCreator);
|
---|
| 248 | ParameterizeStochasticOperator(Problem.Evaluator);
|
---|
[7999] | 249 | foreach (IOperator op in Problem.Operators.OfType<IOperator>()) ParameterizeStochasticOperator(op);
|
---|
[3098] | 250 | foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
|
---|
| 251 | op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
|
---|
| 252 | }
|
---|
| 253 | ParameterizeSolutionsCreator();
|
---|
| 254 | ParameterizeMainLoop();
|
---|
[3187] | 255 | UpdateMoveGenerator();
|
---|
| 256 | UpdateMoveParameters();
|
---|
[3750] | 257 | UpdateAnalyzers();
|
---|
[3101] | 258 | ParameterizeMoveEvaluators();
|
---|
| 259 | ParameterizeMoveMakers();
|
---|
| 260 | ParameterizeMoveGenerators();
|
---|
[3622] | 261 | ParameterizeAnalyzers();
|
---|
[3750] | 262 | ParameterizeIterationBasedOperators();
|
---|
[3098] | 263 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
| 264 | base.OnProblemChanged();
|
---|
| 265 | }
|
---|
| 266 | protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
|
---|
| 267 | ParameterizeStochasticOperator(Problem.SolutionCreator);
|
---|
| 268 | ParameterizeSolutionsCreator();
|
---|
| 269 | base.Problem_SolutionCreatorChanged(sender, e);
|
---|
| 270 | }
|
---|
| 271 | protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
|
---|
| 272 | ParameterizeStochasticOperator(Problem.Evaluator);
|
---|
| 273 | ParameterizeSolutionsCreator();
|
---|
| 274 | ParameterizeMainLoop();
|
---|
[3101] | 275 | ParameterizeMoveEvaluators();
|
---|
| 276 | ParameterizeMoveMakers();
|
---|
[3622] | 277 | ParameterizeAnalyzers();
|
---|
[3098] | 278 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
| 279 | base.Problem_EvaluatorChanged(sender, e);
|
---|
| 280 | }
|
---|
| 281 | protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
|
---|
[7999] | 282 | foreach (IOperator op in Problem.Operators.OfType<IOperator>()) ParameterizeStochasticOperator(op);
|
---|
[3098] | 283 | // This may seem pointless, but some operators already have the eventhandler registered, others don't
|
---|
| 284 | // FIXME: Is there another way to solve this problem?
|
---|
| 285 | foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
|
---|
| 286 | op.MoveQualityParameter.ActualNameChanged -= new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
|
---|
| 287 | op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
|
---|
| 288 | }
|
---|
| 289 | UpdateMoveGenerator();
|
---|
[3187] | 290 | UpdateMoveParameters();
|
---|
[3622] | 291 | UpdateAnalyzers();
|
---|
[3098] | 292 | ParameterizeMainLoop();
|
---|
[3101] | 293 | ParameterizeMoveEvaluators();
|
---|
| 294 | ParameterizeMoveMakers();
|
---|
| 295 | ParameterizeMoveGenerators();
|
---|
[3750] | 296 | ParameterizeIterationBasedOperators();
|
---|
[3098] | 297 | base.Problem_OperatorsChanged(sender, e);
|
---|
| 298 | }
|
---|
| 299 | private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
| 300 | ParameterizeMainLoop();
|
---|
[3101] | 301 | ParameterizeMoveEvaluators();
|
---|
| 302 | ParameterizeMoveMakers();
|
---|
[3622] | 303 | ParameterizeAnalyzers();
|
---|
[3098] | 304 | }
|
---|
| 305 | private void MoveGeneratorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 306 | UpdateMoveParameters();
|
---|
| 307 | }
|
---|
| 308 | private void MoveEvaluatorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 309 | ParameterizeMainLoop();
|
---|
[3101] | 310 | ParameterizeMoveEvaluators();
|
---|
| 311 | ParameterizeMoveMakers();
|
---|
[3098] | 312 | }
|
---|
| 313 | private void MoveEvaluator_MoveQualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
| 314 | ParameterizeMainLoop();
|
---|
[3101] | 315 | ParameterizeMoveEvaluators();
|
---|
| 316 | ParameterizeMoveMakers();
|
---|
[3098] | 317 | }
|
---|
| 318 | #endregion
|
---|
| 319 |
|
---|
| 320 | #region Helpers
|
---|
| 321 | private void Initialize() {
|
---|
| 322 | if (Problem != null) {
|
---|
| 323 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
| 324 | foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
|
---|
| 325 | op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
|
---|
| 326 | }
|
---|
| 327 | }
|
---|
| 328 | MoveGeneratorParameter.ValueChanged += new EventHandler(MoveGeneratorParameter_ValueChanged);
|
---|
| 329 | MoveEvaluatorParameter.ValueChanged += new EventHandler(MoveEvaluatorParameter_ValueChanged);
|
---|
| 330 | }
|
---|
| 331 | private void UpdateMoveGenerator() {
|
---|
[3101] | 332 | IMultiMoveGenerator oldMoveGenerator = MoveGenerator;
|
---|
[7517] | 333 | IMultiMoveGenerator defaultMoveGenerator = Problem.Operators.OfType<IMultiMoveGenerator>().FirstOrDefault();
|
---|
[3098] | 334 | MoveGeneratorParameter.ValidValues.Clear();
|
---|
| 335 | if (Problem != null) {
|
---|
[3101] | 336 | foreach (IMultiMoveGenerator generator in Problem.Operators.OfType<IMultiMoveGenerator>().OrderBy(x => x.Name))
|
---|
[3098] | 337 | MoveGeneratorParameter.ValidValues.Add(generator);
|
---|
| 338 | }
|
---|
| 339 | if (oldMoveGenerator != null) {
|
---|
[3101] | 340 | IMultiMoveGenerator newMoveGenerator = MoveGeneratorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveGenerator.GetType());
|
---|
[3098] | 341 | if (newMoveGenerator != null) MoveGenerator = newMoveGenerator;
|
---|
[7517] | 342 | else oldMoveGenerator = null;
|
---|
[3098] | 343 | }
|
---|
[7517] | 344 | if (oldMoveGenerator == null && defaultMoveGenerator != null)
|
---|
| 345 | MoveGenerator = defaultMoveGenerator;
|
---|
[3098] | 346 | if (MoveGenerator == null) {
|
---|
| 347 | ClearMoveParameters();
|
---|
| 348 | }
|
---|
| 349 | }
|
---|
[3622] | 350 | private void ParameterizeAnalyzers() {
|
---|
| 351 | qualityAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
| 352 | if (Problem != null) {
|
---|
| 353 | qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
[6053] | 354 | qualityAnalyzer.MaximizationParameter.Hidden = true;
|
---|
[3622] | 355 | qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
[3662] | 356 | qualityAnalyzer.QualityParameter.Depth = 0;
|
---|
[6053] | 357 | qualityAnalyzer.QualityParameter.Hidden = true;
|
---|
[3622] | 358 | qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
|
---|
[6053] | 359 | qualityAnalyzer.BestKnownQualityParameter.Hidden = true;
|
---|
| 360 | } else {
|
---|
| 361 | qualityAnalyzer.MaximizationParameter.Hidden = false;
|
---|
| 362 | qualityAnalyzer.QualityParameter.Hidden = false;
|
---|
| 363 | qualityAnalyzer.BestKnownQualityParameter.Hidden = false;
|
---|
[8016] | 364 | temperatureAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
| 365 | temperatureAnalyzer.ValueParameter.ActualName = "Temperature";
|
---|
| 366 | temperatureAnalyzer.ValuesParameter.ActualName = "Temperature Chart";
|
---|
[3622] | 367 | }
|
---|
| 368 | }
|
---|
[3098] | 369 | private void UpdateMoveParameters() {
|
---|
| 370 | IMoveMaker oldMoveMaker = MoveMaker;
|
---|
| 371 | ISingleObjectiveMoveEvaluator oldMoveEvaluator = MoveEvaluator;
|
---|
| 372 | ClearMoveParameters();
|
---|
[7517] | 373 |
|
---|
[3131] | 374 | if (MoveGenerator != null) {
|
---|
| 375 | List<Type> moveTypes = MoveGenerator.GetType().GetInterfaces().Where(x => typeof(IMoveOperator).IsAssignableFrom(x)).ToList();
|
---|
| 376 | foreach (Type type in moveTypes.ToList()) {
|
---|
| 377 | if (moveTypes.Any(t => t != type && type.IsAssignableFrom(t)))
|
---|
| 378 | moveTypes.Remove(type);
|
---|
| 379 | }
|
---|
[7517] | 380 | var operators = Problem.Operators.Where(op => moveTypes.Any(m => m.IsInstanceOfType(op))).ToList();
|
---|
| 381 | IMoveMaker defaultMoveMaker = operators.OfType<IMoveMaker>().FirstOrDefault();
|
---|
| 382 | ISingleObjectiveMoveEvaluator defaultMoveEvaluator = operators.OfType<ISingleObjectiveMoveEvaluator>().FirstOrDefault();
|
---|
| 383 |
|
---|
| 384 | foreach (IMoveMaker moveMaker in operators.OfType<IMoveMaker>().OrderBy(op => op.Name))
|
---|
| 385 | MoveMakerParameter.ValidValues.Add(moveMaker);
|
---|
| 386 | foreach (ISingleObjectiveMoveEvaluator moveEvaluator in operators.OfType<ISingleObjectiveMoveEvaluator>().OrderBy(op => op.Name))
|
---|
| 387 | MoveEvaluatorParameter.ValidValues.Add(moveEvaluator);
|
---|
| 388 |
|
---|
[3131] | 389 | if (oldMoveMaker != null) {
|
---|
| 390 | IMoveMaker mm = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());
|
---|
| 391 | if (mm != null) MoveMaker = mm;
|
---|
[7517] | 392 | else oldMoveMaker = null;
|
---|
[3131] | 393 | }
|
---|
[7517] | 394 | if (oldMoveMaker == null && defaultMoveMaker != null)
|
---|
| 395 | MoveMaker = defaultMoveMaker;
|
---|
| 396 |
|
---|
[3131] | 397 | if (oldMoveEvaluator != null) {
|
---|
| 398 | ISingleObjectiveMoveEvaluator me = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());
|
---|
| 399 | if (me != null) MoveEvaluator = me;
|
---|
[7517] | 400 | else oldMoveEvaluator = null;
|
---|
[3131] | 401 | }
|
---|
[7517] | 402 | if (oldMoveEvaluator == null & defaultMoveEvaluator != null)
|
---|
| 403 | MoveEvaluator = defaultMoveEvaluator;
|
---|
[3098] | 404 | }
|
---|
| 405 | }
|
---|
| 406 | private void ClearMoveParameters() {
|
---|
| 407 | MoveMakerParameter.ValidValues.Clear();
|
---|
| 408 | MoveEvaluatorParameter.ValidValues.Clear();
|
---|
| 409 | }
|
---|
| 410 | private void ParameterizeSolutionsCreator() {
|
---|
| 411 | SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
|
---|
| 412 | SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
|
---|
| 413 | }
|
---|
| 414 | private void ParameterizeMainLoop() {
|
---|
[6053] | 415 | if (Problem != null) {
|
---|
| 416 | MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
|
---|
| 417 | MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
| 418 | MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
| 419 | }
|
---|
[3098] | 420 | if (MoveEvaluator != null)
|
---|
| 421 | MainLoop.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
|
---|
| 422 | }
|
---|
| 423 | private void ParameterizeStochasticOperator(IOperator op) {
|
---|
[6053] | 424 | if (op is IStochasticOperator) {
|
---|
| 425 | IStochasticOperator stOp = (IStochasticOperator)op;
|
---|
| 426 | stOp.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
|
---|
| 427 | stOp.RandomParameter.Hidden = true;
|
---|
| 428 | }
|
---|
[3098] | 429 | }
|
---|
[3101] | 430 | private void ParameterizeMoveEvaluators() {
|
---|
[3098] | 431 | foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
|
---|
| 432 | op.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
[6053] | 433 | op.QualityParameter.Hidden = true;
|
---|
[3098] | 434 | }
|
---|
| 435 | }
|
---|
[3101] | 436 | private void ParameterizeMoveMakers() {
|
---|
[3098] | 437 | foreach (IMoveMaker op in Problem.Operators.OfType<IMoveMaker>()) {
|
---|
| 438 | op.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
[6053] | 439 | op.QualityParameter.Hidden = true;
|
---|
| 440 | if (MoveEvaluator != null) {
|
---|
[3098] | 441 | op.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
|
---|
[6053] | 442 | op.MoveQualityParameter.Hidden = true;
|
---|
| 443 | } else {
|
---|
| 444 | op.MoveQualityParameter.Hidden = false;
|
---|
| 445 | }
|
---|
[3098] | 446 | }
|
---|
| 447 | }
|
---|
| 448 | private void ParameterizeAnnealingOperators() {
|
---|
[3689] | 449 | foreach (IDiscreteDoubleValueModifier op in AnnealingOperatorParameter.ValidValues) {
|
---|
[3098] | 450 | op.IndexParameter.ActualName = "Iterations";
|
---|
[6053] | 451 | op.IndexParameter.Hidden = true;
|
---|
[3098] | 452 | op.StartIndexParameter.Value = new IntValue(0);
|
---|
| 453 | op.EndIndexParameter.ActualName = MaximumIterationsParameter.Name;
|
---|
| 454 | op.ValueParameter.ActualName = "Temperature";
|
---|
[6053] | 455 | op.ValueParameter.Hidden = true;
|
---|
[3098] | 456 | op.StartValueParameter.ActualName = StartTemperatureParameter.Name;
|
---|
[6053] | 457 | op.StartValueParameter.Hidden = true;
|
---|
[3098] | 458 | op.EndValueParameter.ActualName = EndTemperatureParameter.Name;
|
---|
[6053] | 459 | op.EndValueParameter.Hidden = true;
|
---|
[3098] | 460 | ParameterizeStochasticOperator(op);
|
---|
| 461 | }
|
---|
| 462 | }
|
---|
[3101] | 463 | private void ParameterizeMoveGenerators() {
|
---|
| 464 | foreach (IMultiMoveGenerator op in Problem.Operators.OfType<IMultiMoveGenerator>()) {
|
---|
| 465 | op.SampleSizeParameter.ActualName = InnerIterationsParameter.Name;
|
---|
[6053] | 466 | op.SampleSizeParameter.Hidden = true;
|
---|
[3101] | 467 | }
|
---|
| 468 | }
|
---|
[3750] | 469 | private void ParameterizeIterationBasedOperators() {
|
---|
| 470 | if (Problem != null) {
|
---|
| 471 | foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) {
|
---|
| 472 | op.IterationsParameter.ActualName = "Iterations";
|
---|
[6053] | 473 | op.IterationsParameter.Hidden = true;
|
---|
[3750] | 474 | op.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name;
|
---|
[6053] | 475 | op.MaximumIterationsParameter.Hidden = true;
|
---|
[3750] | 476 | }
|
---|
| 477 | }
|
---|
| 478 | }
|
---|
[3622] | 479 | private void UpdateAnalyzers() {
|
---|
| 480 | Analyzer.Operators.Clear();
|
---|
| 481 | if (Problem != null) {
|
---|
[3816] | 482 | foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>()) {
|
---|
[3671] | 483 | foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
|
---|
| 484 | param.Depth = 0;
|
---|
[7172] | 485 | Analyzer.Operators.Add(analyzer, analyzer.EnabledByDefault);
|
---|
[3671] | 486 | }
|
---|
[3622] | 487 | }
|
---|
[7172] | 488 | Analyzer.Operators.Add(qualityAnalyzer, qualityAnalyzer.EnabledByDefault);
|
---|
[8016] | 489 | Analyzer.Operators.Add(temperatureAnalyzer, temperatureAnalyzer.EnabledByDefault);
|
---|
[3622] | 490 | }
|
---|
[5366] | 491 | private SimulatedAnnealingMainLoop FindMainLoop(IOperator start) {
|
---|
| 492 | IOperator mainLoop = start;
|
---|
| 493 | while (mainLoop != null && !(mainLoop is SimulatedAnnealingMainLoop))
|
---|
| 494 | mainLoop = ((SingleSuccessorOperator)mainLoop).Successor;
|
---|
| 495 | if (mainLoop == null) return null;
|
---|
| 496 | else return (SimulatedAnnealingMainLoop)mainLoop;
|
---|
| 497 | }
|
---|
[3098] | 498 | #endregion
|
---|
| 499 | }
|
---|
[8016] | 500 | } |
---|