Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost/3.3/BioBoostProblem.cs @ 17029

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

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

File size: 6.3 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 HeuristicLab.BioBoost.Operators.Moves;
36using HEAL.Attic;
37
38namespace HeuristicLab.BioBoost {
39
40  public interface IBioBoostSimulationEvaluator : ISingleObjectiveEvaluator, IMultiObjectiveEvaluator {}
41
42  [Item("BioBoost Problem", "EU-wide aggregate biomass logistics simulation.")]
43  [Creatable("Problems")]
44  [StorableType("248ABB24-9C03-41FB-816F-C5C47018CB6B")]
45  public class BioBoostProblem : SingleObjectiveHeuristicOptimizationProblem<AggregateEvaluator, BioBoostSolutionCreator>, IStorableContent {
46
47    #region IStorableContent Members
48    public string Filename { get; set; }
49    #endregion
50
51    #region Parameters
52    public ValueParameter<BioBoostProblemData> ProblemDataParameter {
53      get { return (ValueParameter<BioBoostProblemData>) Parameters["ProblemData"]; }
54    }
55    public ValueParameter<IntMatrix> RegionBoundsParameter {
56      get { return (ValueParameter<IntMatrix>) Parameters["RegionBounds"]; }
57    }
58    public ValueParameter<IntValue> NRegionsParameter {
59      get { return (ValueParameter<IntValue>) Parameters["NRegions"]; }
60    }
61    public ValueParameter<BoolValue> RemoveIntermediateResultsParameter {
62      get { return (ValueParameter<BoolValue>) Parameters["RemoveIntermediateResults"]; }
63    }
64    #endregion
65
66    #region Parameter Values
67    public BioBoostProblemData ProblemData {
68      get { return ProblemDataParameter.Value; }
69    }
70    public IntMatrix RegionBounds {
71      get { return RegionBoundsParameter.Value; }
72      set { RegionBoundsParameter.Value = value; }
73    }
74    public int NRegions {
75      get { return NRegionsParameter.Value.Value; }
76      set { NRegionsParameter.Value = new IntValue(value); }
77    }
78    public bool RemoveIntermediateResults {
79      get { return RemoveIntermediateResultsParameter.Value.Value; }
80    }
81    #endregion
82
83    #region Construction & Cloning
84    [StorableConstructor]
85    protected BioBoostProblem(StorableConstructorFlag _) : base(_) { }
86    protected BioBoostProblem(BioBoostProblem orig, Cloner cloner) : base(orig, cloner) {
87      RegisterEvents();
88    }
89    public BioBoostProblem() {
90      Parameters.Add(new ValueParameter<BioBoostProblemData>("ProblemData", "Encapsulation of all data describing the problem instance."));
91      Parameters.Add(new ValueParameter<IntMatrix>("RegionBounds", "Bounds for valid region ids.", new IntMatrix(new int[,]{{0, 0}})));
92      Parameters.Add(new ValueParameter<IntValue>("NRegions", "Number of regions.", new IntValue(0)));
93      Parameters.Add(new ValueParameter<BoolValue>("RemoveIntermediateResults", "Whether to remove intermediate results created during evaluation.", new BoolValue(true)));
94      RegionBoundsParameter.Hidden = true;
95      Maximization.Value = true;
96      RegisterEvents();
97      Operators.Add(new CompoundCrossover());
98      Operators.Add(new MultiCrossover());
99      Operators.Add(new PlantBasedCrossover());
100      Operators.Add(new BoundaryToggleRealVectorMutator());
101      Operators.Add(new CompoundMutator());
102      Operators.Add(new EmptyMutator());
103      Operators.Add(new MultiMutator());
104      Operators.Add(new PlantKiller());
105      Operators.Add(new PlantMerger());
106      Operators.Add(new PlantMover());
107      Operators.Add(new PlantScalingMutator());
108      Operators.Add(new PlantSupplierEqualizer());
109      Operators.Add(new PlantSupplierRandomizer());
110      Operators.Add(new PlantSupplierToggler());
111      Operators.Add(new PlantSupplierUtilizationExchanger());
112      Operators.Add(new BestBioBoostSolutionAnalyzer());
113      Operators.Add(new MoveGeneratorAdapter());
114      Operators.Add(new MoveEvaluatorAdapter());
115      Operators.Add(new MoveMakerAdapter());
116      Evaluator = new MonolithicEvaluator();
117    }
118    public override IDeepCloneable Clone(Cloner cloner) {
119      return new BioBoostProblem(this, cloner);
120    }
121    [StorableHook(HookType.AfterDeserialization)]
122    private void AfterDeserialization() {
123      RegisterEvents();
124    }
125    #endregion
126
127    #region events
128    private void RegisterEvents() {
129      NRegionsParameter.ToStringChanged += new EventHandler(NRegionsParameterChanged);
130      ProblemDataParameter.ValueChanged += UpdateEventRegistration;
131      UpdateEventRegistration(this, EventArgs.Empty);
132    }
133
134    private BioBoostProblemData registeredProblemData = null;
135
136    private void UpdateEventRegistration(object sender, EventArgs eventArgs) {
137      if (registeredProblemData == ProblemData) return;
138      if (registeredProblemData != null) {
139        registeredProblemData.LocationNamesParameter.ToStringChanged -= LocationNamesChanged;
140      }
141      ProblemData.LocationNamesParameter.ToStringChanged += LocationNamesChanged;
142      registeredProblemData = ProblemData;
143    }
144
145    private void LocationNamesChanged(object sender, EventArgs e) {
146      NRegions = ProblemData.LocationNames.Length;
147    }
148
149    private void NRegionsParameterChanged(object sender, EventArgs e) {
150      RegionBounds = new IntMatrix(new int[,] {{0, NRegions}});
151    }
152    #endregion
153  }
154}
Note: See TracBrowser for help on using the repository browser.