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
Location:
branches/SimSharp/HeuristicLab.Problems.Programmable/3.3
Files:
4 added
7 edited

Legend:

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

    r10856 r11363  
    7474      if (min.Count != max.Count) throw new ArgumentException("min must be of the same length as max", "min");
    7575      if (step != null && min.Count != step.Count) throw new ArgumentException("step must be of the same length as min or null", "step");
    76       if (min.Zip(max, (mi, ma) => mi >= ma).Any()) throw new ArgumentException("min must be less than max in each dimension", "min");
     76      if (min.Zip(max, (mi, ma) => mi >= ma).Any(x => x)) throw new ArgumentException("min must be less than max in each dimension", "min");
    7777      this.length = new IntValue(length);
    7878      bounds = new IntMatrix(min.Count, step != null ? 3 : 2);
  • 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  }
  • branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/Datastructures/RealParameterConfiguration.cs

    r10856 r11363  
    7171      if (min.Count == 0) throw new ArgumentException("Bounds must be given for the real parameters.");
    7272      if (min.Count != max.Count) throw new ArgumentException("min must be of the same length as max", "min");
    73       if (min.Zip(max, (mi, ma) => mi >= ma).Any()) throw new ArgumentException("min must be less than max in each dimension", "min");
     73      if (min.Zip(max, (mi, ma) => mi >= ma).Any(x => x)) throw new ArgumentException("min must be less than max in each dimension", "min");
    7474      this.length = new IntValue(length);
    7575      bounds = new DoubleMatrix(min.Count, 2);
  • branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/HeuristicLab.Problems.Programmable-3.3.csproj

    r10856 r11363  
    121121      <Private>False</Private>
    122122    </Reference>
    123     <Reference Include="SimSharp, Version=3.0.3.0, Culture=neutral, PublicKeyToken=4222a9c6c8b27052, processorArchitecture=MSIL">
    124       <SpecificVersion>False</SpecificVersion>
    125       <HintPath>..\..\..\..\trunk\sources\bin\SimSharp.dll</HintPath>
    126       <Private>False</Private>
    127     </Reference>
    128123    <Reference Include="System" />
    129124    <Reference Include="System.Core" />
     
    143138    <Compile Include="Datastructures\ParameterConfiguration.cs" />
    144139    <Compile Include="Datastructures\ParameterVector.cs" />
     140    <Compile Include="Interfaces\IParameterVectorMoveOperator.cs" />
    145141    <Compile Include="Interfaces\ISingleObjectiveProgrammableProblemEvaluator.cs" />
    146142    <Compile Include="Operators\ParameterVectorManipulator.cs" />
    147143    <Compile Include="Operators\ParameterVectorCrossover.cs" />
     144    <Compile Include="Operators\ParameterVectorMoveEvaluator.cs" />
     145    <Compile Include="Operators\ParameterVectorMoveGenerator.cs" />
     146    <Compile Include="Operators\ParameterVectorMoveMaker.cs" />
    148147    <Compile Include="Operators\SingleObjectiveEvaluator.cs" />
    149148    <Compile Include="Operators\ParameterVectorCreater.cs" />
  • branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/Interfaces/ISingleObjectiveProblemDefinition.cs

    r10856 r11363  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using HeuristicLab.Core;
    2324
     
    2627    bool IsMaximizationProblem { get; }
    2728    double Evaluate(IRandom random, ParameterVector vector);
     29    IEnumerable<ParameterVector> GetNeighbors(IRandom random, ParameterVector vector);
    2830  }
    2931}
  • branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblem.cs

    r10856 r11363  
    138138        UpdateMultiVectorEncodingOperators(solutionCreators, configuration);
    139139      }
     140      UpdateMoveOperators();
    140141    }
    141142
     
    597598    }
    598599
     600    protected virtual void UpdateMoveOperators() {
     601      Operators.RemoveAll(x => x is IParameterVectorMoveOperator);
     602      var generator = new ParameterVectorMoveGenerator();
     603      generator.ConfigurationParameter.ActualName = ConfigurationParameter.Name;
     604      generator.ScriptParameter.ActualName = ScriptParameter.Name;
     605
     606      var evaluator = new ParameterVectorMoveEvaluator();
     607      evaluator.ConfigurationParameter.ActualName = ConfigurationParameter.Name;
     608      evaluator.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
     609      evaluator.ScriptParameter.ActualName = ScriptParameter.Name;
     610
     611      var maker = new ParameterVectorMoveMaker();
     612      maker.ConfigurationParameter.ActualName = ConfigurationParameter.Name;
     613      maker.MoveQualityParameter.ActualName = evaluator.MoveQualityParameter.ActualName;
     614      maker.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
     615
     616      Operators.AddRange(new IItem[] { generator, evaluator, maker });
     617    }
     618
    599619    // ReSharper disable RedundantNameQualifier
    600620    protected virtual IBinaryVectorCrossover GetDefaultBinaryCrossover(string paramName, Configuration config) {
  • branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveScript.cs

    r10856 r11363  
    3434    protected SingleObjectiveScript(SingleObjectiveScript original, Cloner cloner)
    3535      : base(original, cloner) { }
    36     public SingleObjectiveScript() { }
     36
     37    public SingleObjectiveScript() {
     38      Code = CodeTemplate;
     39    }
    3740
    3841    public override IDeepCloneable Clone(Cloner cloner) {
     
    7881  }
    7982
     83  public IEnumerable<ParameterVector> GetNeighbors(IRandom random, ParameterVector vector) {
     84    // Create new vectors, based on the given one that represent small changes
     85    // This method is only called from move-based algorithms (LocalSearch, SimulatedAnnealing, etc.)
     86    while (true) {
     87      var neighbor = (ParameterVector)vector.Clone();
     88      //e.g. make a bit flip in a binary parameter
     89      //var bIndex = random.Next(neighbor.Binary(""b"").Length);
     90      //neighbor.Binary(""b"")[bIndex] = !neighbor.Binary(""b"")[bIndex];
     91      yield return neighbor;
     92    }
     93  }
     94
    8095  // implement further classes and methods
    8196}";
Note: See TracChangeset for help on using the changeset viewer.