Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/15/17 14:25:44 (7 years ago)
Author:
abeham
Message:

#2457: merged trunk into branch

Location:
branches/PerformanceComparison/HeuristicLab.Optimization
Files:
2 deleted
10 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/PerformanceComparison/HeuristicLab.Optimization

  • branches/PerformanceComparison/HeuristicLab.Optimization/3.3/BasicProblems/Individuals/Individual.cs

    r14600 r15256  
    2121
    2222using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2325using HeuristicLab.Core;
    2426
     
    2729    protected IEncoding Encoding { get; private set; }
    2830    protected IScope Scope { get; private set; }
    29 
    3031    public string Name { get { return Encoding.Name; } }
    3132
     
    3536    }
    3637
    37     public abstract IItem this[string name] { get; set; }
     38    public IItem this[string name] {
     39      get { return ExtractScopeValue(name, Scope); }
     40      set { SetScopeValue(name, Scope, value); }
     41    }
     42
     43    public IEnumerable<KeyValuePair<string, IItem>> Values {
     44      get { return Scope.Variables.Select(v => new KeyValuePair<string, IItem>(v.Name, v.Value)); }
     45    }
    3846    public abstract TEncoding GetEncoding<TEncoding>() where TEncoding : class, IEncoding;
    3947
    40     public Individual Copy() {
    41       return CopyToScope(new Scope());
     48    public abstract Individual Copy();
     49    internal void CopyToScope(IScope scope) {
     50      foreach (var val in Values)
     51        SetScopeValue(val.Key, scope, val.Value);
    4252    }
    4353
    44     public abstract Individual CopyToScope(IScope scope);
    45 
    46     protected static IItem ExtractScopeValue(string name, IScope scope) {
     54    private static IItem ExtractScopeValue(string name, IScope scope) {
     55      if (scope == null) throw new ArgumentNullException("scope");
    4756      if (!scope.Variables.ContainsKey(name)) throw new ArgumentException(string.Format(" {0} cannot be found in the provided scope.", name));
    4857      var value = scope.Variables[name].Value;
     
    5160    }
    5261
    53     protected static void SetScopeValue(string name, IScope scope, IItem value) {
     62    private static void SetScopeValue(string name, IScope scope, IItem value) {
     63      if (scope == null) throw new ArgumentNullException("scope");
    5464      if (value == null) throw new ArgumentNullException("value");
     65
    5566      if (!scope.Variables.ContainsKey(name)) scope.Variables.Add(new Variable(name, value));
    5667      else scope.Variables[name].Value = value;
  • branches/PerformanceComparison/HeuristicLab.Optimization/3.3/BasicProblems/Individuals/MultiEncodingIndividual.cs

    r14600 r15256  
    3232    }
    3333
    34     private readonly IEnumerable<Individual> individuals;
     34    public MultiEncodingIndividual(MultiEncoding encoding, IScope scope)
     35      : base(encoding, scope) { }
    3536
    36     public MultiEncodingIndividual(MultiEncoding encoding, IScope scope)
    37       : base(encoding, scope) {
    38       individuals = encoding.Encodings.Select(e => e.GetIndividual(scope)).ToArray();
     37    private MultiEncodingIndividual(MultiEncodingIndividual copy) : base(copy.Encoding, new Scope()) {
     38      copy.CopyToScope(Scope);
    3939    }
    40 
    41     private MultiEncodingIndividual(MultiEncoding encoding, IScope scope, IEnumerable<Individual> individuals)
    42       : base(encoding, scope) {
    43       this.individuals = individuals;
    44     }
    45 
    46 
    47     public override IItem this[string name] {
    48       get {
    49         var individual = individuals.SingleOrDefault(i => i.Name == name);
    50         if (individual == null) throw new ArgumentException(string.Format("{0} is not part of the specified encoding.", name));
    51         return individual[name];
    52       }
    53       set {
    54         var individual = individuals.SingleOrDefault(i => i.Name == name);
    55         if (individual == null) throw new ArgumentException(string.Format("{0} is not part of the specified encoding.", name));
    56         individual[name] = value;
    57       }
     40    public override Individual Copy() {
     41      return new MultiEncodingIndividual(this);
    5842    }
    5943
     
    6246      try {
    6347        encoding = (TEncoding)Encoding.Encodings.SingleOrDefault(e => e is TEncoding);
    64       } catch (InvalidOperationException) {
     48      }
     49      catch (InvalidOperationException) {
    6550        throw new InvalidOperationException(string.Format("The individual uses multiple {0} .", typeof(TEncoding).GetPrettyName()));
    6651      }
     
    6853      return encoding;
    6954    }
    70 
    71     public override Individual CopyToScope(IScope scope) {
    72       var copies = individuals.Select(i => i.CopyToScope(scope)).ToArray();
    73       return new MultiEncodingIndividual(Encoding, scope, copies);
    74     }
    7555  }
    7656}
  • branches/PerformanceComparison/HeuristicLab.Optimization/3.3/BasicProblems/Individuals/SingleEncodingIndividual.cs

    r14600 r15256  
    3232    }
    3333
    34     public override IItem this[string name] {
    35       get {
    36         if (Name != name) throw new ArgumentException(string.Format("{0} is not part of the individual.", name));
    37         return ExtractScopeValue(Name, Scope);
    38       }
    39       set {
    40         if (Name != name) throw new ArgumentException(string.Format("{0} is not part of the individual.", name));
    41         SetScopeValue(Name, Scope, value);
    42       }
     34    private SingleEncodingIndividual(SingleEncodingIndividual copy) : base(copy.Encoding, new Scope()) {
     35      copy.CopyToScope(Scope);
     36    }
     37    public override Individual Copy() {
     38      return new SingleEncodingIndividual(this);
    4339    }
    4440
     
    4844      return encoding;
    4945    }
    50 
    51     public override Individual CopyToScope(IScope scope) {
    52       SetScopeValue(Name, scope, (IItem)this[Name].Clone());
    53       return new SingleEncodingIndividual(Encoding, scope);
    54     }
    5546  }
    5647
  • branches/PerformanceComparison/HeuristicLab.Optimization/3.3/BasicProblems/MultiObjectiveBasicProblem.cs

    r14600 r15256  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
    2224using System.Linq;
    2325using HeuristicLab.Common;
     
    5759    public abstract double[] Evaluate(Individual individual, IRandom random);
    5860    public virtual void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random) { }
    59 
     61   
    6062    protected override void OnOperatorsChanged() {
    6163      base.OnOperatorsChanged();
     
    7476      if (encoding != null && encoding.Operators.Any(x => x is ISingleObjectiveOperator && !(x is IMultiObjectiveOperator)))
    7577        encoding.Operators = encoding.Operators.Where(x => !(x is ISingleObjectiveOperator) || x is IMultiObjectiveOperator).ToList();
     78
     79      foreach (var multiOp in Encoding.Operators.OfType<IMultiOperator>()) {
     80        foreach (var soOp in multiOp.Operators.Where(x => x is ISingleObjectiveOperator).ToList()) {
     81          multiOp.RemoveOperator(soOp);
     82        }
     83      }
    7684    }
    7785
  • branches/PerformanceComparison/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveBasicProblem.cs

    r14600 r15256  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    8485    }
    8586
     87    protected Tuple<Individual, double> GetBestIndividual(Individual[] individuals, double[] qualities) {
     88      return GetBestIndividual(individuals, qualities, Maximization);
     89    }
     90    public static Tuple<Individual, double> GetBestIndividual(Individual[] individuals, double[] qualities, bool maximization) {
     91      var zipped = individuals.Zip(qualities, (i, q) => new { Individual = i, Quality = q });
     92      var best = (maximization ? zipped.OrderByDescending(z => z.Quality) : zipped.OrderBy(z => z.Quality)).First();
     93      return Tuple.Create(best.Individual, best.Quality);
     94    }
     95
    8696    protected override void OnOperatorsChanged() {
    8797      base.OnOperatorsChanged();
     
    100110      if (encoding.Operators.Any(x => x is IMultiObjectiveOperator && !(x is ISingleObjectiveOperator)))
    101111        encoding.Operators = encoding.Operators.Where(x => !(x is IMultiObjectiveOperator) || x is ISingleObjectiveOperator).ToList();
     112
     113      foreach (var multiOp in Encoding.Operators.OfType<IMultiOperator>()) {
     114        foreach (var moOp in multiOp.Operators.Where(x => x is IMultiObjectiveOperator).ToList()) {
     115          multiOp.RemoveOperator(moOp);
     116        }
     117      }
    102118    }
    103119
  • branches/PerformanceComparison/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj

    r14776 r15256  
    201201    <Compile Include="Interfaces\ILocalImprovementAlgorithmOperator.cs" />
    202202    <Compile Include="Interfaces\IMultiObjectiveOperator.cs" />
     203    <Compile Include="MultiObjective\DominationCalculator.cs" />
    203204    <Compile Include="Interfaces\IPreexistingSolutionCreator.cs" />
    204205    <Compile Include="Interfaces\ISolutionModel.cs" />
     
    240241    <Compile Include="Interfaces\IDiscreteDoubleMatrixModifier.cs" />
    241242    <Compile Include="Algorithms\HeuristicOptimizationEngineAlgorithm.cs" />
    242     <Compile Include="Interfaces\IGlobalParticleUpdater.cs" />
    243243    <Compile Include="Interfaces\ILocalImprovementOperator.cs" />
    244     <Compile Include="Interfaces\ILocalParticleUpdater.cs" />
    245244    <Compile Include="Algorithms\HeuristicOptimizationAlgorithm.cs" />
    246245    <Compile Include="Interfaces\IMultiNeighborhoodShakingOperator.cs" />
  • branches/PerformanceComparison/HeuristicLab.Optimization/3.3/Interfaces/IParticleCreator.cs

    r14600 r15256  
    2727  /// </summary>
    2828  public interface IParticleCreator : ISolutionCreator {
     29    ILookupParameter<ISolutionCreator> SolutionCreatorParameter { get; }
    2930  }
    3031}
  • branches/PerformanceComparison/HeuristicLab.Optimization/3.3/Problems/SingleObjectiveHeuristicOptimizationProblem.cs

  • branches/PerformanceComparison/HeuristicLab.Optimization/3.3/Results/ResultCollection.cs

    r12764 r15256  
    7575    }
    7676
     77    public void AddOrUpdateResult(string name, IItem value) {
     78      IResult res;
     79      if (!TryGetValue(name, out res)) {
     80        res = new Result(name, value);
     81        Add(res);
     82      } else res.Value = value;
     83    }
    7784  }
    7885}
Note: See TracChangeset for help on using the changeset viewer.