Free cookie consent management tool by TermsFeed Policy Generator

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

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

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

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