Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/15/14 22:34:05 (10 years ago)
Author:
abeham
Message:

#2174: minor refactorings

File:
1 copied

Legend:

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

    r10753 r10754  
    2929
    3030namespace HeuristicLab.Problems.Programmable {
    31   [Item("ProgrammableProblemScript", "Script that defines the parameter vector and evaluates the solution.")]
     31  [Item("ProgrammableProblemScript", "Script that defines the parameter vector and evaluates the solution for a programmable problem.")]
    3232  [StorableClass]
    33   public class ProgrammableProblemScript : Script, IStorableContent {
    34     public string Filename { get; set; }
     33  public abstract class ProgrammableProblemScript : Script {
    3534    protected bool SuppressEvents { get; set; }
    3635
     
    4140    public ProgrammableProblemScript() { }
    4241
    43     public override IDeepCloneable Clone(Cloner cloner) {
    44       return new ProgrammableProblemScript(this, cloner);
    45     }
    46 
    47     private volatile ProgrammableProblemBase instance;
     42    private volatile ProblemBase instance;
    4843    private object locker = new object();
    49     public ProgrammableProblemBase Instance {
     44    public ProblemBase Instance {
    5045      get {
    5146        SuppressEvents = true;
     
    7065      protected set {
    7166        instance = value;
    72         OnInstanceChanged();
    73       }
    74     }
    75 
    76     protected override string CodeTemplate {
    77       get {
    78         return @"using System;
    79 using System.Linq;
    80 using System.Collections.Generic;
    81 using HeuristicLab.Common;
    82 using HeuristicLab.Core;
    83 using HeuristicLab.Data;
    84 using HeuristicLab.Encodings.ParameterVectorEncoding;
    85 using HeuristicLab.Encodings.PermutationEncoding;
    86 
    87 public class MyProblem : HeuristicLab.Problems.Programmable.ProgrammableProblemBase {
    88   public MyProblem() {
    89     // initialize private fields
    90   }
    91   public override bool IsMaximizationProblem { get { return false; } }
    92   public override ParameterVector GetParametersToOptimize() {
    93     return new ParameterVectorBuilder()
    94       // .AddBoolean(""Parameter"")
    95       // .AddInteger(""Parameter"", min: 5, max: 15, step: 3)
    96       // .AddReal(""Parameter"", min: 0.0, max: 1.0)
    97       // .SetPermutation(type: PermutationTypes.Absolute, length: 10)
    98     .Build();
    99   }
    100 
    101   public override void EvaluateFeasibility(ParameterVector vector) {
    102     vector.IsFeasible = true
    103     // && vector.Integer(""Parameter1"") < vector.Integer(""Parameter2"");
    104     // && (vector.Real(""Parameter3"") >= 1.0 || (vector.Real(""Parameter3"") < 1.0 && vector.Integer(""Parameter1"") < 5));
    105     ;
    106   }
    107 
    108   public override double Evaluate(IRandom random, ParameterVector vector) {
    109     var quality = 0.0;
    110     return quality;
    111   }
    112 
    113   // implement further classes and methods
    114 }";
     67        if (!SuppressEvents) OnInstanceChanged();
    11568      }
    11669    }
     
    12073      var types = assembly.GetTypes();
    12174      try {
    122         instance = (ProgrammableProblemBase)Activator.CreateInstance(types.First(x => typeof(ProgrammableProblemBase).IsAssignableFrom(x)));
     75        Instance = (ProblemBase)Activator.CreateInstance(types.First(x => typeof(ProblemBase).IsAssignableFrom(x)));
    12376      } catch {
    124         instance = null;
     77        Instance = null;
    12578      }
    126       if (!SuppressEvents) OnInstanceChanged();
    12779      return assembly;
    12880    }
Note: See TracChangeset for help on using the changeset viewer.