Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/21/18 09:18:49 (6 years ago)
Author:
bwerth
Message:

#2943 worked on MOBasicProblem - added Interfaces;reworked MOCalculators; several minor changes

Location:
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Optimization/3.3
Files:
7 added
5 edited

Legend:

Unmodified
Added
Removed
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Optimization/3.3/BasicProblems/BasicProblem.cs

    r15583 r16171  
    3030namespace HeuristicLab.Optimization {
    3131  [StorableClass]
    32   public abstract class BasicProblem<TEncoding, TEvaluator> : HeuristicOptimizationProblem<TEvaluator, ISolutionCreator>, IProblemDefinition, IStorableContent
     32  public abstract class BasicProblem<TEncoding, TEvaluator> : HeuristicOptimizationProblem<TEvaluator, ISolutionCreator>, IBasicProblem
    3333    where TEncoding : class, IEncoding
    3434    where TEvaluator : class, IEvaluator {
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Optimization/3.3/BasicProblems/MultiObjectiveBasicProblem.cs

    r15583 r16171  
    3131namespace HeuristicLab.Optimization {
    3232  [StorableClass]
    33   public abstract class MultiObjectiveBasicProblem<TEncoding> : BasicProblem<TEncoding, MultiObjectiveEvaluator>, IMultiObjectiveHeuristicOptimizationProblem, IMultiObjectiveProblemDefinition
     33  public abstract class MultiObjectiveBasicProblem<TEncoding> : BasicProblem<TEncoding, MultiObjectiveEvaluator>, IMultiObjectiveBasicProblem
    3434  where TEncoding : class, IEncoding {
     35
     36    #region Parameternames
     37    public const string MaximizationParameterName = "Maximization";
     38    public const string BestKnownFrontParameterName = "BestKnownFront";
     39    public const string ReferencePointParameterName = "ReferencePoint";
     40    #endregion
     41
     42    #region Parameterproperties
     43    public IValueParameter<BoolArray> MaximizationParameter {
     44      get { return (IValueParameter<BoolArray>) Parameters[MaximizationParameterName]; }
     45    }
     46    public IValueParameter<DoubleMatrix> BestKnownFrontParameter {
     47      get { return (IValueParameter<DoubleMatrix>)Parameters[BestKnownFrontParameterName]; }
     48    }
     49    public IValueParameter<DoubleArray> ReferencePointParameter {
     50      get { return (IValueParameter<DoubleArray>)Parameters[ReferencePointParameterName]; }
     51    }
     52    #endregion
     53
     54    #region Properties
     55
     56    public abstract bool[] Maximization { get; }
     57
     58    public DoubleMatrix BestKnownFront {
     59      get { return Parameters.ContainsKey(BestKnownFrontParameterName) ? BestKnownFrontParameter.Value : null; }
     60      set { BestKnownFrontParameter.Value = value; }
     61    }
     62    public DoubleArray ReferencePoint {
     63      get { return Parameters.ContainsKey(ReferencePointParameterName) ? ReferencePointParameter.Value : null; }
     64      set { ReferencePointParameter.Value = value; }
     65    }
     66    #endregion
     67
    3568    [StorableConstructor]
    3669    protected MultiObjectiveBasicProblem(bool deserializing) : base(deserializing) { }
     
    4376    protected MultiObjectiveBasicProblem()
    4477      : base() {
    45       Parameters.Add(new ValueParameter<BoolArray>("Maximization", "Set to false if the problem should be minimized.", (BoolArray)new BoolArray(Maximization).AsReadOnly()));
    46 
     78      Parameters.Add(new ValueParameter<BoolArray>(MaximizationParameterName, "Set to false if the problem should be minimized.", (BoolArray)new BoolArray(Maximization).AsReadOnly()));
     79      Parameters.Add(new OptionalValueParameter<DoubleMatrix>(BestKnownFrontParameterName, "A double matrix representing the best known qualites for this problem (aka points on the Pareto front). Points are to be given in a row-wise fashion."));
     80      Parameters.Add(new OptionalValueParameter<DoubleArray>(ReferencePointParameterName, "The refrence point for hypervolume calculations on this problem"));
    4781      Operators.Add(Evaluator);
    4882      Operators.Add(new MultiObjectiveAnalyzer());
     
    5690    }
    5791
    58     public abstract bool[] Maximization { get; }
     92   
    5993    public abstract double[] Evaluate(Individual individual, IRandom random);
    6094    public virtual void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random) { }
     
    96130    }
    97131
    98 
    99132    #region IMultiObjectiveHeuristicOptimizationProblem Members
    100133    IParameter IMultiObjectiveHeuristicOptimizationProblem.MaximizationParameter {
    101       get { return Parameters["Maximization"]; }
     134      get { return Parameters[MaximizationParameterName]; }
    102135    }
    103136    IMultiObjectiveEvaluator IMultiObjectiveHeuristicOptimizationProblem.Evaluator {
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveBasicProblem.cs

    r15583 r16171  
    3131namespace HeuristicLab.Optimization {
    3232  [StorableClass]
    33   public abstract class SingleObjectiveBasicProblem<TEncoding> : BasicProblem<TEncoding, SingleObjectiveEvaluator>,
    34     ISingleObjectiveProblemDefinition, ISingleObjectiveHeuristicOptimizationProblem
     33  public abstract class SingleObjectiveBasicProblem<TEncoding> : BasicProblem<TEncoding, SingleObjectiveEvaluator>, ISingleObjectiveBasicProblem
    3534  where TEncoding : class, IEncoding {
    3635
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj

    r16123 r16171  
    4141    <DebugType>full</DebugType>
    4242    <Optimize>false</Optimize>
    43     <OutputPath>$(SolutionDir)\bin\</OutputPath>
     43    <OutputPath>..\..\..\..\trunk\bin\</OutputPath>
    4444    <DefineConstants>DEBUG;TRACE</DefineConstants>
    4545    <ErrorReport>prompt</ErrorReport>
     
    105105  </PropertyGroup>
    106106  <ItemGroup>
     107    <Reference Include="ALGLIB-3.7.0, Version=3.7.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     108      <SpecificVersion>False</SpecificVersion>
     109      <HintPath>..\..\..\..\trunk\bin\ALGLIB-3.7.0.dll</HintPath>
     110    </Reference>
     111    <Reference Include="HeuristicLab.ALGLIB-3.7.0, Version=3.7.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     112      <SpecificVersion>False</SpecificVersion>
     113      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.ALGLIB-3.7.0.dll</HintPath>
     114    </Reference>
    107115    <Reference Include="HeuristicLab.Collections-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    108116      <SpecificVersion>False</SpecificVersion>
     
    120128      <SpecificVersion>False</SpecificVersion>
    121129      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Core-3.3.dll</HintPath>
    122     </Reference>
    123     <Reference Include="HeuristicLab.Data-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    124       <SpecificVersion>False</SpecificVersion>
    125       <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Data-3.3.dll</HintPath>
    126130    </Reference>
    127131    <Reference Include="HeuristicLab.Operators-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     
    162166    <Compile Include="BasicProblems\Individuals\MultiEncodingIndividual.cs" />
    163167    <Compile Include="BasicProblems\Individuals\SingleEncodingIndividual.cs" />
     168    <Compile Include="BasicProblems\Interfaces\IBasicProblem.cs" />
    164169    <Compile Include="BasicProblems\Interfaces\IEncoding.cs" />
    165170    <Compile Include="BasicProblems\Interfaces\IEncodingOperator.cs" />
    166171    <Compile Include="BasicProblems\Interfaces\IMultiEncodingOperator.cs" />
     172    <Compile Include="BasicProblems\Interfaces\IMultiObjectiveBasicProblem.cs" />
    167173    <Compile Include="BasicProblems\Interfaces\IMultiObjectiveProblemDefinition.cs" />
    168174    <Compile Include="BasicProblems\Interfaces\internal\IMultiObjectiveAnalysisOperator.cs" />
     
    172178    <Compile Include="BasicProblems\Interfaces\internal\ISingleObjectiveEvaluationOperator.cs" />
    173179    <Compile Include="BasicProblems\Interfaces\IProblemDefinition.cs" />
     180    <Compile Include="BasicProblems\Interfaces\ISingleObjectiveBasicProblem.cs" />
    174181    <Compile Include="BasicProblems\Interfaces\ISingleObjectiveMoveOperator.cs" />
    175182    <Compile Include="BasicProblems\Interfaces\ISingleObjectiveProblemDefinition.cs" />
     
    192199    <Compile Include="Interfaces\ILocalImprovementAlgorithmOperator.cs" />
    193200    <Compile Include="Interfaces\IMultiObjectiveOperator.cs" />
     201    <Compile Include="MultiObjective\CrowdingCalculator.cs" />
    194202    <Compile Include="MultiObjective\DominationCalculator.cs" />
     203    <Compile Include="MultiObjective\GenerationalDistanceCalculator.cs" />
     204    <Compile Include="MultiObjective\HypervolumeCalculator.cs" />
     205    <Compile Include="MultiObjective\SpacingCalculator.cs" />
    195206    <Compile Include="Results\IResultParameter.cs" />
    196207    <Compile Include="Interfaces\ISingleObjectiveOperator.cs" />
     
    319330    </BootstrapperPackage>
    320331  </ItemGroup>
    321   <ItemGroup />
     332  <ItemGroup>
     333    <ProjectReference Include="..\..\HeuristicLab.Data\3.3\HeuristicLab.Data-3.3.csproj">
     334      <Project>{bbab9df5-5ef3-4ba8-ade9-b36e82114937}</Project>
     335      <Name>HeuristicLab.Data-3.3</Name>
     336    </ProjectReference>
     337  </ItemGroup>
    322338  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    323339  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Optimization/3.3/MultiObjective/DominationCalculator.cs

    r15583 r16171  
    2424
    2525namespace HeuristicLab.Optimization {
     26
    2627  public enum DominationResult { Dominates, IsDominated, IsNonDominated };
    2728
    28   public static class DominationCalculator<T> {
     29  public static class DominationCalculator {
    2930    /// <summary>
    3031    /// Calculates the best pareto front only. The fast non-dominated sorting algorithm is used
     
    4344    /// <param name="dominateOnEqualQualities">Whether solutions of exactly equal quality should dominate one another.</param>
    4445    /// <returns>The pareto front containing the best solutions and their associated quality resp. fitness.</returns>
    45     public static List<Tuple<T, double[]>> CalculateBestParetoFront(T[] solutions, double[][] qualities, bool[] maximization, bool dominateOnEqualQualities = true) {
    46       int populationSize = solutions.Length;
     46    public static List<Tuple<T, double[]>> CalculateBestParetoFront<T>(T[] solutions, double[][] qualities, bool[] maximization, bool dominateOnEqualQualities = true) {
     47      var populationSize = solutions.Length;
    4748
    4849      Dictionary<T, List<int>> dominatedIndividuals;
     
    6970    /// <param name="dominateOnEqualQualities">Whether solutions of exactly equal quality should dominate one another.</param>
    7071    /// <returns>A sorted list of the pareto fronts from best to worst.</returns>
    71     public static List<List<Tuple<T, double[]>>> CalculateAllParetoFronts(T[] solutions, double[][] qualities, bool[] maximization, out int[] rank, bool dominateOnEqualQualities = true) {
    72       int populationSize = solutions.Length;
     72    public static List<List<Tuple<T, double[]>>> CalculateAllParetoFronts<T>(T[] solutions, double[][] qualities, bool[] maximization, out int[] rank, bool dominateOnEqualQualities = true) {
     73      var populationSize = solutions.Length;
    7374
    7475      Dictionary<T, List<int>> dominatedIndividuals;
     
    7677      var fronts = new List<List<Tuple<T, double[]>>>();
    7778      fronts.Add(CalculateBestFront(solutions, qualities, maximization, dominateOnEqualQualities, populationSize, out dominatedIndividuals, out dominationCounter, out rank));
    78       int i = 0;
     79      var i = 0;
    7980      while (i < fronts.Count && fronts[i].Count > 0) {
    8081        var nextFront = new List<Tuple<T, double[]>>();
     
    8283          List<int> dominatedIndividualsByp;
    8384          if (dominatedIndividuals.TryGetValue(p.Item1, out dominatedIndividualsByp)) {
    84             for (int k = 0; k < dominatedIndividualsByp.Count; k++) {
    85               int dominatedIndividual = dominatedIndividualsByp[k];
     85            for (var k = 0; k < dominatedIndividualsByp.Count; k++) {
     86              var dominatedIndividual = dominatedIndividualsByp[k];
    8687              dominationCounter[dominatedIndividual] -= 1;
    8788              if (dominationCounter[dominatedIndividual] == 0) {
     
    9899    }
    99100
    100     private static List<Tuple<T, double[]>> CalculateBestFront(T[] solutions, double[][] qualities, bool[] maximization, bool dominateOnEqualQualities, int populationSize, out Dictionary<T, List<int>> dominatedIndividuals, out int[] dominationCounter, out int[] rank) {
     101    private static List<Tuple<T, double[]>> CalculateBestFront<T>(T[] solutions, double[][] qualities, bool[] maximization, bool dominateOnEqualQualities, int populationSize, out Dictionary<T, List<int>> dominatedIndividuals, out int[] dominationCounter, out int[] rank) {
    101102      var front = new List<Tuple<T, double[]>>();
    102103      dominatedIndividuals = new Dictionary<T, List<int>>();
    103104      dominationCounter = new int[populationSize];
    104105      rank = new int[populationSize];
    105       for (int pI = 0; pI < populationSize - 1; pI++) {
     106      for (var pI = 0; pI < populationSize - 1; pI++) {
    106107        var p = solutions[pI];
    107108        List<int> dominatedIndividualsByp;
    108109        if (!dominatedIndividuals.TryGetValue(p, out dominatedIndividualsByp))
    109110          dominatedIndividuals[p] = dominatedIndividualsByp = new List<int>();
    110         for (int qI = pI + 1; qI < populationSize; qI++) {
     111        for (var qI = pI + 1; qI < populationSize; qI++) {
    111112          var test = Dominates(qualities[pI], qualities[qI], maximization, dominateOnEqualQualities);
    112113          if (test == DominationResult.Dominates) {
     
    147148      if (dominateOnEqualQualities) {
    148149        var equal = true;
    149         for (int i = 0; i < left.Length; i++) {
     150        for (var i = 0; i < left.Length; i++) {
    150151          if (left[i] != right[i]) {
    151152            equal = false;
     
    157158
    158159      bool leftIsBetter = false, rightIsBetter = false;
    159       for (int i = 0; i < left.Length; i++) {
     160      for (var i = 0; i < left.Length; i++) {
    160161        if (IsDominated(left[i], right[i], maximizations[i])) rightIsBetter = true;
    161162        else if (IsDominated(right[i], left[i], maximizations[i])) leftIsBetter = true;
Note: See TracChangeset for help on using the changeset viewer.