#region License Information /* HeuristicLab * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using HeuristicLab.BioBoost.Analysis; using HeuristicLab.BioBoost.Evaluators; using HeuristicLab.BioBoost.Operators.Crossover; using HeuristicLab.BioBoost.Operators.Mutation; using HeuristicLab.BioBoost.ProblemDescription; using HeuristicLab.BioBoost.SolutionCreation; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Optimization; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using System; using HEAL.Attic; namespace HeuristicLab.BioBoost { [Item("Multiobjective BioBoost Problem", "EU-wide aggregate biomass logistics simulation (multiobjective).")] [Creatable("Problems")] [StorableType("1DEF0202-CD83-4310-80FB-751D06A68B7D")] public class MultiobjectiveBioBoostProblem : MultiObjectiveHeuristicOptimizationProblem, IStorableContent { #region IStorableContent Members public string Filename { get; set; } #endregion #region Parameters public ValueParameter ProblemDataParameter { get { return (ValueParameter) Parameters["ProblemData"]; } } public ValueParameter RegionBoundsParameter { get { return (ValueParameter) Parameters["RegionBounds"]; } } public ValueParameter NRegionsParameter { get { return (ValueParameter) Parameters["NRegions"]; } } public ValueParameter RemoveIntermediateResultsParameter { get { return (ValueParameter) Parameters["RemoveIntermediateResults"]; } } #endregion #region Parameter Values public BioBoostProblemData ProblemData { get { return ProblemDataParameter.Value; } } public IntMatrix RegionBounds { get { return RegionBoundsParameter.Value; } set { RegionBoundsParameter.Value = value; } } public int NRegions { get { return NRegionsParameter.Value.Value; } set { NRegionsParameter.Value = new IntValue(value); } } public bool RemoveIntermediateResults { get { return RemoveIntermediateResultsParameter.Value.Value; } } #endregion #region Construction & Cloning [StorableConstructor] protected MultiobjectiveBioBoostProblem(StorableConstructorFlag _) : base(_) { } protected MultiobjectiveBioBoostProblem(MultiobjectiveBioBoostProblem orig, Cloner cloner) : base(orig, cloner) { RegisterEvents(); } public MultiobjectiveBioBoostProblem() { Parameters.Add(new ValueParameter("ProblemData", "Encapsulation of all data describing the problem instance.")); Parameters.Add(new ValueParameter("RegionBounds", "Bounds for valid region ids.", new IntMatrix(new int[,]{{0, 0}}))); Parameters.Add(new ValueParameter("NRegions", "Number of regions.", new IntValue(0))); Parameters.Add(new ValueParameter("RemoveIntermediateResults", "Whether to remove intermediate results created during evaluation.", new BoolValue(true))); Maximization = new BoolArray(new [] {true, true}); RegionBoundsParameter.Hidden = true; RegisterEvents(); Operators.Add(new CompoundCrossover()); Operators.Add(new MultiCrossover()); Operators.Add(new PlantBasedCrossover()); Operators.Add(new BoundaryToggleRealVectorMutator()); Operators.Add(new CompoundMutator()); Operators.Add(new EmptyMutator()); Operators.Add(new MultiMutator()); Operators.Add(new PlantKiller()); Operators.Add(new PlantMerger()); Operators.Add(new PlantMover()); Operators.Add(new PlantScalingMutator()); Operators.Add(new PlantSupplierEqualizer()); Operators.Add(new PlantSupplierRandomizer()); Operators.Add(new PlantSupplierToggler()); Operators.Add(new PlantSupplierUtilizationExchanger()); Operators.Add(new MultiObjectiveBioBoostSolutionAnalyzer()); } public override IDeepCloneable Clone(Cloner cloner) { return new MultiobjectiveBioBoostProblem(this, cloner); } [StorableHook(HookType.AfterDeserialization)] private void AfterDeserialization() { RegisterEvents(); } #endregion #region events private void RegisterEvents() { NRegionsParameter.ToStringChanged += new EventHandler(NRegionsParameterChanged); ProblemDataParameter.ValueChanged += UpdateEventRegistration; UpdateEventRegistration(this, EventArgs.Empty); } private BioBoostProblemData registeredProblemData = null; private void UpdateEventRegistration(object sender, EventArgs eventArgs) { if (registeredProblemData == ProblemData) return; if (registeredProblemData != null) { registeredProblemData.LocationNamesParameter.ToStringChanged -= LocationNamesChanged; } ProblemData.LocationNamesParameter.ToStringChanged += LocationNamesChanged; registeredProblemData = ProblemData; } private void LocationNamesChanged(object sender, EventArgs e) { NRegions = ProblemData.LocationNames.Length; } private void NRegionsParameterChanged(object sender, EventArgs e) { RegionBounds = new IntMatrix(new int[,] {{0, NRegions}}); } #endregion } }