[11400] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 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.Drawing;
|
---|
| 25 | using System.Linq;
|
---|
| 26 | using HeuristicLab.Common;
|
---|
| 27 | using HeuristicLab.Core;
|
---|
| 28 | using HeuristicLab.Data;
|
---|
| 29 | using HeuristicLab.Optimization;
|
---|
| 30 | using HeuristicLab.Parameters;
|
---|
| 31 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 32 |
|
---|
| 33 | namespace HeuristicLab.Problems.Programmable {
|
---|
| 34 | [Item("Programmable Problem (multi-objective)", "Represents a multi-objective problem that can be programmed.")]
|
---|
| 35 | [Creatable("Problems")]
|
---|
| 36 | [StorableClass]
|
---|
[11739] | 37 | public class OLD_MultiObjectiveProgrammableProblem : MultiObjectiveHeuristicOptimizationProblem<MultiObjectiveEvaluator, ISolutionCreator>, IParameterizedNamedItem, IStorableContent {
|
---|
[11400] | 38 | public string Filename { get; set; }
|
---|
| 39 |
|
---|
| 40 | public static new Image StaticItemImage {
|
---|
| 41 | get { return Common.Resources.VSImageLibrary.Script; }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | public new ParameterCollection Parameters {
|
---|
| 45 | get { return base.Parameters; }
|
---|
| 46 | }
|
---|
| 47 | IKeyedItemCollection<string, IParameter> IParameterizedItem.Parameters {
|
---|
| 48 | get { return Parameters; }
|
---|
| 49 | }
|
---|
| 50 |
|
---|
[11484] | 51 | public IValueParameter<IMultiObjectiveProblemDefinition> ProblemDefinitionParameter {
|
---|
| 52 | get { return (IValueParameter<IMultiObjectiveProblemDefinition>)Parameters["ProblemDefinition"]; }
|
---|
[11400] | 53 | }
|
---|
| 54 |
|
---|
[11550] | 55 | protected IValueParameter<IEncoding> EncodingParameter {
|
---|
| 56 | get { return (IValueParameter<IEncoding>)Parameters["Encoding"]; }
|
---|
[11400] | 57 | }
|
---|
| 58 |
|
---|
[11484] | 59 | public IMultiObjectiveProblemDefinition ProblemDefinition {
|
---|
[11400] | 60 | get { return ProblemDefinitionParameter.Value; }
|
---|
| 61 | set { ProblemDefinitionParameter.Value = value; }
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | [Storable]
|
---|
[11484] | 65 | protected List<IParameter> DynamicEncodingParameters;
|
---|
[11400] | 66 |
|
---|
| 67 | [StorableConstructor]
|
---|
[11739] | 68 | protected OLD_MultiObjectiveProgrammableProblem(bool deserializing) : base(deserializing) { }
|
---|
| 69 | protected OLD_MultiObjectiveProgrammableProblem(OLD_MultiObjectiveProgrammableProblem original, Cloner cloner)
|
---|
[11400] | 70 | : base(original, cloner) {
|
---|
[11484] | 71 | DynamicEncodingParameters = original.DynamicEncodingParameters.Select(cloner.Clone).ToList();
|
---|
[11400] | 72 | RegisterEventHandlers();
|
---|
| 73 | }
|
---|
[11739] | 74 | public OLD_MultiObjectiveProgrammableProblem()
|
---|
[11484] | 75 | : base(new MultiObjectiveEvaluator(), new MultiEncodingCreator()) {
|
---|
[11739] | 76 | Parameters.Add(new ValueParameter<IMultiObjectiveProblemDefinition>("ProblemDefinition", "Defines the problem.", new MultiObjectiveProblemDefinitionScript() { Name = Name }));
|
---|
[11550] | 77 | Parameters.Add(new ValueParameter<IEncoding>("Encoding", "Describes which parameters exist, what they're called, what type they are and their bounds if any."));
|
---|
[11400] | 78 |
|
---|
[11484] | 79 | DynamicEncodingParameters = new List<IParameter>();
|
---|
[11400] | 80 |
|
---|
| 81 | Operators.Add(new MultiObjectiveAnalyzer());
|
---|
| 82 | Operators.Add(Evaluator);
|
---|
| 83 |
|
---|
| 84 | RegisterEventHandlers();
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[11739] | 88 | return new OLD_MultiObjectiveProgrammableProblem(this, cloner);
|
---|
[11400] | 89 | }
|
---|
| 90 |
|
---|
| 91 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 92 | // ReSharper disable UnusedMember.Local
|
---|
| 93 | private void AfterDeserialization() {
|
---|
| 94 | RegisterEventHandlers();
|
---|
| 95 | }
|
---|
| 96 | // ReSharper restore UnusedMember.Local
|
---|
| 97 |
|
---|
| 98 | private void RegisterEventHandlers() {
|
---|
| 99 | ProblemDefinitionParameter.ValueChanged += ProblemDefinitionParameterOnValueChanged;
|
---|
| 100 | RegisterHostInstanceChanges();
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | private void ProblemDefinitionParameterOnValueChanged(object sender, EventArgs eventArgs) {
|
---|
| 104 | RegisterHostInstanceChanges();
|
---|
| 105 | Parameterize();
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | private void RegisterHostInstanceChanges() {
|
---|
[11739] | 109 | //ProblemDefinitionParameter.Value.ProblemDefinitionChanged += ProblemDefinitionChanged;
|
---|
[11400] | 110 | ProblemDefinitionParameter.Value.NameChanged += ProblemDefinitionHostOnNameChanged;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | private void ProblemDefinitionHostOnNameChanged(object sender, EventArgs eventArgs) {
|
---|
| 114 | if (sender != ProblemDefinitionParameter.Value) return;
|
---|
| 115 | Name = ProblemDefinitionParameter.Value.Name;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | protected override void OnNameChanged() {
|
---|
| 119 | base.OnNameChanged();
|
---|
| 120 | ProblemDefinitionParameter.Value.Name = Name;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | protected override void OnEvaluatorChanged() {
|
---|
| 124 | base.OnEvaluatorChanged();
|
---|
| 125 | Parameterize();
|
---|
| 126 | }
|
---|
| 127 |
|
---|
[11484] | 128 | protected virtual void ProblemDefinitionChanged(object sender, EventArgs eventArgs) {
|
---|
[11400] | 129 | Parameterize();
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | protected virtual void Parameterize() {
|
---|
[11484] | 133 | var definition = ProblemDefinitionParameter.Value;
|
---|
| 134 | if (definition == null) return;
|
---|
[11400] | 135 |
|
---|
[11550] | 136 | IEncoding encoding = definition.Encoding;
|
---|
[11484] | 137 | EncodingParameter.Value = encoding;
|
---|
| 138 | Maximization = new BoolArray(definition.Maximization);
|
---|
[11400] | 139 |
|
---|
[11484] | 140 | Evaluator.EncodingParameter.ActualName = EncodingParameter.Name;
|
---|
[11739] | 141 | //Evaluator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;
|
---|
| 142 | //foreach (var evalOp in Operators.OfType<IMultiObjectiveProgrammableProblemEvaluator>()) {
|
---|
| 143 | // evalOp.EncodingParameter.ActualName = EncodingParameter.Name;
|
---|
| 144 | // evalOp.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;
|
---|
| 145 | //}
|
---|
| 146 | //foreach (var analyzeOp in Operators.OfType<IMultiObjectiveProgrammableProblemAnalyzer>()) {
|
---|
| 147 | // analyzeOp.EncodingParameter.ActualName = EncodingParameter.Name;
|
---|
| 148 | // analyzeOp.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;
|
---|
| 149 | // analyzeOp.QualitiesParameter.ActualName = Evaluator.QualitiesParameter.ActualName;
|
---|
| 150 | //}
|
---|
[11400] | 151 |
|
---|
[11587] | 152 | SolutionCreator = encoding.SolutionCreator;
|
---|
| 153 |
|
---|
[11484] | 154 | foreach (var param in DynamicEncodingParameters)
|
---|
| 155 | if (Parameters.Contains(param)) Parameters.Remove(param);
|
---|
| 156 | DynamicEncodingParameters.Clear();
|
---|
[11400] | 157 |
|
---|
[11587] | 158 | DynamicEncodingParameters.AddRange(encoding.Parameters);
|
---|
[11484] | 159 |
|
---|
[11587] | 160 |
|
---|
[11484] | 161 | foreach (var param in DynamicEncodingParameters) {
|
---|
| 162 | param.Hidden = true;
|
---|
| 163 | Parameters.Add(param);
|
---|
| 164 | }
|
---|
| 165 |
|
---|
[11400] | 166 | }
|
---|
| 167 | }
|
---|
| 168 | }
|
---|