Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost/3.3/BioBoostProblem.cs @ 13617

Last change on this file since 13617 was 13071, checked in by gkronber, 8 years ago

#2499: added license headers and removed unused usings

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