Changeset 11393


Ignore:
Timestamp:
09/26/14 22:57:18 (8 years ago)
Author:
abeham
Message:

#2174: enabled possibility to set different problem definitions than just scripted ones

Location:
branches/ProgrammableProblem
Files:
4 added
2 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable.Views/3.3/ProgrammableProblemView.cs

    r10753 r11393  
    2424using HeuristicLab.Core.Views;
    2525using HeuristicLab.MainForm;
    26 using HeuristicLab.Scripting.Views;
     26using HeuristicLab.MainForm.WindowsForms;
    2727
    2828namespace HeuristicLab.Problems.Programmable.Views {
     
    3030  [Content(typeof(SingleObjectiveProgrammableProblem), true)]
    3131  public partial class ProgrammableProblemView : ItemView {
    32     protected ScriptView ScriptView;
     32    protected ViewHost DefinitionView;
    3333
    3434    public new SingleObjectiveProgrammableProblem Content {
     
    3939    public ProgrammableProblemView() {
    4040      InitializeComponent();
    41       ScriptView = new ScriptView { Dock = DockStyle.Fill };
    42       Controls.Add(ScriptView);
     41      DefinitionView = new ViewHost() { ViewsLabelVisible = false, Dock = DockStyle.Fill };
     42      Controls.Add(DefinitionView);
    4343    }
    4444
     
    4646      base.OnContentChanged();
    4747      if (Content == null) {
    48         ScriptView.Content = null;
     48        DefinitionView.Content = null;
    4949      } else {
    50         ScriptView.Content = Content.ScriptParameter.Value;
     50        DefinitionView.Content = Content.ProblemDefinitionParameter.Value;
    5151        Caption = Content.Name;
    5252      }
     
    5454
    5555    protected override void RegisterContentEvents() {
    56       Content.ScriptParameter.ValueChanged += ScriptParameterOnValueChanged;
     56      Content.ProblemDefinitionParameter.ValueChanged += ProblemDefinitionParameterOnValueChanged;
    5757      Content.NameChanged += ContentOnNameChanged;
    5858      base.RegisterContentEvents();
     
    6161    protected override void DeregisterContentEvents() {
    6262      base.DeregisterContentEvents();
    63       Content.ScriptParameter.ValueChanged -= ScriptParameterOnValueChanged;
     63      Content.ProblemDefinitionParameter.ValueChanged -= ProblemDefinitionParameterOnValueChanged;
    6464      Content.NameChanged -= ContentOnNameChanged;
    6565    }
    6666
    67     private void ScriptParameterOnValueChanged(object sender, EventArgs eventArgs) {
    68       ScriptView.Content = Content.ScriptParameter.Value;
     67    private void ProblemDefinitionParameterOnValueChanged(object sender, EventArgs eventArgs) {
     68      DefinitionView.Content = Content.ProblemDefinitionParameter.Value;
    6969    }
    7070
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/HeuristicLab.Problems.Programmable-3.3.csproj

    r11363 r11393  
    139139    <Compile Include="Datastructures\ParameterVector.cs" />
    140140    <Compile Include="Interfaces\IParameterVectorMoveOperator.cs" />
     141    <Compile Include="Interfaces\ISingleObjectiveProblemDefinitionHost.cs" />
    141142    <Compile Include="Interfaces\ISingleObjectiveProgrammableProblemEvaluator.cs" />
    142143    <Compile Include="Operators\ParameterVectorManipulator.cs" />
     
    149150    <Compile Include="Interfaces\IProblemDefinition.cs" />
    150151    <Compile Include="Interfaces\ISingleObjectiveProblemDefinition.cs" />
    151     <Compile Include="ProgrammableProblemScript.cs" />
    152     <Compile Include="SingleObjectiveScript.cs" />
     152    <Compile Include="ProblemDefinitionScript.cs" />
     153    <Compile Include="SingleObjectiveProblemDefinition.cs" />
     154    <Compile Include="SingleObjectiveProblemDefinitionScript.cs" />
    153155    <Compile Include="SingleObjectiveProgrammableProblem.cs" />
    154156    <None Include="HeuristicLab.snk" />
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Interfaces/IProblemDefinition.cs

    r10856 r11393  
    2020#endregion
    2121
     22
    2223namespace HeuristicLab.Problems.Programmable {
    2324  public interface IProblemDefinition {
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Interfaces/ISingleObjectiveProblemDefinition.cs

    r11363 r11393  
    2222using System.Collections.Generic;
    2323using HeuristicLab.Core;
     24using HeuristicLab.Optimization;
    2425
    2526namespace HeuristicLab.Problems.Programmable {
     
    2728    bool IsMaximizationProblem { get; }
    2829    double Evaluate(IRandom random, ParameterVector vector);
     30    void Analyze(ParameterVector[] vectors, double[] qualities, ResultCollection results);
    2931    IEnumerable<ParameterVector> GetNeighbors(IRandom random, ParameterVector vector);
    3032  }
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/ParameterVectorMoveEvaluator.cs

    r11363 r11393  
    4343    }
    4444
    45     public ILookupParameter<SingleObjectiveScript> ScriptParameter {
    46       get { return (ILookupParameter<SingleObjectiveScript>)Parameters["Script"]; }
     45    public ILookupParameter<ISingleObjectiveProblemDefinitionHost> ProblemDefinitionParameter {
     46      get { return (ILookupParameter<ISingleObjectiveProblemDefinitionHost>)Parameters["ProblemDefinition"]; }
    4747    }
    4848
     
    6464    public ParameterVectorMoveEvaluator() {
    6565      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use."));
    66       Parameters.Add(new LookupParameter<SingleObjectiveScript>("Script", "The script that will execute the evaluation function and define the parameter vector."));
     66      Parameters.Add(new LookupParameter<ISingleObjectiveProblemDefinitionHost>("ProblemDefinition", "The host that holds the problem definition."));
    6767      Parameters.Add(new LookupParameter<Configuration>("Configuration", "An item that holds the problem's configuration."));
    6868      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the parameter vector."));
     
    7676    public override IOperation InstrumentedApply() {
    7777      var random = RandomParameter.ActualValue;
    78       var runner = ScriptParameter.ActualValue;
    79       if (runner.Instance == null) throw new InvalidOperationException("Script instance is null, maybe the code doesn't compile.");
     78      var host = ProblemDefinitionParameter.ActualValue;
     79      if (host.Instance == null) throw new InvalidOperationException("Problem definition instance is null.");
    8080      var config = ConfigurationParameter.ActualValue;
    8181      var binDict = new Dictionary<string, BinaryVector>();
     
    111111        realVectors: realDict.Count > 0 ? realDict : null,
    112112        permutations: permDict.Count > 0 ? permDict : null);
    113       MoveQualityParameter.ActualValue = new DoubleValue(runner.Instance.Evaluate(random, vector));
     113      MoveQualityParameter.ActualValue = new DoubleValue(host.Instance.Evaluate(random, vector));
    114114      return base.InstrumentedApply();
    115115    }
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/ParameterVectorMoveGenerator.cs

    r11363 r11393  
    4848    }
    4949
    50     public ILookupParameter<SingleObjectiveScript> ScriptParameter {
    51       get { return (ILookupParameter<SingleObjectiveScript>)Parameters["Script"]; }
     50    public ILookupParameter<ISingleObjectiveProblemDefinitionHost> ProblemDefinitionParameter {
     51      get { return (ILookupParameter<ISingleObjectiveProblemDefinitionHost>)Parameters["ProblemDefinition"]; }
    5252    }
    5353
     
    6363      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use."));
    6464      Parameters.Add(new ValueLookupParameter<IntValue>("SampleSize", "The number of moves to sample."));
    65       Parameters.Add(new LookupParameter<SingleObjectiveScript>("Script", "The script that will execute the evaluation function and define the parameter vector."));
     65      Parameters.Add(new LookupParameter<ISingleObjectiveProblemDefinitionHost>("ProblemDefinition", "The host that holds the problem definition."));
    6666      Parameters.Add(new LookupParameter<Configuration>("Configuration", "An item that holds the problem's configuration."));
    6767    }
     
    7373    public override IOperation InstrumentedApply() {
    7474      var random = RandomParameter.ActualValue;
    75       var runner = ScriptParameter.ActualValue;
    76       if (runner.Instance == null) throw new InvalidOperationException("Script instance is null, maybe the code doesn't compile.");
     75      var host = ProblemDefinitionParameter.ActualValue;
     76      if (host.Instance == null) throw new InvalidOperationException("Problem definition instance is null.");
    7777      var sampleSize = SampleSizeParameter.ActualValue.Value;
    7878      var config = ConfigurationParameter.ActualValue;
     
    109109        realVectors: realDict.Count > 0 ? realDict : null,
    110110        permutations: permDict.Count > 0 ? permDict : null);
    111       var nbhood = runner.Instance.GetNeighbors(random, vector).Take(sampleSize).ToList();
     111      var nbhood = host.Instance.GetNeighbors(random, vector).Take(sampleSize).ToList();
    112112
    113113      var moveScopes = new Scope[nbhood.Count];
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/ParameterVectorMoveMaker.cs

    r11363 r11393  
    5050    protected ParameterVectorMoveMaker(ParameterVectorMoveMaker original, Cloner cloner) : base(original, cloner) { }
    5151    public ParameterVectorMoveMaker() {
    52       Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use."));
    53       Parameters.Add(new LookupParameter<SingleObjectiveScript>("Script", "The script that will execute the evaluation function and define the parameter vector."));
    5452      Parameters.Add(new LookupParameter<Configuration>("Configuration", "An item that holds the problem's configuration."));
    5553      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the parameter vector."));
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/SingleObjectiveEvaluator.cs

    r10850 r11393  
    4343    }
    4444
    45     public ILookupParameter<SingleObjectiveScript> ScriptParameter {
    46       get { return (ILookupParameter<SingleObjectiveScript>)Parameters["Script"]; }
     45    public ILookupParameter<ISingleObjectiveProblemDefinitionHost> ProblemDefinitionParameter {
     46      get { return (ILookupParameter<ISingleObjectiveProblemDefinitionHost>)Parameters["ProblemDefinition"]; }
    4747    }
    4848
     
    6060    public SingleObjectiveEvaluator() {
    6161      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use."));
    62       Parameters.Add(new LookupParameter<SingleObjectiveScript>("Script", "The script that will execute the evaluation function and define the parameter vector."));
     62      Parameters.Add(new LookupParameter<ISingleObjectiveProblemDefinitionHost>("ProblemDefinition", "The host that holds the problem definition."));
    6363      Parameters.Add(new LookupParameter<Configuration>("Configuration", "An item that holds the problem's configuration."));
    6464      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the parameter vector."));
     
    7171    public override IOperation Apply() {
    7272      var random = RandomParameter.ActualValue;
    73       var runner = ScriptParameter.ActualValue;
    74       if (runner.Instance == null) throw new InvalidOperationException("Script instance is null, maybe the code doesn't compile.");
     73      var host = ProblemDefinitionParameter.ActualValue;
     74      if (host.Instance == null) throw new InvalidOperationException("Script instance is null, maybe the code doesn't compile.");
    7575      var config = ConfigurationParameter.ActualValue;
    7676      var binDict = new Dictionary<string, BinaryVector>();
     
    106106        realVectors: realDict.Count > 0 ? realDict : null,
    107107        permutations: permDict.Count > 0 ? permDict : null);
    108       QualityParameter.ActualValue = new DoubleValue(runner.Instance.Evaluate(random, vector));
     108      QualityParameter.ActualValue = new DoubleValue(host.Instance.Evaluate(random, vector));
    109109      return base.Apply();
    110110    }
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblem.cs

    r11363 r11393  
    5555    }
    5656
    57     public IValueParameter<SingleObjectiveScript> ScriptParameter {
    58       get { return (IValueParameter<SingleObjectiveScript>)Parameters["Script"]; }
    59     }
    60 
    61     public IValueParameter<Configuration> ConfigurationParameter {
     57    public IValueParameter<ISingleObjectiveProblemDefinitionHost> ProblemDefinitionParameter {
     58      get { return (IValueParameter<ISingleObjectiveProblemDefinitionHost>)Parameters["ProblemDefinition"]; }
     59    }
     60
     61    protected IValueParameter<Configuration> ConfigurationParameter {
    6262      get { return (IValueParameter<Configuration>)Parameters["Configuration"]; }
     63    }
     64
     65    public ISingleObjectiveProblemDefinitionHost ProblemDefinition {
     66      get { return ProblemDefinitionParameter.Value; }
     67      set { ProblemDefinitionParameter.Value = value; }
    6368    }
    6469
     
    7681    public SingleObjectiveProgrammableProblem()
    7782      : base(new SingleObjectiveEvaluator(), new ParameterVectorCreater()) {
    78       Parameters.Add(new ValueParameter<SingleObjectiveScript>("Script", "Defines the problem.", new SingleObjectiveScript() { Name = Name }));
     83      Parameters.Add(new ValueParameter<ISingleObjectiveProblemDefinitionHost>("ProblemDefinition", "Defines the problem.", new SingleObjectiveProblemDefinitionScript() { Name = Name }));
    7984      Parameters.Add(new ValueParameter<Configuration>("Configuration", "Describes which parameters exist, what they're called, what type they are and their bounds if any."));
    8085
     
    100105
    101106    private void RegisterEventHandlers() {
    102       ScriptParameter.ValueChanged += ScriptParameterOnValueChanged;
    103       RegisterScriptInstanceChanges();
    104     }
    105 
    106     private void ScriptParameterOnValueChanged(object sender, EventArgs eventArgs) {
    107       RegisterScriptInstanceChanges();
    108     }
    109 
    110     private void RegisterScriptInstanceChanges() {
    111       ScriptParameter.Value.InstanceChanged += ScriptOnInstanceChanged;
    112       ScriptParameter.Value.NameChanged += ScriptOnNameChanged;
    113     }
    114 
    115     private void ScriptOnNameChanged(object sender, EventArgs eventArgs) {
    116       if (sender != ScriptParameter.Value) return;
    117       Name = ScriptParameter.Value.Name;
     107      ProblemDefinitionParameter.ValueChanged += ProblemDefinitionParameterOnValueChanged;
     108      RegisterHostInstanceChanges();
     109    }
     110
     111    private void ProblemDefinitionParameterOnValueChanged(object sender, EventArgs eventArgs) {
     112      RegisterHostInstanceChanges();
     113      Parameterize();
     114    }
     115
     116    private void RegisterHostInstanceChanges() {
     117      ProblemDefinitionParameter.Value.InstanceChanged += ProblemDefinitionHostOnInstanceChanged;
     118      ProblemDefinitionParameter.Value.NameChanged += ProblemDefinitionHostOnNameChanged;
     119    }
     120
     121    private void ProblemDefinitionHostOnNameChanged(object sender, EventArgs eventArgs) {
     122      if (sender != ProblemDefinitionParameter.Value) return;
     123      Name = ProblemDefinitionParameter.Value.Name;
    118124    }
    119125
    120126    protected override void OnNameChanged() {
    121127      base.OnNameChanged();
    122       ScriptParameter.Value.Name = Name;
    123     }
    124 
    125     protected virtual void ScriptOnInstanceChanged(object sender, EventArgs eventArgs) {
    126       var instance = ScriptParameter.Value.Instance;
     128      ProblemDefinitionParameter.Value.Name = Name;
     129    }
     130
     131    protected virtual void ProblemDefinitionHostOnInstanceChanged(object sender, EventArgs eventArgs) {
     132      Parameterize();
     133    }
     134
     135    protected virtual void Parameterize() {
     136      var instance = ProblemDefinitionParameter.Value.Instance;
    127137      if (instance == null) return;
    128138
    129       var configuration = instance.GetConfiguration();
     139      Configuration configuration;
     140      try {
     141        configuration = instance.GetConfiguration();
     142      } catch { return; }
    130143      ConfigurationParameter.Value = configuration;
    131144      Maximization.Value = instance.IsMaximizationProblem;
     
    602615      var generator = new ParameterVectorMoveGenerator();
    603616      generator.ConfigurationParameter.ActualName = ConfigurationParameter.Name;
    604       generator.ScriptParameter.ActualName = ScriptParameter.Name;
     617      generator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;
    605618
    606619      var evaluator = new ParameterVectorMoveEvaluator();
    607620      evaluator.ConfigurationParameter.ActualName = ConfigurationParameter.Name;
    608621      evaluator.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
    609       evaluator.ScriptParameter.ActualName = ScriptParameter.Name;
     622      evaluator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;
    610623
    611624      var maker = new ParameterVectorMoveMaker();
Note: See TracChangeset for help on using the changeset viewer.