- Timestamp:
- 11/18/15 17:23:48 (9 years ago)
- Location:
- stable
- Files:
-
- 1 deleted
- 5 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 13180,13183,13203,13212,13257
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/CompiledMultiObjectiveOptimizationSupport.cs
r13183 r13259 1 using System; 2 using System.Linq; 3 using System.Collections.Generic; 4 using HeuristicLab.Common; 5 using HeuristicLab.Core; 6 using HeuristicLab.Data; 1 using HeuristicLab.Core; 7 2 using HeuristicLab.Optimization; 8 3 … … 13 8 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 14 9 // Write or update results given the range of vectors and resulting qualities 15 // Uncomment the following lines if you want to retrieve the best individual16 //var bestIndex = Maximization ?17 // qualities.Select((v, i) => Tuple.Create(i, v)).OrderByDescending(x => x.Item2).First().Item118 // : qualities.Select((v, i) => Tuple.Create(i, v)).OrderBy(x => x.Item2).First().Item1;19 //var best = individuals[bestIndex];20 10 } 21 11 -
stable/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/CompiledSingleObjectiveOptimizationSupport.cs
r11961 r13259 1 using System; 2 using System.Linq; 3 using System.Collections.Generic; 4 using HeuristicLab.Common; 1 using System.Collections.Generic; 5 2 using HeuristicLab.Core; 6 using HeuristicLab.Data;7 3 using HeuristicLab.Optimization; 8 4 … … 14 10 // Write or update results given the range of vectors and resulting qualities 15 11 // Uncomment the following lines if you want to retrieve the best individual 16 //var bestIndex = Maximization ? 17 // qualities.Select((v, i) => Tuple.Create(i, v)).OrderByDescending(x => x.Item2).First().Item1 18 // : qualities.Select((v, i) => Tuple.Create(i, v)).OrderBy(x => x.Item2).First().Item1; 19 //var best = individuals[bestIndex]; 12 // Maximization: 13 // var bestIndex = qualities.Select((v, i) => Tuple.Create(i, v)).OrderByDescending(x => x.Item2).First().Item1; 14 // Minimization: 15 // var bestIndex = qualities.Select((v, i) => Tuple.Create(i, v)).OrderBy(x => x.Item2).First().Item1; 16 // var best = individuals[bestIndex]; 20 17 } 21 18 … … 38 35 } 39 36 } 40 -
stable/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/SingleObjectiveOptimizationSupportScript.cs
r12009 r13259 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 using System.Linq;25 using System.Reflection;26 23 using HeuristicLab.Common; 27 24 using HeuristicLab.Core; … … 29 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 27 using HeuristicLab.Problems.ExternalEvaluation.Programmable; 31 using HeuristicLab.Scripting;32 28 33 29 namespace HeuristicLab.Problems.ExternalEvaluation { 34 30 [Item("ProblemDefinitionScript", "Script that defines the parameter vector and evaluates the solution for a programmable problem.")] 35 31 [StorableClass] 36 public sealed class SingleObjectiveOptimizationSupportScript : Script, ISingleObjectiveOptimizationSupport { 37 38 [Storable] 39 private VariableStore variableStore; 40 public VariableStore VariableStore { 41 get { return variableStore; } 42 } 32 public sealed class SingleObjectiveOptimizationSupportScript : OptimizationSupportScript<ISingleObjectiveOptimizationSupport>, ISingleObjectiveOptimizationSupport { 43 33 44 34 protected override string CodeTemplate { … … 48 38 [StorableConstructor] 49 39 private SingleObjectiveOptimizationSupportScript(bool deserializing) : base(deserializing) { } 50 private SingleObjectiveOptimizationSupportScript(SingleObjectiveOptimizationSupportScript original, Cloner cloner) 51 : base(original, cloner) { 52 variableStore = cloner.Clone(original.variableStore); 53 } 54 public SingleObjectiveOptimizationSupportScript() 55 : base() { 56 variableStore = new VariableStore(); 57 } 40 private SingleObjectiveOptimizationSupportScript(SingleObjectiveOptimizationSupportScript original, Cloner cloner) : base(original, cloner) { } 41 public SingleObjectiveOptimizationSupportScript() : base() { } 58 42 59 43 public override IDeepCloneable Clone(Cloner cloner) { 60 44 return new SingleObjectiveOptimizationSupportScript(this, cloner); 61 }62 63 private readonly object compileLock = new object();64 private volatile ISingleObjectiveOptimizationSupport compiledInstance;65 private ISingleObjectiveOptimizationSupport CompiledInstance {66 get {67 if (compiledInstance == null) {68 lock (compileLock) {69 if (compiledInstance == null) {70 Compile();71 }72 }73 }74 return compiledInstance;75 }76 set { compiledInstance = value; }77 }78 79 public override Assembly Compile() {80 var assembly = base.Compile();81 var types = assembly.GetTypes();82 if (!types.Any(x => typeof(CompiledOptimizationSupport).IsAssignableFrom(x)))83 throw new SingleObjectiveOptimizationSupportException("The compiled code doesn't contain an optimization support." + Environment.NewLine + "The support class must be a subclass of CompiledOptimizationSupport.");84 if (types.Count(x => typeof(CompiledOptimizationSupport).IsAssignableFrom(x)) > 1)85 throw new SingleObjectiveOptimizationSupportException("The compiled code contains multiple support classes." + Environment.NewLine + "Only one subclass of CompiledOptimizationSupport is allowed.");86 87 CompiledOptimizationSupport inst;88 try {89 inst = (CompiledOptimizationSupport)Activator.CreateInstance(types.Single(x => typeof(CompiledOptimizationSupport).IsAssignableFrom(x)));90 inst.vars = new Variables(VariableStore);91 } catch (Exception e) {92 compiledInstance = null;93 throw new SingleObjectiveOptimizationSupportException("Instantiating the optimization support class failed." + Environment.NewLine + "Check your default constructor.", e);94 }95 96 var soInst = inst as ISingleObjectiveOptimizationSupport;97 if (soInst == null)98 throw new SingleObjectiveOptimizationSupportException("The optimization support class does not implement ISingleObjectiveOptimizationSupport." + Environment.NewLine + "Please implement that interface in the subclass of CompiledOptimizationSupport.");99 100 CompiledInstance = soInst;101 102 return assembly;103 }104 105 protected override void OnCodeChanged() {106 base.OnCodeChanged();107 compiledInstance = null;108 45 } 109 46 -
stable/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/Templates.Designer.cs
r11893 r13259 2 2 // <auto-generated> 3 3 // This code was generated by a tool. 4 // Runtime Version:4.0.30319. 342094 // Runtime Version:4.0.30319.42000 5 5 // 6 6 // Changes to this file may cause incorrect behavior and will be lost if … … 68 68 ///using HeuristicLab.Core; 69 69 ///using HeuristicLab.Data; 70 ///using HeuristicLab.Encodings.PermutationEncoding;71 70 ///using HeuristicLab.Optimization; 72 ///using HeuristicLab.Problems.Programmable;73 71 /// 74 ///namespace HeuristicLab.Problems.Programmable { 75 /// public class CompiledSingleObjectiveProblemDefinition : CompiledProblemDefinition, ISingleObjectiveProblemDefinition { 76 /// public bool Maximization { get { return false; } } 72 ///namespace HeuristicLab.Problems.ExternalEvaluation { 73 /// public class CompiledMultiObjectiveOptimizationSupport : CompiledOptimizationSupport, IMultiObjectiveOptimizationSupport { 77 74 /// 78 /// [rest of string was truncated]";. 75 /// public void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random) { 76 /// // Use vars.yourVaria [rest of string was truncated]";. 77 /// </summary> 78 internal static string CompiledMultiObjectiveOptimizationSupport { 79 get { 80 return ResourceManager.GetString("CompiledMultiObjectiveOptimizationSupport", resourceCulture); 81 } 82 } 83 84 /// <summary> 85 /// Looks up a localized string similar to using System; 86 ///using System.Linq; 87 ///using System.Collections.Generic; 88 ///using HeuristicLab.Common; 89 ///using HeuristicLab.Core; 90 ///using HeuristicLab.Data; 91 ///using HeuristicLab.Optimization; 92 /// 93 ///namespace HeuristicLab.Problems.ExternalEvaluation { 94 /// public class CompiledSingleObjectiveOptimizationSupport : CompiledOptimizationSupport, ISingleObjectiveOptimizationSupport { 95 /// 96 /// public void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) { 97 /// // Use vars.yourVaria [rest of string was truncated]";. 79 98 /// </summary> 80 99 internal static string CompiledSingleObjectiveOptimizationSupport { -
stable/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/Templates.resx
r11893 r13259 119 119 </resheader> 120 120 <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 121 <data name="CompiledMultiObjectiveOptimizationSupport" type="System.Resources.ResXFileRef, System.Windows.Forms"> 122 <value>compiledmultiobjectiveoptimizationsupport.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value> 123 </data> 121 124 <data name="CompiledSingleObjectiveOptimizationSupport" type="System.Resources.ResXFileRef, System.Windows.Forms"> 122 125 <value>CompiledSingleObjectiveOptimizationSupport.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
Note: See TracChangeset
for help on using the changeset viewer.