Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11900


Ignore:
Timestamp:
02/05/15 10:19:37 (10 years ago)
Author:
abeham
Message:

#2174:

  • Removed compilation calls from the problem (AfterDeserialization and in cloning constructor) and instead compile instance lazily when accessed
  • Compile support code in ExternalEvaluationProblem lazy
  • Fixed encoding class names in template code files (forgot to add vector)
Location:
branches/ProgrammableProblem
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/ProgrammableProblem/HeuristicLab.Problems.ExternalEvaluation/3.4/ExternalEvaluationProblem.cs

    r11899 r11900  
    7979    [StorableConstructor]
    8080    private ExternalEvaluationProblem(bool deserializing) : base(deserializing) { }
    81     private ExternalEvaluationProblem(ExternalEvaluationProblem original, Cloner cloner)
    82       : base(original, cloner) {
    83       CompileSupportScript();
    84     }
     81    private ExternalEvaluationProblem(ExternalEvaluationProblem original, Cloner cloner) : base(original, cloner) { }
    8582    public override IDeepCloneable Clone(Cloner cloner) {
    8683      return new ExternalEvaluationProblem(this, cloner);
     
    9289      Parameters.Add(new ValueParameter<SolutionMessageBuilder>("MessageBuilder", "The message builder that converts from HeuristicLab objects to SolutionMessage representation.", new SolutionMessageBuilder()));
    9390      Parameters.Add(new FixedValueParameter<SingleObjectiveOptimizationSupportScript>("SupportScript", "A script that can provide neighborhood and analyze the results of the optimization.", new SingleObjectiveOptimizationSupportScript()));
    94       CompileSupportScript();
    95     }
    96 
    97     [StorableHook(HookType.AfterDeserialization)]
    98     private void AfterDeserialization() {
    99       CompileSupportScript();
    100     }
    101 
    102     private void CompileSupportScript() {
    103       try {
    104         OptimizationSupportScript.Compile();
    105       } catch (SingleObjectiveOptimizationSupportException ex) {
    106         PluginInfrastructure.ErrorHandling.ShowErrorDialog("Support script doesn't compile.", ex);
    107       }
    10891    }
    10992
  • branches/ProgrammableProblem/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/SingleObjectiveOptimizationSupportScript.cs

    r11893 r11900  
    6262    }
    6363
     64    private readonly object compileLock = new object();
    6465    private volatile ISingleObjectiveOptimizationSupport compiledInstance;
    6566    private ISingleObjectiveOptimizationSupport CompiledInstance {
    6667      get {
    67         if (compiledInstance == null) throw new InvalidOperationException("The problem definition script is not compiled and cannot be used.");
     68        if (compiledInstance == null) {
     69          lock (compileLock) {
     70            if (compiledInstance == null) {
     71              Compile();
     72            }
     73          }
     74        }
    6875        return compiledInstance;
    6976      }
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/MultiObjectiveProgrammableProblem.cs

    r11880 r11900  
    4848      : base(original, cloner) {
    4949      RegisterEvents();
    50       try {
    51         ProblemScript.Compile();
    52       } catch (InvalidOperationException) {
    53         //Compilation error
    54       }
    5550    }
    5651    public override IDeepCloneable Clone(Cloner cloner) { return new MultiObjectiveProgrammableProblem(this, cloner); }
    5752
    58 
    5953    [StorableConstructor]
    6054    private MultiObjectiveProgrammableProblem(bool deserializing) : base(deserializing) { }
    61 
    6255    public MultiObjectiveProgrammableProblem()
    6356      : base() {
     
    6962    private void AfterDeserialization() {
    7063      RegisterEvents();
    71       try {
    72         ProblemScript.Compile();
    73       } catch (InvalidOperationException) {
    74         //Compilation error
    75       }
    7664    }
    7765
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/Scripts/ProblemDefinitionScript.cs

    r11885 r11900  
    5555    }
    5656
    57     private readonly object locker = new object();
     57    private readonly object compileLock = new object();
    5858    private volatile IProblemDefinition compiledProblemDefinition;
    5959    protected IProblemDefinition CompiledProblemDefinition {
    6060      get {
    61         if (compiledProblemDefinition == null) throw new InvalidOperationException("The problem definition script is not compiled and cannot be used.");
     61        // double checked locking pattern
     62        if (compiledProblemDefinition == null) {
     63          lock (compileLock) {
     64            if (compiledProblemDefinition == null) {
     65              Compile(false);
     66            }
     67          }
     68        }
    6269        return compiledProblemDefinition;
    63       }
    64       private set {
    65         compiledProblemDefinition = value;
    66         OnProblemDefinitionChanged();
    6770      }
    6871    }
    6972
    70     public override Assembly Compile() {
     73    public sealed override Assembly Compile() {
     74      return Compile(true);
     75    }
     76
     77    protected virtual Assembly Compile(bool fireChanged) {
    7178      var assembly = base.Compile();
    7279      var types = assembly.GetTypes();
     
    93100
    94101      try {
    95         CompiledProblemDefinition = inst;
     102        compiledProblemDefinition = inst;
     103        if (fireChanged) OnProblemDefinitionChanged();
    96104      } catch (Exception e) {
    97105        compiledProblemDefinition = null;
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/Scripts/Templates/CompiledMultiObjectiveProblemDefinition.cs

    r11880 r11900  
    1616      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    1717      // Define the solution encoding which can also consist of multiple vectors, examples below
    18       //Encoding = new BinaryEncoding("b", length: 5);
    19       //Encoding = new IntegerEncoding("i", length: 5, min: 2, max: 14, step: 4);
    20       //Encoding = new RealEncoding("r", length: 5, min: -1.0, max: 1.0);
     18      //Encoding = new BinaryVectorEncoding("b", length: 5);
     19      //Encoding = new IntegerVectorEncoding("i", length: 5, min: 2, max: 14, step: 4);
     20      //Encoding = new RealVectorEncoding("r", length: 5, min: -1.0, max: 1.0);
    2121      //Encoding = new PermutationEncoding("p", length: 5, type: PermutationTypes.Absolute);
    2222      // The encoding can also be a combination
    2323      //Encoding = new MultiEncoding()
    24       //.Add(new BinaryEncoding("b", length: 5))
    25       //.Add(new IntegerEncoding("i", length: 5, min: 2, max: 14, step: 4))
    26       //.Add(new RealEncoding("r", length: 5, min: -1.0, max: 1.0))
     24      //.Add(new BinaryVectorEncoding("b", length: 5))
     25      //.Add(new IntegerVectorEncoding("i", length: 5, min: 2, max: 14, step: 4))
     26      //.Add(new RealVectorEncoding("r", length: 5, min: -1.0, max: 1.0))
    2727      //.Add(new PermutationEncoding("p", length: 5, type: PermutationTypes.Absolute))
    2828      ;
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/Scripts/Templates/CompiledSingleObjectiveProblemDefinition.cs

    r11880 r11900  
    1616      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    1717      // Define the solution encoding which can also consist of multiple vectors, examples below
    18       //Encoding = new BinaryEncoding("b", length: 5);
    19       //Encoding = new IntegerEncoding("i", length: 5, min: 2, max: 14, step: 2);
    20       //Encoding = new RealEncoding("r", length: 5, min: -1.0, max: 1.0);
     18      //Encoding = new BinaryVectorEncoding("b", length: 5);
     19      //Encoding = new IntegerVectorEncoding("i", length: 5, min: 2, max: 14, step: 2);
     20      //Encoding = new RealVectorEncoding("r", length: 5, min: -1.0, max: 1.0);
    2121      //Encoding = new PermutationEncoding("p", length: 5, type: PermutationTypes.Absolute);
    2222      // The encoding can also be a combination
    2323      //Encoding = new MultiEncoding()
    24       //.Add(new BinaryEncoding("b", length: 5))
    25       //.Add(new IntegerEncoding("i", length: 5, min: 2, max: 14, step: 4))
    26       //.Add(new RealEncoding("r", length: 5, min: -1.0, max: 1.0))
     24      //.Add(new BinaryVectorEncoding("b", length: 5))
     25      //.Add(new IntegerVectorEncoding("i", length: 5, min: 2, max: 14, step: 4))
     26      //.Add(new RealVectorEncoding("r", length: 5, min: -1.0, max: 1.0))
    2727      //.Add(new PermutationEncoding("p", length: 5, type: PermutationTypes.Absolute))
    2828      ;
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/SingleObjectiveProgrammableProblem.cs

    r11885 r11900  
    4949      : base(original, cloner) {
    5050      RegisterEvents();
    51       try {
    52         ProblemScript.Compile();
    53       } catch (ProblemDefinitionScriptException e) {
    54         PluginInfrastructure.ErrorHandling.ShowErrorDialog(e);
    55       }
    5651    }
    5752    public override IDeepCloneable Clone(Cloner cloner) { return new SingleObjectiveProgrammableProblem(this, cloner); }
    5853
    59 
    6054    [StorableConstructor]
    6155    private SingleObjectiveProgrammableProblem(bool deserializing) : base(deserializing) { }
    62 
    6356    public SingleObjectiveProgrammableProblem()
    6457      : base() {
    6558      Parameters.Add(new FixedValueParameter<SingleObjectiveProblemDefinitionScript>("ProblemScript", "Defines the problem.", new SingleObjectiveProblemDefinitionScript() { Name = Name }));
    6659      RegisterEvents();
    67 
    68 
    6960    }
    7061
     
    7263    private void AfterDeserialization() {
    7364      RegisterEvents();
    74       try {
    75         ProblemScript.Compile();
    76       } catch (InvalidOperationException) {
    77         //Compilation error
    78       }
    7965    }
    8066
Note: See TracChangeset for help on using the changeset viewer.