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