source: branches/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost/3.3/MultiobjectiveBioBoostProblem.cs @ 13069

Last change on this file since 13069 was 13069, checked in by gkronber, 7 years ago

#2499: imported source code for HeuristicLab.BioBoost from private repository with some changes

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