Changeset 11900
- Timestamp:
- 02/05/15 10:19:37 (10 years ago)
- Location:
- branches/ProgrammableProblem
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProgrammableProblem/HeuristicLab.Problems.ExternalEvaluation/3.4/ExternalEvaluationProblem.cs
r11899 r11900 79 79 [StorableConstructor] 80 80 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) { } 85 82 public override IDeepCloneable Clone(Cloner cloner) { 86 83 return new ExternalEvaluationProblem(this, cloner); … … 92 89 Parameters.Add(new ValueParameter<SolutionMessageBuilder>("MessageBuilder", "The message builder that converts from HeuristicLab objects to SolutionMessage representation.", new SolutionMessageBuilder())); 93 90 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 }108 91 } 109 92 -
branches/ProgrammableProblem/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/SingleObjectiveOptimizationSupportScript.cs
r11893 r11900 62 62 } 63 63 64 private readonly object compileLock = new object(); 64 65 private volatile ISingleObjectiveOptimizationSupport compiledInstance; 65 66 private ISingleObjectiveOptimizationSupport CompiledInstance { 66 67 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 } 68 75 return compiledInstance; 69 76 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/MultiObjectiveProgrammableProblem.cs
r11880 r11900 48 48 : base(original, cloner) { 49 49 RegisterEvents(); 50 try {51 ProblemScript.Compile();52 } catch (InvalidOperationException) {53 //Compilation error54 }55 50 } 56 51 public override IDeepCloneable Clone(Cloner cloner) { return new MultiObjectiveProgrammableProblem(this, cloner); } 57 52 58 59 53 [StorableConstructor] 60 54 private MultiObjectiveProgrammableProblem(bool deserializing) : base(deserializing) { } 61 62 55 public MultiObjectiveProgrammableProblem() 63 56 : base() { … … 69 62 private void AfterDeserialization() { 70 63 RegisterEvents(); 71 try {72 ProblemScript.Compile();73 } catch (InvalidOperationException) {74 //Compilation error75 }76 64 } 77 65 -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/Scripts/ProblemDefinitionScript.cs
r11885 r11900 55 55 } 56 56 57 private readonly object locker= new object();57 private readonly object compileLock = new object(); 58 58 private volatile IProblemDefinition compiledProblemDefinition; 59 59 protected IProblemDefinition CompiledProblemDefinition { 60 60 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 } 62 69 return compiledProblemDefinition; 63 }64 private set {65 compiledProblemDefinition = value;66 OnProblemDefinitionChanged();67 70 } 68 71 } 69 72 70 public override Assembly Compile() { 73 public sealed override Assembly Compile() { 74 return Compile(true); 75 } 76 77 protected virtual Assembly Compile(bool fireChanged) { 71 78 var assembly = base.Compile(); 72 79 var types = assembly.GetTypes(); … … 93 100 94 101 try { 95 CompiledProblemDefinition = inst; 102 compiledProblemDefinition = inst; 103 if (fireChanged) OnProblemDefinitionChanged(); 96 104 } catch (Exception e) { 97 105 compiledProblemDefinition = null; -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/Scripts/Templates/CompiledMultiObjectiveProblemDefinition.cs
r11880 r11900 16 16 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 17 17 // Define the solution encoding which can also consist of multiple vectors, examples below 18 //Encoding = new Binary Encoding("b", length: 5);19 //Encoding = new Integer Encoding("i", length: 5, min: 2, max: 14, step: 4);20 //Encoding = new Real Encoding("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); 21 21 //Encoding = new PermutationEncoding("p", length: 5, type: PermutationTypes.Absolute); 22 22 // The encoding can also be a combination 23 23 //Encoding = new MultiEncoding() 24 //.Add(new Binary Encoding("b", length: 5))25 //.Add(new Integer Encoding("i", length: 5, min: 2, max: 14, step: 4))26 //.Add(new Real Encoding("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)) 27 27 //.Add(new PermutationEncoding("p", length: 5, type: PermutationTypes.Absolute)) 28 28 ; -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/Scripts/Templates/CompiledSingleObjectiveProblemDefinition.cs
r11880 r11900 16 16 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 17 17 // Define the solution encoding which can also consist of multiple vectors, examples below 18 //Encoding = new Binary Encoding("b", length: 5);19 //Encoding = new Integer Encoding("i", length: 5, min: 2, max: 14, step: 2);20 //Encoding = new Real Encoding("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); 21 21 //Encoding = new PermutationEncoding("p", length: 5, type: PermutationTypes.Absolute); 22 22 // The encoding can also be a combination 23 23 //Encoding = new MultiEncoding() 24 //.Add(new Binary Encoding("b", length: 5))25 //.Add(new Integer Encoding("i", length: 5, min: 2, max: 14, step: 4))26 //.Add(new Real Encoding("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)) 27 27 //.Add(new PermutationEncoding("p", length: 5, type: PermutationTypes.Absolute)) 28 28 ; -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/SingleObjectiveProgrammableProblem.cs
r11885 r11900 49 49 : base(original, cloner) { 50 50 RegisterEvents(); 51 try {52 ProblemScript.Compile();53 } catch (ProblemDefinitionScriptException e) {54 PluginInfrastructure.ErrorHandling.ShowErrorDialog(e);55 }56 51 } 57 52 public override IDeepCloneable Clone(Cloner cloner) { return new SingleObjectiveProgrammableProblem(this, cloner); } 58 53 59 60 54 [StorableConstructor] 61 55 private SingleObjectiveProgrammableProblem(bool deserializing) : base(deserializing) { } 62 63 56 public SingleObjectiveProgrammableProblem() 64 57 : base() { 65 58 Parameters.Add(new FixedValueParameter<SingleObjectiveProblemDefinitionScript>("ProblemScript", "Defines the problem.", new SingleObjectiveProblemDefinitionScript() { Name = Name })); 66 59 RegisterEvents(); 67 68 69 60 } 70 61 … … 72 63 private void AfterDeserialization() { 73 64 RegisterEvents(); 74 try {75 ProblemScript.Compile();76 } catch (InvalidOperationException) {77 //Compilation error78 }79 65 } 80 66
Note: See TracChangeset
for help on using the changeset viewer.