Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/15/14 10:23:34 (10 years ago)
Author:
abeham
Message:

#2174:

  • Removed SimSharp reference (not the purpose of this branch anymore)
  • Fixed bugs regarding parameter names when no parameter have been defined
  • Added a method to the problem definition to retrieve a neighborhood solution
    • Programmable problem now works with LocalSearch and SimulatedAnnealing
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/Datastructures/ParameterVector.cs

    r10850 r11363  
    2222using System.Collections.Generic;
    2323using System.Linq;
     24using HeuristicLab.Common;
    2425using HeuristicLab.Encodings.BinaryVectorEncoding;
    2526using HeuristicLab.Encodings.IntegerVectorEncoding;
     
    2829
    2930namespace HeuristicLab.Problems.Programmable {
    30   public class ParameterVector {
    31     protected Dictionary<string, BinaryVector> BinaryParameters;
    32     protected Dictionary<string, IntegerVector> IntegerParameters;
    33     protected Dictionary<string, RealVector> RealParameters;
    34     protected Dictionary<string, Permutation> PermutationParameters;
     31  public sealed class ParameterVector : IDeepCloneable {
     32    private Dictionary<string, BinaryVector> BinaryParameters;
     33    private Dictionary<string, IntegerVector> IntegerParameters;
     34    private Dictionary<string, RealVector> RealParameters;
     35    private Dictionary<string, Permutation> PermutationParameters;
    3536
    3637    public ParameterVector(IEnumerable<KeyValuePair<string, BinaryVector>> binaryVectors = null,
     
    4243      if (realVectors != null) RealParameters = realVectors.ToDictionary(x => x.Key, x => x.Value);
    4344      if (permutations != null) PermutationParameters = permutations.ToDictionary(x => x.Key, x => x.Value);
     45    }
     46    private ParameterVector(ParameterVector original, Cloner cloner) {
     47      cloner.RegisterClonedObject(original, this);
     48      if (original.BinaryParameters != null) {
     49        BinaryParameters = new Dictionary<string, BinaryVector>(original.BinaryParameters.Comparer);
     50        foreach (var param in original.BinaryParameters)
     51          BinaryParameters[param.Key] = cloner.Clone(param.Value);
     52      }
     53      if (original.IntegerParameters != null) {
     54        IntegerParameters = new Dictionary<string, IntegerVector>(original.IntegerParameters.Comparer);
     55        foreach (var param in original.IntegerParameters)
     56          IntegerParameters[param.Key] = cloner.Clone(param.Value);
     57      }
     58      if (original.RealParameters != null) {
     59        RealParameters = new Dictionary<string, RealVector>(original.RealParameters.Comparer);
     60        foreach (var param in original.RealParameters)
     61          RealParameters[param.Key] = cloner.Clone(param.Value);
     62      }
     63      if (original.PermutationParameters != null) {
     64        PermutationParameters = new Dictionary<string, Permutation>(original.PermutationParameters.Comparer);
     65        foreach (var param in original.PermutationParameters)
     66          PermutationParameters[param.Key] = cloner.Clone(param.Value);
     67      }
     68    }
     69
     70    public object Clone() {
     71      return Clone(new Cloner());
     72    }
     73
     74    public IDeepCloneable Clone(Cloner cloner) {
     75      return new ParameterVector(this, cloner);
    4476    }
    4577
     
    5385
    5486    public IEnumerable<string> BinaryNames {
    55       get { return BinaryParameters.Keys; }
     87      get { return BinaryParameters != null ? BinaryParameters.Keys : Enumerable.Empty<string>(); }
    5688    }
    5789
     
    6597
    6698    public IEnumerable<string> IntegerNames {
    67       get { return IntegerParameters.Keys; }
     99      get { return IntegerParameters != null ? IntegerParameters.Keys : Enumerable.Empty<string>(); }
    68100    }
    69101
     
    77109
    78110    public IEnumerable<string> RealNames {
    79       get { return RealParameters.Keys; }
     111      get { return RealParameters != null ? RealParameters.Keys : Enumerable.Empty<string>(); }
    80112    }
    81113
     
    85117
    86118    public IEnumerable<string> PermutationNames {
    87       get { return PermutationParameters.Keys; }
     119      get { return PermutationParameters != null ? PermutationParameters.Keys : Enumerable.Empty<string>(); }
    88120    }
    89121  }
Note: See TracChangeset for help on using the changeset viewer.