[13069] | 1 | using System.Collections.Generic;
|
---|
| 2 | using HeuristicLab.BioBoost.Analysis;
|
---|
| 3 | using HeuristicLab.BioBoost.Evaluators;
|
---|
| 4 | using HeuristicLab.BioBoost.Operators.Crossover;
|
---|
| 5 | using HeuristicLab.BioBoost.Operators.Mutation;
|
---|
| 6 | using HeuristicLab.BioBoost.ProblemDescription;
|
---|
| 7 | using HeuristicLab.BioBoost.SolutionCreation;
|
---|
| 8 | using HeuristicLab.Common;
|
---|
| 9 | using HeuristicLab.Core;
|
---|
| 10 | using HeuristicLab.Data;
|
---|
| 11 | using HeuristicLab.Optimization;
|
---|
| 12 | using HeuristicLab.Parameters;
|
---|
| 13 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 14 | using System;
|
---|
| 15 | using HeuristicLab.BioBoost.Operators.Moves;
|
---|
| 16 |
|
---|
| 17 | namespace 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 | }
|
---|