Changeset 13183
- Timestamp:
- 11/16/15 18:55:07 (9 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.4
- Files:
-
- 1 added
- 5 edited
- 3 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.4/HeuristicLab.Problems.ExternalEvaluation-3.4.csproj
r13180 r13183 135 135 <Compile Include="Drivers\EvaluationTCPChannel.cs" /> 136 136 <Compile Include="Interfaces\IExternalEvaluationProblem.cs" /> 137 <Compile Include="Interfaces\IMultiObjectiveOptimizationSupport.cs" /> 137 138 <Compile Include="MultiObjectiveExternalEvaluationProblem.cs" /> 138 139 <Compile Include="ExternalEvaluationProblem.cs" /> … … 143 144 <Compile Include="Plugin.cs" /> 144 145 <Compile Include="Programmable\CompiledOptimizationSupport.cs" /> 146 <Compile Include="Programmable\CompiledMultiObjectiveOptimizationSupport.cs" /> 145 147 <Compile Include="Programmable\CompiledSingleObjectiveOptimizationSupport.cs" /> 148 <Compile Include="Programmable\MultiObjectiveOptimizationSupportScript.cs" /> 149 <Compile Include="Programmable\OptimizationSupportScript.cs" /> 146 150 <Compile Include="Programmable\SingleObjectiveOptimizationSupportScript.cs" /> 147 <Compile Include="Programmable\ SingleObjectiveOptimizationSupportScriptException.cs" />151 <Compile Include="Programmable\OptimizationSupportScriptException.cs" /> 148 152 <Compile Include="Programmable\Templates.Designer.cs"> 149 153 <AutoGen>True</AutoGen> -
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.4/Interfaces/IMultiObjectiveOptimizationSupport.cs
r13166 r13183 20 20 #endregion 21 21 22 using System.Collections.Generic;23 22 using HeuristicLab.Core; 24 23 using HeuristicLab.Optimization; 25 24 26 25 namespace HeuristicLab.Problems.ExternalEvaluation { 27 public interface ISingleObjectiveOptimizationSupport { 28 void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random); 29 IEnumerable<Individual> GetNeighbors(Individual individual, IRandom random); 26 public interface IMultiObjectiveOptimizationSupport { 27 void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random); 30 28 } 31 29 } -
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.4/MultiObjectiveExternalEvaluationProblem.cs
r13180 r13183 53 53 get { return (IValueParameter<SolutionMessageBuilder>)Parameters["MessageBuilder"]; } 54 54 } 55 //public IFixedValueParameter<MultiObjectiveOptimizationSupportScript> SupportScriptParameter {56 //get { return (IFixedValueParameter<MultiObjectiveOptimizationSupportScript>)Parameters["SupportScript"]; }57 //}55 public IFixedValueParameter<MultiObjectiveOptimizationSupportScript> SupportScriptParameter { 56 get { return (IFixedValueParameter<MultiObjectiveOptimizationSupportScript>)Parameters["SupportScript"]; } 57 } 58 58 #endregion 59 59 … … 68 68 get { return MessageBuilderParameter.Value; } 69 69 } 70 //public MultiObjectiveOptimizationSupportScript OptimizationSupportScript {71 //get { return SupportScriptParameter.Value; }72 //}73 //private IMultiObjectiveOptimizationSupport OptimizationSupport {74 //get { return SupportScriptParameter.Value; }75 //}70 public MultiObjectiveOptimizationSupportScript OptimizationSupportScript { 71 get { return SupportScriptParameter.Value; } 72 } 73 private IMultiObjectiveOptimizationSupport OptimizationSupport { 74 get { return SupportScriptParameter.Value; } 75 } 76 76 #endregion 77 77 … … 89 89 Parameters.Add(new ValueParameter<CheckedItemCollection<IEvaluationServiceClient>>("Clients", "The clients that are used to communicate with the external application.", new CheckedItemCollection<IEvaluationServiceClient>() { new EvaluationServiceClient() })); 90 90 Parameters.Add(new ValueParameter<SolutionMessageBuilder>("MessageBuilder", "The message builder that converts from HeuristicLab objects to SolutionMessage representation.", new SolutionMessageBuilder()) { Hidden = true }); 91 //Parameters.Add(new FixedValueParameter<MultiObjectiveOptimizationSupportScript>("SupportScript", "A script that can analyze the results of the optimization.", new MultiObjectiveOptimizationSupportScript()));91 Parameters.Add(new FixedValueParameter<MultiObjectiveOptimizationSupportScript>("SupportScript", "A script that can analyze the results of the optimization.", new MultiObjectiveOptimizationSupportScript())); 92 92 93 93 //Operators.Add(new BestScopeSolutionAnalyzer()); pareto front … … 114 114 115 115 public override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random) { 116 //OptimizationSupport.Analyze(individuals, qualities, results, random);116 OptimizationSupport.Analyze(individuals, qualities, results, random); 117 117 } 118 118 -
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/CompiledMultiObjectiveOptimizationSupport.cs
r13166 r13183 8 8 9 9 namespace HeuristicLab.Problems.ExternalEvaluation { 10 public class Compiled SingleObjectiveOptimizationSupport : CompiledOptimizationSupport, ISingleObjectiveOptimizationSupport {10 public class CompiledMultiObjectiveOptimizationSupport : CompiledOptimizationSupport, IMultiObjectiveOptimizationSupport { 11 11 12 public void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {12 public void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random) { 13 13 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 14 14 // Write or update results given the range of vectors and resulting qualities … … 20 20 } 21 21 22 public IEnumerable<Individual> GetNeighbors(Individual individual, IRandom random) {23 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable24 // Create new vectors, based on the given one that represent small changes25 // This method is only called from move-based algorithms (Local Search, Simulated Annealing, etc.)26 while (true) {27 // Algorithm will draw only a finite amount of samples28 // Change to a for-loop to return a concrete amount of neighbors29 var neighbor = individual.Copy();30 // For instance, perform a single bit-flip in a binary parameter31 //var bIndex = random.Next(neighbor.BinaryVector("b").Length);32 //neighbor.BinaryVector("b")[bIndex] = !neighbor.BinaryVector("b")[bIndex];33 yield return neighbor;34 }35 }36 37 22 // Implement further classes and methods 38 23 } 39 24 } 40 -
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/MultiObjectiveOptimizationSupportScript.cs
r13166 r13183 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 using System.Linq;25 using System.Reflection;26 22 using HeuristicLab.Common; 27 23 using HeuristicLab.Core; … … 29 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 26 using HeuristicLab.Problems.ExternalEvaluation.Programmable; 31 using HeuristicLab.Scripting;32 27 33 28 namespace HeuristicLab.Problems.ExternalEvaluation { 34 29 [Item("ProblemDefinitionScript", "Script that defines the parameter vector and evaluates the solution for a programmable problem.")] 35 30 [StorableClass] 36 public sealed class SingleObjectiveOptimizationSupportScript : Script, ISingleObjectiveOptimizationSupport { 37 38 [Storable] 39 private VariableStore variableStore; 40 public VariableStore VariableStore { 41 get { return variableStore; } 42 } 31 public sealed class MultiObjectiveOptimizationSupportScript : OptimizationSupportScript<IMultiObjectiveOptimizationSupport>, IMultiObjectiveOptimizationSupport { 43 32 44 33 protected override string CodeTemplate { 45 get { return Templates.Compiled SingleObjectiveOptimizationSupport; }34 get { return Templates.CompiledMultiObjectiveOptimizationSupport; } 46 35 } 47 36 48 37 [StorableConstructor] 49 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(); 38 private MultiObjectiveOptimizationSupportScript(bool deserializing) : base(deserializing) { } 39 private MultiObjectiveOptimizationSupportScript(MultiObjectiveOptimizationSupportScript original, Cloner cloner) : base(original, cloner) { } 40 public MultiObjectiveOptimizationSupportScript() : base() { } 41 42 public override IDeepCloneable Clone(Cloner cloner) { 43 return new MultiObjectiveOptimizationSupportScript(this, cloner); 57 44 } 58 45 59 public override IDeepCloneable Clone(Cloner cloner) { 60 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 } 109 110 void ISingleObjectiveOptimizationSupport.Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) { 46 void IMultiObjectiveOptimizationSupport.Analyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random) { 111 47 CompiledInstance.Analyze(individuals, qualities, results, random); 112 }113 114 IEnumerable<Individual> ISingleObjectiveOptimizationSupport.GetNeighbors(Individual individual, IRandom random) {115 return CompiledInstance.GetNeighbors(individual, random);116 48 } 117 49 } -
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/OptimizationSupportScriptException.cs
r13166 r13183 25 25 namespace HeuristicLab.Problems.ExternalEvaluation { 26 26 [Serializable] 27 public class SingleObjectiveOptimizationSupportException : Exception {28 public SingleObjectiveOptimizationSupportException() { }29 public SingleObjectiveOptimizationSupportException(string message) : base(message) { }30 public SingleObjectiveOptimizationSupportException(string message, Exception inner) : base(message, inner) { }27 public class OptimizationSupportException : Exception { 28 public OptimizationSupportException() { } 29 public OptimizationSupportException(string message) : base(message) { } 30 public OptimizationSupportException(string message, Exception inner) : base(message, inner) { } 31 31 32 protected SingleObjectiveOptimizationSupportException(SerializationInfo info, StreamingContext context)32 protected OptimizationSupportException(SerializationInfo info, StreamingContext context) 33 33 : base(info, context) { } 34 34 } -
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/SingleObjectiveOptimizationSupportScript.cs
r12012 r13183 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 -
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/Templates.Designer.cs
r11893 r13183 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 { -
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/Templates.resx
r11893 r13183 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.