Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11813


Ignore:
Timestamp:
01/21/15 11:54:43 (10 years ago)
Author:
mkommend
Message:

#2174: Updated views and renamed programmable problem to basic problem and added individual extension methods.

Location:
branches/ProgrammableProblem
Files:
7 edited
3 moved

Legend:

Unmodified
Added
Removed
  • branches/ProgrammableProblem/HeuristicLab.Optimization

  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable.Views/3.3/HeuristicLab.Problems.Programmable.Views-3.3.csproj

    r11753 r11813  
    4040  </PropertyGroup>
    4141  <ItemGroup>
    42     <Reference Include="HeuristicLab.CodeEditor-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     42    <Reference Include="HeuristicLab.CodeEditor-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    4343      <SpecificVersion>False</SpecificVersion>
    44       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.CodeEditor-3.3.dll</HintPath>
    45       <Private>False</Private>
     44      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.CodeEditor-3.4.dll</HintPath>
    4645    </Reference>
    4746    <Reference Include="HeuristicLab.Collections-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/HeuristicLab.Problems.Programmable-3.3.csproj

    r11768 r11813  
    148148    <Compile Include="Interfaces\IEncodingOperator.cs" />
    149149    <Compile Include="Interfaces\ISingleObjectiveMoveOperator.cs" />
    150     <Compile Include="New\ProgrammableProblem.cs" />
    151     <Compile Include="New\MultiObjectiveProgrammableProblem.cs" />
     150    <Compile Include="New\BasicProblem.cs" />
     151    <Compile Include="New\MultiObjectiveBasicProblem.cs" />
    152152    <Compile Include="New\MultiObjectiveScriptableProblem.cs" />
    153153    <Compile Include="New\Scripts\Templates\CompiledMultiObjectiveProblemDefinition.cs" />
     
    175175    <Compile Include="New\Scripts\ProblemDefinitionScript.cs" />
    176176    <Compile Include="New\OneMaxNew.cs" />
    177     <Compile Include="New\SingleObjectiveProgrammableProblem.cs" />
     177    <Compile Include="New\SingleObjectiveBasicProblem.cs" />
    178178    <Compile Include="New\SingleObjectiveScriptableProblem.cs" />
    179179    <Compile Include="New\Scripts\MultiObjectiveProblemDefinitionScript.cs" />
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Individuals/Individual.cs

    r11737 r11813  
    4040
    4141    public abstract IItem this[string name] { get; set; }
     42    public abstract TEncoding GetEncoding<TEncoding>() where TEncoding : class, IEncoding;
    4243
    4344    public Individual Copy() {
     
    6263  #region extension methods
    6364  public static class IndividualExtensionMethods {
     65    public static BinaryVector BinaryVector(this Individual individual) {
     66      var encoding = individual.GetEncoding<BinaryEncoding>();
     67      return individual.BinaryVector(encoding.Name);
     68    }
    6469    public static BinaryVector BinaryVector(this Individual individual, string name) {
    6570      return (BinaryVector)individual[name];
     71    }
     72
     73    public static IntegerVector IntegerVector(this Individual individual) {
     74      var encoding = individual.GetEncoding<IntegerEncoding>();
     75      return individual.IntegerVector(encoding.Name);
    6676    }
    6777    public static IntegerVector IntegerVector(this Individual individual, string name) {
    6878      return (IntegerVector)individual[name];
    6979    }
     80
     81    public static Permutation Permutation(this Individual individual) {
     82      var encoding = individual.GetEncoding<PermutationEncoding>();
     83      return individual.Permutation(encoding.Name);
     84    }
    7085    public static Permutation Permutation(this Individual individual, string name) {
    7186      return (Permutation)individual[name];
     87    }
     88
     89    public static RealVector RealVector(this Individual individual) {
     90      var encoding = individual.GetEncoding<RealEncoding>();
     91      return individual.RealVector(encoding.Name);
    7292    }
    7393    public static RealVector RealVector(this Individual individual, string name) {
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Individuals/MultiEncodingIndividual.cs

    r11737 r11813  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    2627
     
    4647    public override IItem this[string name] {
    4748      get {
    48         var individual = individuals.FirstOrDefault(i => i.Name == name);
     49        var individual = individuals.SingleOrDefault(i => i.Name == name);
    4950        if (individual == null) throw new ArgumentException(string.Format("{0} is not part of the specified encoding.", name));
    5051        return individual[name];
    5152      }
    5253      set {
    53         var individual = individuals.FirstOrDefault(i => i.Name == name);
     54        var individual = individuals.SingleOrDefault(i => i.Name == name);
    5455        if (individual == null) throw new ArgumentException(string.Format("{0} is not part of the specified encoding.", name));
    5556        individual[name] = value;
    5657      }
     58    }
     59
     60    public override TEncoding GetEncoding<TEncoding>() {
     61      TEncoding encoding;
     62      try {
     63        encoding = (TEncoding)Encoding.Encodings.SingleOrDefault(e => e is TEncoding);
     64      }
     65      catch (InvalidOperationException) {
     66        throw new InvalidOperationException(string.Format("The individual uses multiple {0} .", typeof(TEncoding).GetPrettyName()));
     67      }
     68      if (encoding == null) throw new InvalidOperationException(string.Format("The individual does not use a {0}.", typeof(TEncoding).GetPrettyName()));
     69      return encoding;
    5770    }
    5871
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Individuals/SingleEncodingIndividual.cs

    r11619 r11813  
    2121
    2222using System;
     23using HeuristicLab.Common;
    2324using HeuristicLab.Core;
    2425
     
    4243    }
    4344
     45    public override TEncoding GetEncoding<TEncoding>() {
     46      TEncoding encoding = Encoding as TEncoding;
     47      if (encoding == null) throw new InvalidOperationException(string.Format("The individual does not use a {0}.", typeof(TEncoding).GetPrettyName()));
     48      return encoding;
     49    }
     50
    4451    internal override Individual Copy(IScope scope) {
    4552      SetScopeValue(Name, scope, (IItem)this[Name].Clone());
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/BasicProblem.cs

    r11798 r11813  
    103103      Parameters.Add(solutionCreatorParam);
    104104
    105       //TODO register solution creator changed event
     105      //TODO register solution creator changed event, change access modifier to private
     106      //((IValueParameter)solutionCreatorParam).ValueChanged += SolutionCreatorParameter_ValueChanged;     
    106107
    107108      OnOperatorsChanged();
     
    132133
    133134      var comparer = new TypeEqualityComparer<IOperator>();
     135      var cloner = new Cloner();
    134136      var oldOperators = oldEncoding.Operators;
    135137      var newOperators = newEncoding.Operators;
    136138
    137       var operators = oldOperators.Intersect(newOperators, comparer);
    138       //TODO clone overlapping operators
     139
     140      var operators = oldOperators.Intersect(newOperators, comparer).Select(op => cloner.Clone(op));
    139141      operators = operators.Union(newOperators, comparer);
    140142
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/OneMaxNew.cs

    r11797 r11813  
    2121
    2222using System.Linq;
     23using HeuristicLab.Analysis;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
     26using HeuristicLab.Encodings.BinaryVectorEncoding;
     27using HeuristicLab.Optimization;
    2528using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2629
     
    3740      : base() {
    3841      Encoding = new BinaryEncoding("BinaryVector", 10);
     42      var bestScopeSolutionAnalyzer = Operators.OfType<BestScopeSolutionAnalyzer>().FirstOrDefault();
     43      if (bestScopeSolutionAnalyzer != null) Operators.Remove(bestScopeSolutionAnalyzer);
    3944    }
    4045
     
    4752    }
    4853    public override double Evaluate(Individual individual, IRandom random) {
    49       return individual.BinaryVector("BinaryVector").Count(b => b);
     54      return individual.BinaryVector().Count(b => b);
    5055    }
    5156
    52 
     57    public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results) {
     58      base.Analyze(individuals, qualities, results);
     59      var best = individuals.Zip(qualities, (i, q) => new { Individual = i, Quality = q }).OrderByDescending(z => z.Quality).First();
     60      if (!results.ContainsKey("Best Solution")) {
     61        results.Add(new Result("Best Solution", typeof(BinaryVector)));
     62      }
     63      results["Best Solution"].Value = best.Individual.BinaryVector();
     64    }
    5365  }
    5466}
Note: See TracChangeset for help on using the changeset viewer.