[3098] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[5445] | 3 | * Copyright (C) 2002-2011 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.")]
|
---|
| 39 | [Creatable("Algorithms")]
|
---|
[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 | }
|
---|
[6476] | 61 | public ConstrainedValueParameter<IMultiMoveGenerator> MoveGeneratorParameter {
|
---|
[3101] | 62 | get { return (ConstrainedValueParameter<IMultiMoveGenerator>)Parameters["MoveGenerator"]; }
|
---|
[3098] | 63 | }
|
---|
[6476] | 64 | public ConstrainedValueParameter<IMoveMaker> MoveMakerParameter {
|
---|
[3098] | 65 | get { return (ConstrainedValueParameter<IMoveMaker>)Parameters["MoveMaker"]; }
|
---|
| 66 | }
|
---|
[6476] | 67 | public ConstrainedValueParameter<ISingleObjectiveMoveEvaluator> MoveEvaluatorParameter {
|
---|
[3098] | 68 | get { return (ConstrainedValueParameter<ISingleObjectiveMoveEvaluator>)Parameters["MoveEvaluator"]; }
|
---|
| 69 | }
|
---|
[6476] | 70 | public ConstrainedValueParameter<IDiscreteDoubleValueModifier> AnnealingOperatorParameter {
|
---|
[3098] | 71 | get { return (ConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["AnnealingOperator"]; }
|
---|
| 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;
|
---|
[3098] | 146 | #endregion
|
---|
| 147 |
|
---|
[3622] | 148 | [StorableConstructor]
|
---|
| 149 | private SimulatedAnnealing(bool deserializing) : base(deserializing) { }
|
---|
[4722] | 150 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 151 | private void AfterDeserialization() {
|
---|
| 152 | Initialize();
|
---|
| 153 | }
|
---|
| 154 | private SimulatedAnnealing(SimulatedAnnealing original, Cloner cloner)
|
---|
| 155 | : base(original, cloner) {
|
---|
| 156 | qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
|
---|
| 157 | Initialize();
|
---|
| 158 | }
|
---|
| 159 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 160 | return new SimulatedAnnealing(this, cloner);
|
---|
| 161 | }
|
---|
[3098] | 162 | public SimulatedAnnealing()
|
---|
| 163 | : base() {
|
---|
| 164 | Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
|
---|
| 165 | Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
|
---|
[3101] | 166 | Parameters.Add(new ConstrainedValueParameter<IMultiMoveGenerator>("MoveGenerator", "The operator used to generate moves to the neighborhood of the current solution."));
|
---|
[3098] | 167 | Parameters.Add(new ConstrainedValueParameter<ISingleObjectiveMoveEvaluator>("MoveEvaluator", "The operator used to evaluate a move."));
|
---|
| 168 | Parameters.Add(new ConstrainedValueParameter<IMoveMaker>("MoveMaker", "The operator used to perform a move."));
|
---|
| 169 | Parameters.Add(new ConstrainedValueParameter<IDiscreteDoubleValueModifier>("AnnealingOperator", "The operator used to modify the temperature."));
|
---|
[3101] | 170 | Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(100)));
|
---|
| 171 | Parameters.Add(new ValueParameter<IntValue>("InnerIterations", "The amount of inner iterations (number of moves before temperature is adjusted again).", new IntValue(10)));
|
---|
[3098] | 172 | Parameters.Add(new ValueParameter<DoubleValue>("StartTemperature", "The initial temperature.", new DoubleValue(100)));
|
---|
| 173 | Parameters.Add(new ValueParameter<DoubleValue>("EndTemperature", "The final temperature which should be reached when iterations reaches maximum iterations.", new DoubleValue(1e-6)));
|
---|
[3658] | 174 | Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
|
---|
[4068] | 175 |
|
---|
[3098] | 176 | RandomCreator randomCreator = new RandomCreator();
|
---|
| 177 | SolutionsCreator solutionsCreator = new SolutionsCreator();
|
---|
[5356] | 178 | VariableCreator variableCreator = new VariableCreator();
|
---|
| 179 | ResultsCollector resultsCollector = new ResultsCollector();
|
---|
[3098] | 180 | SimulatedAnnealingMainLoop mainLoop = new SimulatedAnnealingMainLoop();
|
---|
| 181 | OperatorGraph.InitialOperator = randomCreator;
|
---|
| 182 |
|
---|
| 183 | randomCreator.RandomParameter.ActualName = "Random";
|
---|
| 184 | randomCreator.SeedParameter.ActualName = SeedParameter.Name;
|
---|
| 185 | randomCreator.SeedParameter.Value = null;
|
---|
| 186 | randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
|
---|
| 187 | randomCreator.SetSeedRandomlyParameter.Value = null;
|
---|
| 188 | randomCreator.Successor = solutionsCreator;
|
---|
| 189 |
|
---|
| 190 | solutionsCreator.NumberOfSolutions = new IntValue(1);
|
---|
[5356] | 191 | solutionsCreator.Successor = variableCreator;
|
---|
[3098] | 192 |
|
---|
[5356] | 193 | variableCreator.Name = "Initialize EvaluatedMoves";
|
---|
| 194 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("EvaluatedMoves", new IntValue()));
|
---|
[5753] | 195 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0)));
|
---|
[5356] | 196 | variableCreator.Successor = resultsCollector;
|
---|
| 197 |
|
---|
| 198 | resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Moves", null, "EvaluatedMoves"));
|
---|
| 199 | resultsCollector.ResultsParameter.ActualName = "Results";
|
---|
| 200 | resultsCollector.Successor = mainLoop;
|
---|
| 201 |
|
---|
[3098] | 202 | mainLoop.MoveGeneratorParameter.ActualName = MoveGeneratorParameter.Name;
|
---|
| 203 | mainLoop.MoveEvaluatorParameter.ActualName = MoveEvaluatorParameter.Name;
|
---|
| 204 | mainLoop.MoveMakerParameter.ActualName = MoveMakerParameter.Name;
|
---|
| 205 | mainLoop.AnnealingOperatorParameter.ActualName = AnnealingOperatorParameter.Name;
|
---|
| 206 | mainLoop.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name;
|
---|
| 207 | mainLoop.StartTemperatureParameter.ActualName = StartTemperatureParameter.Name;
|
---|
| 208 | mainLoop.EndTemperatureParameter.ActualName = EndTemperatureParameter.Name;
|
---|
| 209 | mainLoop.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
|
---|
| 210 | mainLoop.ResultsParameter.ActualName = "Results";
|
---|
[3622] | 211 | mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
|
---|
[5356] | 212 | mainLoop.EvaluatedMovesParameter.ActualName = "EvaluatedMoves";
|
---|
[5753] | 213 | mainLoop.IterationsParameter.ActualName = "Iterations";
|
---|
[3098] | 214 |
|
---|
[3689] | 215 | foreach (IDiscreteDoubleValueModifier op in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name))
|
---|
| 216 | AnnealingOperatorParameter.ValidValues.Add(op);
|
---|
| 217 | ParameterizeAnnealingOperators();
|
---|
| 218 |
|
---|
| 219 | qualityAnalyzer = new QualityAnalyzer();
|
---|
| 220 | ParameterizeAnalyzers();
|
---|
| 221 | UpdateAnalyzers();
|
---|
| 222 |
|
---|
[3098] | 223 | Initialize();
|
---|
| 224 | }
|
---|
| 225 |
|
---|
[3275] | 226 | public override void Prepare() {
|
---|
[3265] | 227 | if (Problem != null && MoveGenerator != null && MoveMaker != null && MoveEvaluator != null)
|
---|
[3275] | 228 | base.Prepare();
|
---|
[3189] | 229 | }
|
---|
| 230 |
|
---|
[3098] | 231 | #region Events
|
---|
| 232 | protected override void OnProblemChanged() {
|
---|
| 233 | ParameterizeStochasticOperator(Problem.SolutionCreator);
|
---|
| 234 | ParameterizeStochasticOperator(Problem.Evaluator);
|
---|
| 235 | foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
|
---|
| 236 | foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
|
---|
| 237 | op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
|
---|
| 238 | }
|
---|
| 239 | ParameterizeSolutionsCreator();
|
---|
| 240 | ParameterizeMainLoop();
|
---|
[3187] | 241 | UpdateMoveGenerator();
|
---|
| 242 | UpdateMoveParameters();
|
---|
[3750] | 243 | UpdateAnalyzers();
|
---|
[3101] | 244 | ParameterizeMoveEvaluators();
|
---|
| 245 | ParameterizeMoveMakers();
|
---|
| 246 | ParameterizeMoveGenerators();
|
---|
[3622] | 247 | ParameterizeAnalyzers();
|
---|
[3750] | 248 | ParameterizeIterationBasedOperators();
|
---|
[3098] | 249 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
| 250 | base.OnProblemChanged();
|
---|
| 251 | }
|
---|
| 252 | protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
|
---|
| 253 | ParameterizeStochasticOperator(Problem.SolutionCreator);
|
---|
| 254 | ParameterizeSolutionsCreator();
|
---|
| 255 | base.Problem_SolutionCreatorChanged(sender, e);
|
---|
| 256 | }
|
---|
| 257 | protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
|
---|
| 258 | ParameterizeStochasticOperator(Problem.Evaluator);
|
---|
| 259 | ParameterizeSolutionsCreator();
|
---|
| 260 | ParameterizeMainLoop();
|
---|
[3101] | 261 | ParameterizeMoveEvaluators();
|
---|
| 262 | ParameterizeMoveMakers();
|
---|
[3622] | 263 | ParameterizeAnalyzers();
|
---|
[3098] | 264 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
| 265 | base.Problem_EvaluatorChanged(sender, e);
|
---|
| 266 | }
|
---|
| 267 | protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
|
---|
| 268 | foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
|
---|
| 269 | // This may seem pointless, but some operators already have the eventhandler registered, others don't
|
---|
| 270 | // FIXME: Is there another way to solve this problem?
|
---|
| 271 | foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
|
---|
| 272 | op.MoveQualityParameter.ActualNameChanged -= new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
|
---|
| 273 | op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
|
---|
| 274 | }
|
---|
| 275 | UpdateMoveGenerator();
|
---|
[3187] | 276 | UpdateMoveParameters();
|
---|
[3622] | 277 | UpdateAnalyzers();
|
---|
[3098] | 278 | ParameterizeMainLoop();
|
---|
[3101] | 279 | ParameterizeMoveEvaluators();
|
---|
| 280 | ParameterizeMoveMakers();
|
---|
| 281 | ParameterizeMoveGenerators();
|
---|
[3750] | 282 | ParameterizeIterationBasedOperators();
|
---|
[3098] | 283 | base.Problem_OperatorsChanged(sender, e);
|
---|
| 284 | }
|
---|
| 285 | private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
| 286 | ParameterizeMainLoop();
|
---|
[3101] | 287 | ParameterizeMoveEvaluators();
|
---|
| 288 | ParameterizeMoveMakers();
|
---|
[3622] | 289 | ParameterizeAnalyzers();
|
---|
[3098] | 290 | }
|
---|
| 291 | private void MoveGeneratorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 292 | UpdateMoveParameters();
|
---|
| 293 | }
|
---|
| 294 | private void MoveEvaluatorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 295 | ParameterizeMainLoop();
|
---|
[3101] | 296 | ParameterizeMoveEvaluators();
|
---|
| 297 | ParameterizeMoveMakers();
|
---|
[3098] | 298 | }
|
---|
| 299 | private void MoveEvaluator_MoveQualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
| 300 | ParameterizeMainLoop();
|
---|
[3101] | 301 | ParameterizeMoveEvaluators();
|
---|
| 302 | ParameterizeMoveMakers();
|
---|
[3098] | 303 | }
|
---|
| 304 | #endregion
|
---|
| 305 |
|
---|
| 306 | #region Helpers
|
---|
| 307 | private void Initialize() {
|
---|
| 308 | if (Problem != null) {
|
---|
| 309 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
| 310 | foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
|
---|
| 311 | op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
|
---|
| 312 | }
|
---|
| 313 | }
|
---|
| 314 | MoveGeneratorParameter.ValueChanged += new EventHandler(MoveGeneratorParameter_ValueChanged);
|
---|
| 315 | MoveEvaluatorParameter.ValueChanged += new EventHandler(MoveEvaluatorParameter_ValueChanged);
|
---|
| 316 | }
|
---|
| 317 | private void UpdateMoveGenerator() {
|
---|
[3101] | 318 | IMultiMoveGenerator oldMoveGenerator = MoveGenerator;
|
---|
[3098] | 319 | MoveGeneratorParameter.ValidValues.Clear();
|
---|
| 320 | if (Problem != null) {
|
---|
[3101] | 321 | foreach (IMultiMoveGenerator generator in Problem.Operators.OfType<IMultiMoveGenerator>().OrderBy(x => x.Name))
|
---|
[3098] | 322 | MoveGeneratorParameter.ValidValues.Add(generator);
|
---|
| 323 | }
|
---|
| 324 | if (oldMoveGenerator != null) {
|
---|
[3101] | 325 | IMultiMoveGenerator newMoveGenerator = MoveGeneratorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveGenerator.GetType());
|
---|
[3098] | 326 | if (newMoveGenerator != null) MoveGenerator = newMoveGenerator;
|
---|
| 327 | }
|
---|
| 328 | if (MoveGenerator == null) {
|
---|
| 329 | ClearMoveParameters();
|
---|
| 330 | }
|
---|
| 331 | }
|
---|
[3622] | 332 | private void ParameterizeAnalyzers() {
|
---|
| 333 | qualityAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
| 334 | if (Problem != null) {
|
---|
| 335 | qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
[6053] | 336 | qualityAnalyzer.MaximizationParameter.Hidden = true;
|
---|
[3622] | 337 | qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
[3662] | 338 | qualityAnalyzer.QualityParameter.Depth = 0;
|
---|
[6053] | 339 | qualityAnalyzer.QualityParameter.Hidden = true;
|
---|
[3622] | 340 | qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
|
---|
[6053] | 341 | qualityAnalyzer.BestKnownQualityParameter.Hidden = true;
|
---|
| 342 | } else {
|
---|
| 343 | qualityAnalyzer.MaximizationParameter.Hidden = false;
|
---|
| 344 | qualityAnalyzer.QualityParameter.Hidden = false;
|
---|
| 345 | qualityAnalyzer.BestKnownQualityParameter.Hidden = false;
|
---|
[3622] | 346 | }
|
---|
| 347 | }
|
---|
[3098] | 348 | private void UpdateMoveParameters() {
|
---|
| 349 | IMoveMaker oldMoveMaker = MoveMaker;
|
---|
| 350 | ISingleObjectiveMoveEvaluator oldMoveEvaluator = MoveEvaluator;
|
---|
| 351 | ClearMoveParameters();
|
---|
[3131] | 352 | if (MoveGenerator != null) {
|
---|
| 353 | List<Type> moveTypes = MoveGenerator.GetType().GetInterfaces().Where(x => typeof(IMoveOperator).IsAssignableFrom(x)).ToList();
|
---|
| 354 | foreach (Type type in moveTypes.ToList()) {
|
---|
| 355 | if (moveTypes.Any(t => t != type && type.IsAssignableFrom(t)))
|
---|
| 356 | moveTypes.Remove(type);
|
---|
| 357 | }
|
---|
| 358 | foreach (Type type in moveTypes) {
|
---|
| 359 | var operators = Problem.Operators.Where(x => type.IsAssignableFrom(x.GetType())).OrderBy(x => x.Name);
|
---|
| 360 | foreach (IMoveMaker moveMaker in operators.OfType<IMoveMaker>())
|
---|
| 361 | MoveMakerParameter.ValidValues.Add(moveMaker);
|
---|
| 362 | foreach (ISingleObjectiveMoveEvaluator moveEvaluator in operators.OfType<ISingleObjectiveMoveEvaluator>())
|
---|
| 363 | MoveEvaluatorParameter.ValidValues.Add(moveEvaluator);
|
---|
| 364 | }
|
---|
| 365 | if (oldMoveMaker != null) {
|
---|
| 366 | IMoveMaker mm = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());
|
---|
| 367 | if (mm != null) MoveMaker = mm;
|
---|
| 368 | }
|
---|
| 369 | if (oldMoveEvaluator != null) {
|
---|
| 370 | ISingleObjectiveMoveEvaluator me = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());
|
---|
| 371 | if (me != null) MoveEvaluator = me;
|
---|
| 372 | }
|
---|
[3098] | 373 | }
|
---|
| 374 | }
|
---|
| 375 | private void ClearMoveParameters() {
|
---|
| 376 | MoveMakerParameter.ValidValues.Clear();
|
---|
| 377 | MoveEvaluatorParameter.ValidValues.Clear();
|
---|
| 378 | }
|
---|
| 379 | private void ParameterizeSolutionsCreator() {
|
---|
| 380 | SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
|
---|
| 381 | SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
|
---|
| 382 | }
|
---|
| 383 | private void ParameterizeMainLoop() {
|
---|
[6053] | 384 | if (Problem != null) {
|
---|
| 385 | MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
|
---|
| 386 | MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
| 387 | MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
| 388 | }
|
---|
[3098] | 389 | if (MoveEvaluator != null)
|
---|
| 390 | MainLoop.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
|
---|
| 391 | }
|
---|
| 392 | private void ParameterizeStochasticOperator(IOperator op) {
|
---|
[6053] | 393 | if (op is IStochasticOperator) {
|
---|
| 394 | IStochasticOperator stOp = (IStochasticOperator)op;
|
---|
| 395 | stOp.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
|
---|
| 396 | stOp.RandomParameter.Hidden = true;
|
---|
| 397 | }
|
---|
[3098] | 398 | }
|
---|
[3101] | 399 | private void ParameterizeMoveEvaluators() {
|
---|
[3098] | 400 | foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
|
---|
| 401 | op.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
[6053] | 402 | op.QualityParameter.Hidden = true;
|
---|
[3098] | 403 | }
|
---|
| 404 | }
|
---|
[3101] | 405 | private void ParameterizeMoveMakers() {
|
---|
[3098] | 406 | foreach (IMoveMaker op in Problem.Operators.OfType<IMoveMaker>()) {
|
---|
| 407 | op.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
[6053] | 408 | op.QualityParameter.Hidden = true;
|
---|
| 409 | if (MoveEvaluator != null) {
|
---|
[3098] | 410 | op.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
|
---|
[6053] | 411 | op.MoveQualityParameter.Hidden = true;
|
---|
| 412 | } else {
|
---|
| 413 | op.MoveQualityParameter.Hidden = false;
|
---|
| 414 | }
|
---|
[3098] | 415 | }
|
---|
| 416 | }
|
---|
| 417 | private void ParameterizeAnnealingOperators() {
|
---|
[3689] | 418 | foreach (IDiscreteDoubleValueModifier op in AnnealingOperatorParameter.ValidValues) {
|
---|
[3098] | 419 | op.IndexParameter.ActualName = "Iterations";
|
---|
[6053] | 420 | op.IndexParameter.Hidden = true;
|
---|
[3098] | 421 | op.StartIndexParameter.Value = new IntValue(0);
|
---|
| 422 | op.EndIndexParameter.ActualName = MaximumIterationsParameter.Name;
|
---|
| 423 | op.ValueParameter.ActualName = "Temperature";
|
---|
[6053] | 424 | op.ValueParameter.Hidden = true;
|
---|
[3098] | 425 | op.StartValueParameter.ActualName = StartTemperatureParameter.Name;
|
---|
[6053] | 426 | op.StartValueParameter.Hidden = true;
|
---|
[3098] | 427 | op.EndValueParameter.ActualName = EndTemperatureParameter.Name;
|
---|
[6053] | 428 | op.EndValueParameter.Hidden = true;
|
---|
[3098] | 429 | ParameterizeStochasticOperator(op);
|
---|
| 430 | }
|
---|
| 431 | }
|
---|
[3101] | 432 | private void ParameterizeMoveGenerators() {
|
---|
| 433 | foreach (IMultiMoveGenerator op in Problem.Operators.OfType<IMultiMoveGenerator>()) {
|
---|
| 434 | op.SampleSizeParameter.ActualName = InnerIterationsParameter.Name;
|
---|
[6053] | 435 | op.SampleSizeParameter.Hidden = true;
|
---|
[3101] | 436 | }
|
---|
| 437 | }
|
---|
[3750] | 438 | private void ParameterizeIterationBasedOperators() {
|
---|
| 439 | if (Problem != null) {
|
---|
| 440 | foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) {
|
---|
| 441 | op.IterationsParameter.ActualName = "Iterations";
|
---|
[6053] | 442 | op.IterationsParameter.Hidden = true;
|
---|
[3750] | 443 | op.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name;
|
---|
[6053] | 444 | op.MaximumIterationsParameter.Hidden = true;
|
---|
[3750] | 445 | }
|
---|
| 446 | }
|
---|
| 447 | }
|
---|
[3622] | 448 | private void UpdateAnalyzers() {
|
---|
| 449 | Analyzer.Operators.Clear();
|
---|
| 450 | if (Problem != null) {
|
---|
[3816] | 451 | foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>()) {
|
---|
[3671] | 452 | foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
|
---|
| 453 | param.Depth = 0;
|
---|
[3622] | 454 | Analyzer.Operators.Add(analyzer);
|
---|
[3671] | 455 | }
|
---|
[3622] | 456 | }
|
---|
[3799] | 457 | Analyzer.Operators.Add(qualityAnalyzer);
|
---|
[3622] | 458 | }
|
---|
[5366] | 459 | private SimulatedAnnealingMainLoop FindMainLoop(IOperator start) {
|
---|
| 460 | IOperator mainLoop = start;
|
---|
| 461 | while (mainLoop != null && !(mainLoop is SimulatedAnnealingMainLoop))
|
---|
| 462 | mainLoop = ((SingleSuccessorOperator)mainLoop).Successor;
|
---|
| 463 | if (mainLoop == null) return null;
|
---|
| 464 | else return (SimulatedAnnealingMainLoop)mainLoop;
|
---|
| 465 | }
|
---|
[3098] | 466 | #endregion
|
---|
| 467 | }
|
---|
| 468 | }
|
---|