source: addons/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost/3.3/MultiobjectiveBioBoostProblem.cs @ 16575

Last change on this file since 16575 was 16575, checked in by gkronber, 3 years ago

#2520: changed HeuristicLab.BioBoost addon to compile with new HL.Persistence

File size: 6.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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
22using HeuristicLab.BioBoost.Analysis;
23using HeuristicLab.BioBoost.Evaluators;
24using HeuristicLab.BioBoost.Operators.Crossover;
25using HeuristicLab.BioBoost.Operators.Mutation;
26using HeuristicLab.BioBoost.ProblemDescription;
27using HeuristicLab.BioBoost.SolutionCreation;
28using HeuristicLab.Common;
29using HeuristicLab.Core;
30using HeuristicLab.Data;
31using HeuristicLab.Optimization;
32using HeuristicLab.Parameters;
33using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
34using System;
35using HEAL.Attic;
36
37namespace HeuristicLab.BioBoost {
38
39  [Item("Multiobjective BioBoost Problem", "EU-wide aggregate biomass logistics simulation (multiobjective).")]
40  [Creatable("Problems")]
41  [StorableType("1DEF0202-CD83-4310-80FB-751D06A68B7D")]
42  public class MultiobjectiveBioBoostProblem : MultiObjectiveHeuristicOptimizationProblem<AggregateEvaluator, BioBoostSolutionCreator>, IStorableContent {
43
44    #region IStorableContent Members
45    public string Filename { get; set; }
46    #endregion
47
48    #region Parameters
49    public ValueParameter<BioBoostProblemData> ProblemDataParameter {
50      get { return (ValueParameter<BioBoostProblemData>) Parameters["ProblemData"]; }
51    }
52    public ValueParameter<IntMatrix> RegionBoundsParameter {
53      get { return (ValueParameter<IntMatrix>) Parameters["RegionBounds"]; }
54    }
55    public ValueParameter<IntValue> NRegionsParameter {
56      get { return (ValueParameter<IntValue>) Parameters["NRegions"]; }
57    }
58    public ValueParameter<BoolValue> RemoveIntermediateResultsParameter {
59      get { return (ValueParameter<BoolValue>) Parameters["RemoveIntermediateResults"]; }
60    }
61    #endregion
62
63    #region Parameter Values
64    public BioBoostProblemData ProblemData {
65      get { return ProblemDataParameter.Value; }
66    }
67    public IntMatrix RegionBounds {
68      get { return RegionBoundsParameter.Value; }
69      set { RegionBoundsParameter.Value = value; }
70    }
71    public int NRegions {
72      get { return NRegionsParameter.Value.Value; }
73      set { NRegionsParameter.Value = new IntValue(value); }
74    }
75    public bool RemoveIntermediateResults {
76      get { return RemoveIntermediateResultsParameter.Value.Value; }
77    }
78    #endregion
79
80    #region Construction & Cloning
81    [StorableConstructor]
82    protected MultiobjectiveBioBoostProblem(StorableConstructorFlag _) : base(_) { }
83    protected MultiobjectiveBioBoostProblem(MultiobjectiveBioBoostProblem orig, Cloner cloner) : base(orig, cloner) {
84      RegisterEvents();
85    }
86    public MultiobjectiveBioBoostProblem() {
87      Parameters.Add(new ValueParameter<BioBoostProblemData>("ProblemData", "Encapsulation of all data describing the problem instance."));
88      Parameters.Add(new ValueParameter<IntMatrix>("RegionBounds", "Bounds for valid region ids.", new IntMatrix(new int[,]{{0, 0}})));
89      Parameters.Add(new ValueParameter<IntValue>("NRegions", "Number of regions.", new IntValue(0)));
90      Parameters.Add(new ValueParameter<BoolValue>("RemoveIntermediateResults", "Whether to remove intermediate results created during evaluation.", new BoolValue(true)));
91      Maximization = new BoolArray(new [] {true, true});
92      RegionBoundsParameter.Hidden = true;
93      RegisterEvents();
94      Operators.Add(new CompoundCrossover());
95      Operators.Add(new MultiCrossover());
96      Operators.Add(new PlantBasedCrossover());
97      Operators.Add(new BoundaryToggleRealVectorMutator());
98      Operators.Add(new CompoundMutator());
99      Operators.Add(new EmptyMutator());
100      Operators.Add(new MultiMutator());
101      Operators.Add(new PlantKiller());
102      Operators.Add(new PlantMerger());
103      Operators.Add(new PlantMover());
104      Operators.Add(new PlantScalingMutator());
105      Operators.Add(new PlantSupplierEqualizer());
106      Operators.Add(new PlantSupplierRandomizer());
107      Operators.Add(new PlantSupplierToggler());
108      Operators.Add(new PlantSupplierUtilizationExchanger());
109      Operators.Add(new MultiObjectiveBioBoostSolutionAnalyzer());
110    }
111    public override IDeepCloneable Clone(Cloner cloner) {
112      return new MultiobjectiveBioBoostProblem(this, cloner);
113    }
114    [StorableHook(HookType.AfterDeserialization)]
115    private void AfterDeserialization() {
116      RegisterEvents();
117    }
118    #endregion
119
120    #region events
121    private void RegisterEvents() {
122      NRegionsParameter.ToStringChanged += new EventHandler(NRegionsParameterChanged);
123      ProblemDataParameter.ValueChanged += UpdateEventRegistration;
124      UpdateEventRegistration(this, EventArgs.Empty);
125    }
126
127    private BioBoostProblemData registeredProblemData = null;
128
129    private void UpdateEventRegistration(object sender, EventArgs eventArgs) {
130      if (registeredProblemData == ProblemData) return;
131      if (registeredProblemData != null) {
132        registeredProblemData.LocationNamesParameter.ToStringChanged -= LocationNamesChanged;
133      }
134      ProblemData.LocationNamesParameter.ToStringChanged += LocationNamesChanged;
135      registeredProblemData = ProblemData;
136    }
137
138    private void LocationNamesChanged(object sender, EventArgs e) {
139      NRegions = ProblemData.LocationNames.Length;
140    }
141
142    private void NRegionsParameterChanged(object sender, EventArgs e) {
143      RegionBounds = new IntMatrix(new int[,] {{0, NRegions}});
144    }
145    #endregion
146  }
147}
Note: See TracBrowser for help on using the repository browser.