Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11397


Ignore:
Timestamp:
09/28/14 09:18:30 (10 years ago)
Author:
abeham
Message:

#2174:

  • Renamed methods from e.g. Configuration.AddReal to Configuration.AddRealVector
  • Introduced the variable store into the single-objective problem definition script
  • Created a base class for problem definitions that are derived from in code
  • Created a view for problem definition scripts that also includes the variable store
    • It looks like a C# script view, but unfortunately, the content types are not compatible
Location:
branches/ProgrammableProblem
Files:
3 added
9 edited

Legend:

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

    r10753 r11397  
    3838  </PropertyGroup>
    3939  <ItemGroup>
     40    <Reference Include="HeuristicLab.CodeEditor-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     41      <SpecificVersion>False</SpecificVersion>
     42      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.CodeEditor-3.3.dll</HintPath>
     43      <Private>False</Private>
     44    </Reference>
     45    <Reference Include="HeuristicLab.Collections-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     46      <SpecificVersion>False</SpecificVersion>
     47      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Collections-3.3.dll</HintPath>
     48      <Private>False</Private>
     49    </Reference>
    4050    <Reference Include="HeuristicLab.Common-3.3">
    4151      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Common-3.3.dll</HintPath>
     
    98108  <ItemGroup>
    99109    <Compile Include="Plugin.cs" />
     110    <Compile Include="ProblemDefinitionScriptView.cs">
     111      <SubType>UserControl</SubType>
     112    </Compile>
     113    <Compile Include="ProblemDefinitionScriptView.Designer.cs">
     114      <DependentUpon>ProblemDefinitionScriptView.cs</DependentUpon>
     115    </Compile>
    100116    <Compile Include="ProgrammableProblemView.cs">
    101117      <SubType>UserControl</SubType>
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Datastructures/Configuration.cs

    r10856 r11397  
    5454
    5555
    56     public Configuration AddBinary(string name, int length) {
     56    public Configuration AddBinaryVector(string name, int length) {
    5757      if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name");
    5858      Parameters.Add(name, new BinaryParameterConfiguration(length));
     
    6060    }
    6161
    62     public Configuration AddInteger(string name, int length, int min, int max, int? step = null) {
     62    public Configuration AddIntegerVector(string name, int length, int min, int max, int? step = null) {
    6363      if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name");
    6464      Parameters.Add(name, new IntegerParameterConfiguration(length, min, max, step));
     
    6666    }
    6767
    68     public Configuration AddInteger(string name, int length, IList<int> min, IList<int> max, IList<int> step = null) {
     68    public Configuration AddIntegerVector(string name, int length, IList<int> min, IList<int> max, IList<int> step = null) {
    6969      if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name");
    7070      Parameters.Add(name, new IntegerParameterConfiguration(length, min, max, step));
     
    7272    }
    7373
    74     public Configuration AddReal(string name, int length, double min, double max) {
     74    public Configuration AddRealVector(string name, int length, double min, double max) {
    7575      if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name");
    7676      Parameters.Add(name, new RealParameterConfiguration(length, min, max));
     
    7878    }
    7979
    80     public Configuration AddReal(string name, int length, IList<double> min, IList<double> max) {
     80    public Configuration AddRealVector(string name, int length, IList<double> min, IList<double> max) {
    8181      if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name");
    8282      Parameters.Add(name, new RealParameterConfiguration(length, min, max));
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Datastructures/ParameterVector.cs

    r11363 r11397  
    7676    }
    7777
    78     public BinaryVector Binary(string name) {
     78    public BinaryVector BinaryVector(string name) {
    7979      return BinaryParameters[name];
    8080    }
    8181
    82     public bool Binary(string name, int index) {
     82    public bool BinaryValue(string name, int index) {
    8383      return BinaryParameters[name][index];
    8484    }
     
    8888    }
    8989
    90     public IntegerVector Integer(string name) {
     90    public IntegerVector IntegerVector(string name) {
    9191      return IntegerParameters[name];
    9292    }
    9393
    94     public int Integer(string name, int index) {
     94    public int IntegerValue(string name, int index) {
    9595      return IntegerParameters[name][index];
    9696    }
     
    100100    }
    101101
    102     public RealVector Real(string name) {
     102    public RealVector RealVector(string name) {
    103103      return RealParameters[name];
    104104    }
    105105
    106     public double Real(string name, int index) {
     106    public double RealValue(string name, int index) {
    107107      return RealParameters[name][index];
    108108    }
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/HeuristicLab.Problems.Programmable-3.3.csproj

    r11396 r11397  
    153153    <Compile Include="Interfaces\IProblemDefinition.cs" />
    154154    <Compile Include="Interfaces\ISingleObjectiveProblemDefinition.cs" />
     155    <Compile Include="ProblemDefinition.cs" />
    155156    <Compile Include="ProblemDefinitionScript.cs" />
    156157    <Compile Include="SingleObjectiveProblemDefinition.cs" />
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Interfaces/IProblemDefinition.cs

    r11393 r11397  
    2323namespace HeuristicLab.Problems.Programmable {
    2424  public interface IProblemDefinition {
     25    dynamic vars { get; set; }
     26    void Initialize();
    2527    Configuration GetConfiguration();
    2628  }
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/ParameterVectorMoveGenerator.cs

    r11396 r11397  
    7979        moveScopes[i] = new Scope(i.ToString());
    8080        foreach (var param in nbhood[i].BinaryNames)
    81           moveScopes[i].Variables.Add(new Variable(param, nbhood[i].Binary(param)));
     81          moveScopes[i].Variables.Add(new Variable(param, nbhood[i].BinaryVector(param)));
    8282
    8383        foreach (var param in nbhood[i].IntegerNames)
    84           moveScopes[i].Variables.Add(new Variable(param, nbhood[i].Integer(param)));
     84          moveScopes[i].Variables.Add(new Variable(param, nbhood[i].IntegerVector(param)));
    8585
    8686        foreach (var param in nbhood[i].RealNames)
    87           moveScopes[i].Variables.Add(new Variable(param, nbhood[i].Real(param)));
     87          moveScopes[i].Variables.Add(new Variable(param, nbhood[i].RealVector(param)));
    8888
    8989        foreach (var param in nbhood[i].PermutationNames)
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/ProblemDefinitionScript.cs

    r11393 r11397  
    3434    protected bool SuppressEvents { get; set; }
    3535
     36    [Storable]
     37    private VariableStore variableStore;
     38    public VariableStore VariableStore {
     39      get { return variableStore; }
     40    }
     41
    3642    [StorableConstructor]
    3743    protected ProblemDefinitionScript(bool deserializing) : base(deserializing) { }
    3844    protected ProblemDefinitionScript(ProblemDefinitionScript original, Cloner cloner)
    39       : base(original, cloner) { }
    40     public ProblemDefinitionScript() { }
     45      : base(original, cloner) {
     46      variableStore = cloner.Clone(original.variableStore);
     47    }
     48    protected ProblemDefinitionScript() {
     49      variableStore = new VariableStore();
     50    }
    4151
    4252    private volatile IProblemDefinition instance;
     
    7484      try {
    7585        Instance = (IProblemDefinition)Activator.CreateInstance(types.First(x => typeof(IProblemDefinition).IsAssignableFrom(x)));
     86        Instance.vars = new Variables(VariableStore);
     87        Instance.Initialize();
    7688      } catch {
    7789        Instance = null;
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProblemDefinition.cs

    r11393 r11397  
    3030  [Item("Single-objective Problem Definition", "This definition can be dynamically created through code and assigned to the problem.")]
    3131  public class SingleObjectiveProblemDefinition : ISingleObjectiveProblemDefinitionHost, ISingleObjectiveProblemDefinition {
    32 
    3332    private bool isMaximizationProblem;
    3433    public bool IsMaximizationProblem {
     
    114113
    115114    #region Problem definition explicit interface implementations
     115    dynamic IProblemDefinition.vars { get; set; }
     116
     117    void IProblemDefinition.Initialize() {
     118
     119    }
     120
     121    Configuration IProblemDefinition.GetConfiguration() {
     122      return Configuration();
     123    }
     124
    116125    bool ISingleObjectiveProblemDefinition.IsMaximizationProblem {
    117126      get { return IsMaximizationProblem; }
     
    128137    IEnumerable<ParameterVector> ISingleObjectiveProblemDefinition.GetNeighbors(IRandom random, ParameterVector vector) {
    129138      return Neighbors(random, vector);
    130     }
    131 
    132     Configuration IProblemDefinition.GetConfiguration() {
    133       return Configuration();
    134139    }
    135140    #endregion
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProblemDefinitionScript.cs

    r11393 r11397  
    6060using HeuristicLab.Problems.Programmable;
    6161
    62 public class ProblemDefinition : ISingleObjectiveProblemDefinition {
    63   public ProblemDefinition() {
    64     // initialize private fields
     62public class CustomProblemDefinition : ProblemDefinition, ISingleObjectiveProblemDefinition {
     63  public bool IsMaximizationProblem { get { return false; } }
     64
     65  public override void Initialize() {
     66    // when the definition is created here you can initialize variables in the variable store
    6567  }
    6668
    67   public bool IsMaximizationProblem { get { return false; } }
    68 
    69   public Configuration GetConfiguration() {
     69  public override Configuration GetConfiguration() {
    7070    return new Configuration()
    71       // .AddBinary(""b"", length: 5)
    72       // .AddInteger(""i"", length: 5, min: 2, max: 14, step: 4)
    73       // .AddReal(""r"", length: 5, min: -1.0, max: 1.0)
     71      // .AddBinaryVector(""b"", length: 5)
     72      // .AddIntegerVector(""i"", length: 5, min: 2, max: 14, step: 4)
     73      // .AddRealVector(""r"", length: 5, min: -1.0, max: 1.0)
    7474      // .AddPermutation(""P"", length: 5, type: PermutationTypes.Absolute)
    7575    ;
     
    7878  public double Evaluate(IRandom random, ParameterVector vector) {
    7979    var quality = 0.0;
    80     // quality = vector.Real(""r"").Sum(x => x * x);
     80    // use vars.yourVariable to access variables in the variable store i.e. yourVariable
     81    // quality = vector.RealVector(""r"").Sum(x => x * x);
    8182    return quality;
    8283  }
     
    8485  public void Analyze(ParameterVector[] vectors, double[] qualities, ResultCollection results) {
    8586    // write or update results given the range of vectors and resulting qualities
     87    // use e.g. vars.yourVariable to access variables in the variable store i.e. yourVariable
    8688  }
    8789
     
    9092    // This method is only called from move-based algorithms (LocalSearch, SimulatedAnnealing, etc.)
    9193    while (true) {
     94      // this is not an infinite loop as only a finite amount of samples will be drawn
     95      // it is possible to return a concrete amount of neighbors also
    9296      var neighbor = (ParameterVector)vector.Clone();
    9397      //e.g. make a bit flip in a binary parameter
    94       //var bIndex = random.Next(neighbor.Binary(""b"").Length);
    95       //neighbor.Binary(""b"")[bIndex] = !neighbor.Binary(""b"")[bIndex];
     98      //var bIndex = random.Next(neighbor.BinaryVector(""b"").Length);
     99      //neighbor.BinaryVector(""b"")[bIndex] = !neighbor.BinaryVector(""b"")[bIndex];
    96100      yield return neighbor;
    97       yield break;
    98101    }
    99102  }
Note: See TracChangeset for help on using the changeset viewer.