Changeset 13345
- Timestamp:
- 11/23/15 18:38:37 (9 years ago)
- Location:
- branches/ProblemRefactoring
- Files:
-
- 3 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProblemRefactoring/HeuristicLab.Problems.Programmable.Views/3.3/HeuristicLab.Problems.Programmable.Views-3.3.csproj
r12470 r13345 93 93 <Compile Include="ProblemDefinitionScriptView.Designer.cs"> 94 94 <DependentUpon>ProblemDefinitionScriptView.cs</DependentUpon> 95 </Compile>96 <Compile Include="MultiObjectiveProgrammableProblemView.cs">97 <SubType>UserControl</SubType>98 </Compile>99 <Compile Include="MultiObjectiveProgrammableProblemView.Designer.cs">100 <DependentUpon>MultiObjectiveProgrammableProblemView.cs</DependentUpon>101 95 </Compile> 102 96 <Compile Include="SingleObjectiveProgrammableProblemView.cs"> -
branches/ProblemRefactoring/HeuristicLab.Problems.Programmable.Views/3.3/ProblemDefinitionScriptView.cs
r12012 r13345 23 23 using System.Drawing; 24 24 using HeuristicLab.MainForm; 25 using HeuristicLab.Optimization; 25 26 using HeuristicLab.Scripting.Views; 26 27 … … 52 53 try { 53 54 base.Compile(); 54 } catch (ProblemDefinitionScriptException e) { 55 } 56 catch (ProblemDefinitionScriptException e) { 55 57 PluginInfrastructure.ErrorHandling.ShowErrorDialog(e); 56 58 return false; -
branches/ProblemRefactoring/HeuristicLab.Problems.Programmable.Views/3.3/SingleObjectiveProgrammableProblemView.cs
r12012 r13345 28 28 namespace HeuristicLab.Problems.Programmable.Views { 29 29 [View("Single-Objective Scriptable Problem View")] 30 [Content(typeof( SingleObjectiveProgrammableProblem), true)]30 [Content(typeof(IProgrammableProblem), true)] 31 31 public partial class SingleObjectiveProgrammableProblemView : ItemView { 32 32 protected ViewHost ScriptView; 33 33 34 public new SingleObjectiveProgrammableProblem Content {35 get { return ( SingleObjectiveProgrammableProblem)base.Content; }34 public new IProgrammableProblem Content { 35 get { return (IProgrammableProblem)base.Content; } 36 36 set { base.Content = value; } 37 37 } -
branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/CompiledProblemDefinition.cs
r12012 r13345 24 24 25 25 namespace HeuristicLab.Problems.Programmable { 26 public abstract class CompiledProblemDefinition : IProblemDefinition { 27 private IEncoding encoding; 28 public IEncoding Encoding { 26 public abstract class CompiledProblemDefinition<TEncoding, TSolution> : IProblemDefinition<TEncoding, TSolution> 27 where TEncoding : class, IEncoding<TSolution> 28 where TSolution : class, ISolution { 29 private TEncoding encoding; 30 public TEncoding Encoding { 29 31 get { return encoding; } 30 protectedset {32 internal set { 31 33 if (value == null) throw new ArgumentNullException("The encoding must not be null."); 32 34 encoding = value; … … 38 40 39 41 protected CompiledProblemDefinition() { } 40 protected CompiledProblemDefinition( IEncoding encoding)42 protected CompiledProblemDefinition(TEncoding encoding) 41 43 : base() { 42 44 Encoding = encoding; -
branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/HeuristicLab.Problems.Programmable-3.3.csproj
r12724 r13345 86 86 </ItemGroup> 87 87 <ItemGroup> 88 <Compile Include="MultiObjectiveProgrammableProblem.cs" /> 88 <Compile Include="CompiledProblemDefinition.cs"> 89 <SubType>Code</SubType> 90 </Compile> 91 <Compile Include="Interfaces\IProgrammableProblem.cs" /> 92 <Compile Include="ProblemDefinitionScript.cs"> 93 <SubType>Code</SubType> 94 </Compile> 89 95 <Compile Include="ProblemDefinitionScriptException.cs" /> 90 <Compile Include=" Templates\CompiledMultiObjectiveProblemDefinition.cs" />91 <Co mpileInclude="Templates\CompiledSingleObjectiveProblemDefinition.cs" />96 <Compile Include="SingleObjectiveProgrammableProblems.cs" /> 97 <Content Include="Templates\CompiledSingleObjectiveProblemDefinition.cs" /> 92 98 <Compile Include="Templates\ScriptTemplates.Designer.cs"> 93 99 <AutoGen>True</AutoGen> … … 95 101 <DependentUpon>ScriptTemplates.resx</DependentUpon> 96 102 </Compile> 97 <Compile Include="CompiledProblemDefinition.cs" />98 <Compile Include="ProblemDefinitionScript.cs" />99 103 <Compile Include="SingleObjectiveProgrammableProblem.cs" /> 100 <Compile Include="MultiObjectiveProblemDefinitionScript.cs" />101 104 <Compile Include="SingleObjectiveProblemDefinitionScript.cs" /> 102 105 <EmbeddedResource Include="Templates\ScriptTemplates.resx"> … … 145 148 <Name>HeuristicLab.Encodings.BinaryVectorEncoding-3.3</Name> 146 149 </ProjectReference> 147 <ProjectReference Include="..\..\HeuristicLab.Encodings.IntegerVectorEncoding\3.3\HeuristicLab.Encodings.IntegerVectorEncoding-3.3.csproj">148 <Project>{ddfb14dd-2a85-493c-a52d-e69729bbaeb0}</Project>149 <Name>HeuristicLab.Encodings.IntegerVectorEncoding-3.3</Name>150 </ProjectReference>151 <ProjectReference Include="..\..\HeuristicLab.Encodings.LinearLinkageEncoding\3.3\HeuristicLab.Encodings.LinearLinkageEncoding-3.3.csproj">152 <Project>{be698769-975a-429e-828c-72bb2b6182c8}</Project>153 <Name>HeuristicLab.Encodings.LinearLinkageEncoding-3.3</Name>154 <Private>False</Private>155 </ProjectReference>156 <ProjectReference Include="..\..\HeuristicLab.Encodings.PermutationEncoding\3.3\HeuristicLab.Encodings.PermutationEncoding-3.3.csproj">157 <Project>{dbecb8b0-b166-4133-baf1-ed67c3fd7fca}</Project>158 <Name>HeuristicLab.Encodings.PermutationEncoding-3.3</Name>159 </ProjectReference>160 <ProjectReference Include="..\..\HeuristicLab.Encodings.RealVectorEncoding\3.3\HeuristicLab.Encodings.RealVectorEncoding-3.3.csproj">161 <Project>{bb6d334a-4bb6-4674-9883-31a6ebb32cab}</Project>162 <Name>HeuristicLab.Encodings.RealVectorEncoding-3.3</Name>163 </ProjectReference>164 <ProjectReference Include="..\..\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding\3.4\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj">165 <Project>{06d4a186-9319-48a0-bade-a2058d462eea}</Project>166 <Name>HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4</Name>167 <Private>False</Private>168 </ProjectReference>169 150 <ProjectReference Include="..\..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj"> 170 151 <Project>{23da7ff4-d5b8-41b6-aa96-f0561d24f3ee}</Project> -
branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/ProblemDefinitionScript.cs
r13218 r13345 30 30 31 31 namespace HeuristicLab.Problems.Programmable { 32 [Item("ProblemDefinitionScript", "Script that defines the parameter vector and evaluates the solution for a programmable problem.")]33 32 [StorableClass] 34 public abstract class ProblemDefinitionScript : Script, IProblemDefinition { 35 protected bool SuppressEvents { get; set; } 36 33 public abstract class ProblemDefinitionScript : Script { 37 34 [Storable] 38 35 private VariableStore variableStore; … … 41 38 } 42 39 43 [Storable]44 private bool codeChanged;45 46 40 [StorableConstructor] 47 41 protected ProblemDefinitionScript(bool deserializing) : base(deserializing) { } … … 49 43 : base(original, cloner) { 50 44 variableStore = cloner.Clone(original.variableStore); 51 codeChanged = original.codeChanged;52 45 } 53 46 protected ProblemDefinitionScript() … … 59 52 variableStore = new VariableStore(); 60 53 } 54 } 61 55 62 IEncoding IProblemDefinition.Encoding { 63 get { return CompiledProblemDefinition.Encoding; } 56 [Item("ProblemDefinitionScript", "Script that defines the parameter vector and evaluates the solution for a programmable problem.")] 57 [StorableClass] 58 public abstract class ProblemDefinitionScript<TEncoding, TSolution> : ProblemDefinitionScript, IProblemDefinition<TEncoding, TSolution> 59 where TEncoding : class, IEncoding<TSolution> 60 where TSolution : class, ISolution { 61 62 [Storable] 63 private bool codeChanged; 64 65 [Storable] 66 private TEncoding encoding; 67 internal TEncoding Encoding { 68 get { return encoding; } 69 set { encoding = value; } 70 } 71 72 TEncoding IProblemDefinition<TEncoding, TSolution>.Encoding { 73 get { return Encoding; } 74 } 75 76 internal void Initialize() { 77 CompiledProblemDefinition.Initialize(); 78 } 79 80 [StorableConstructor] 81 protected ProblemDefinitionScript(bool deserializing) : base(deserializing) { } 82 protected ProblemDefinitionScript(ProblemDefinitionScript<TEncoding, TSolution> original, Cloner cloner) 83 : base(original, cloner) { 84 codeChanged = original.codeChanged; 85 } 86 protected ProblemDefinitionScript() 87 : base() { 88 } 89 protected ProblemDefinitionScript(string code) 90 : base(code) { 64 91 } 65 92 66 93 private readonly object compileLock = new object(); 67 private volatile IProblemDefinitioncompiledProblemDefinition;68 protected IProblemDefinitionCompiledProblemDefinition {94 private volatile CompiledProblemDefinition<TEncoding, TSolution> compiledProblemDefinition; 95 protected CompiledProblemDefinition<TEncoding, TSolution> CompiledProblemDefinition { 69 96 get { 70 97 // double checked locking pattern … … 88 115 var assembly = base.Compile(); 89 116 var types = assembly.GetTypes(); 90 if (!types.Any(x => typeof(CompiledProblemDefinition ).IsAssignableFrom(x)))117 if (!types.Any(x => typeof(CompiledProblemDefinition<TEncoding, TSolution>).IsAssignableFrom(x))) 91 118 throw new ProblemDefinitionScriptException("The compiled code doesn't contain a problem definition." + Environment.NewLine + "The problem definition must be a subclass of CompiledProblemDefinition."); 92 if (types.Count(x => typeof(CompiledProblemDefinition ).IsAssignableFrom(x)) > 1)119 if (types.Count(x => typeof(CompiledProblemDefinition<TEncoding, TSolution>).IsAssignableFrom(x)) > 1) 93 120 throw new ProblemDefinitionScriptException("The compiled code contains multiple problem definitions." + Environment.NewLine + "Only one subclass of CompiledProblemDefinition is allowed."); 94 121 95 CompiledProblemDefinition inst;122 CompiledProblemDefinition<TEncoding, TSolution> inst; 96 123 try { 97 inst = (CompiledProblemDefinition)Activator.CreateInstance(types.Single(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x))); 98 } catch (Exception e) { 124 inst = (CompiledProblemDefinition<TEncoding, TSolution>)Activator.CreateInstance(types.Single(x => typeof(CompiledProblemDefinition<TEncoding, TSolution>).IsAssignableFrom(x))); 125 } 126 catch (Exception e) { 99 127 compiledProblemDefinition = null; 100 128 throw new ProblemDefinitionScriptException("Instantiating the problem definition failed." + Environment.NewLine + "Check your default constructor.", e); … … 103 131 try { 104 132 inst.vars = new Variables(VariableStore); 105 inst.Initialize(); 106 } catch (Exception e) { 133 inst.Encoding = encoding; 134 } 135 catch (Exception e) { 107 136 compiledProblemDefinition = null; 108 137 throw new ProblemDefinitionScriptException("Initializing the problem definition failed." + Environment.NewLine + "Check your Initialize() method.", e); … … 112 141 compiledProblemDefinition = inst; 113 142 if (fireChanged) OnProblemDefinitionChanged(); 114 } catch (Exception e) { 143 } 144 catch (Exception e) { 115 145 compiledProblemDefinition = null; 116 146 throw new ProblemDefinitionScriptException("Using the problem definition in the problem failed." + Environment.NewLine + "Examine this error message carefully (often there is an issue with the defined encoding).", e); -
branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProblemDefinitionScript.cs
r13218 r13345 29 29 [Item("Single-objective Problem Definition Script", "Script that defines the parameter vector and evaluates the solution for a programmable problem.")] 30 30 [StorableClass] 31 public sealed class SingleObjectiveProblemDefinitionScript : ProblemDefinitionScript, ISingleObjectiveProblemDefinition, IStorableContent { 31 public class SingleObjectiveProblemDefinitionScript<TEncoding, TSolution> : ProblemDefinitionScript<TEncoding, TSolution>, ISingleObjectiveProblemDefinition<TEncoding, TSolution>, IStorableContent 32 where TEncoding : class, IEncoding<TSolution> 33 where TSolution : class, ISolution { 32 34 public string Filename { get; set; } 33 35 34 pr ivate new ISingleObjectiveProblemDefinitionCompiledProblemDefinition {35 get { return (ISingleObjectiveProblemDefinition )base.CompiledProblemDefinition; }36 protected new ISingleObjectiveProblemDefinition<TEncoding, TSolution> CompiledProblemDefinition { 37 get { return (ISingleObjectiveProblemDefinition<TEncoding, TSolution>)base.CompiledProblemDefinition; } 36 38 } 37 39 38 40 [StorableConstructor] 39 private SingleObjectiveProblemDefinitionScript(bool deserializing) : base(deserializing) { } 40 private SingleObjectiveProblemDefinitionScript(SingleObjectiveProblemDefinitionScript original, Cloner cloner) : base(original, cloner) { } 41 public SingleObjectiveProblemDefinitionScript() : base(ScriptTemplates.CompiledSingleObjectiveProblemDefinition) { } 41 protected SingleObjectiveProblemDefinitionScript(bool deserializing) : base(deserializing) { } 42 protected SingleObjectiveProblemDefinitionScript(SingleObjectiveProblemDefinitionScript<TEncoding, TSolution> original, Cloner cloner) : base(original, cloner) { } 43 public SingleObjectiveProblemDefinitionScript(string codeTemplate) : base(codeTemplate) { } 44 public SingleObjectiveProblemDefinitionScript() { } 42 45 43 46 public override IDeepCloneable Clone(Cloner cloner) { 44 return new SingleObjectiveProblemDefinitionScript (this, cloner);47 return new SingleObjectiveProblemDefinitionScript<TEncoding, TSolution>(this, cloner); 45 48 } 46 49 47 bool ISingleObjectiveProblemDefinition .Maximization {50 bool ISingleObjectiveProblemDefinition<TEncoding, TSolution>.Maximization { 48 51 get { return CompiledProblemDefinition.Maximization; } 49 52 } 50 53 51 double ISingleObjectiveProblemDefinition .Evaluate(Individualindividual, IRandom random) {54 double ISingleObjectiveProblemDefinition<TEncoding, TSolution>.Evaluate(TSolution individual, IRandom random) { 52 55 return CompiledProblemDefinition.Evaluate(individual, random); 53 56 } 54 57 55 void ISingleObjectiveProblemDefinition .Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {58 void ISingleObjectiveProblemDefinition<TEncoding, TSolution>.Analyze(TSolution[] individuals, double[] qualities, ResultCollection results, IRandom random) { 56 59 CompiledProblemDefinition.Analyze(individuals, qualities, results, random); 57 60 } 58 IEnumerable< Individual> ISingleObjectiveProblemDefinition.GetNeighbors(Individualindividual, IRandom random) {61 IEnumerable<TSolution> ISingleObjectiveProblemDefinition<TEncoding, TSolution>.GetNeighbors(TSolution individual, IRandom random) { 59 62 return CompiledProblemDefinition.GetNeighbors(individual, random); 60 63 } -
branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblem.cs
r13336 r13345 33 33 namespace HeuristicLab.Problems.Programmable { 34 34 [Item("Programmable Problem (single-objective)", "Represents a single-objective problem that can be programmed with a script.")] 35 [Creatable(CreatableAttribute.Categories.Problems, Priority = 100)]36 35 [StorableClass] 37 public sealed class SingleObjectiveProgrammableProblem : SingleObjectiveProblem<IEncoding>, IProgrammableItem { 36 public class SingleObjectiveProgrammableProblem<TEncoding, TSolution> : SingleObjectiveProblem<TEncoding, TSolution>, IProgrammableItem, IProgrammableProblem 37 where TEncoding : class, IEncoding<TSolution> 38 where TSolution : class, ISolution { 38 39 public static new Image StaticItemImage { 39 40 get { return VSImageLibrary.Script; } 40 41 } 41 42 42 private FixedValueParameter<SingleObjectiveProblemDefinitionScript > SingleObjectiveProblemScriptParameter {43 get { return (FixedValueParameter<SingleObjectiveProblemDefinitionScript >)Parameters["ProblemScript"]; }43 private FixedValueParameter<SingleObjectiveProblemDefinitionScript<TEncoding, TSolution>> SingleObjectiveProblemScriptParameter { 44 get { return (FixedValueParameter<SingleObjectiveProblemDefinitionScript<TEncoding, TSolution>>)Parameters["ProblemScript"]; } 44 45 } 45 46 46 public SingleObjectiveProblemDefinitionScript ProblemScript {47 public SingleObjectiveProblemDefinitionScript<TEncoding, TSolution> ProblemScript { 47 48 get { return SingleObjectiveProblemScriptParameter.Value; } 48 49 } 49 50 50 public ISingleObjectiveProblemDefinition ProblemDefinition {51 public ISingleObjectiveProblemDefinition<TEncoding, TSolution> ProblemDefinition { 51 52 get { return SingleObjectiveProblemScriptParameter.Value; } 52 53 } 53 54 54 pr ivate SingleObjectiveProgrammableProblem(SingleObjectiveProgrammableProblemoriginal, Cloner cloner)55 protected SingleObjectiveProgrammableProblem(SingleObjectiveProgrammableProblem<TEncoding, TSolution> original, Cloner cloner) 55 56 : base(original, cloner) { 56 57 RegisterEvents(); 57 58 } 58 public override IDeepCloneable Clone(Cloner cloner) { return new SingleObjectiveProgrammableProblem (this, cloner); }59 public override IDeepCloneable Clone(Cloner cloner) { return new SingleObjectiveProgrammableProblem<TEncoding, TSolution>(this, cloner); } 59 60 60 61 [StorableConstructor] 61 pr ivateSingleObjectiveProgrammableProblem(bool deserializing) : base(deserializing) { }62 public SingleObjectiveProgrammableProblem( )62 protected SingleObjectiveProgrammableProblem(bool deserializing) : base(deserializing) { } 63 public SingleObjectiveProgrammableProblem(string codeTemplate) 63 64 : base() { 64 Parameters.Add(new FixedValueParameter<SingleObjectiveProblemDefinitionScript >("ProblemScript", "Defines the problem.", new SingleObjectiveProblemDefinitionScript() { Name = Name}));65 Parameters.Add(new FixedValueParameter<SingleObjectiveProblemDefinitionScript<TEncoding, TSolution>>("ProblemScript", "Defines the problem.", new SingleObjectiveProblemDefinitionScript<TEncoding, TSolution>(codeTemplate) { Name = Name, Encoding = Encoding })); 65 66 Operators.Add(new BestScopeSolutionAnalyzer()); 66 67 RegisterEvents(); … … 79 80 Parameters.Remove("Maximization"); 80 81 Parameters.Add(new FixedValueParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.", (BoolValue)new BoolValue(Maximization).AsReadOnly()) { Hidden = true }); 82 ProblemScript.Initialize(); 81 83 82 Encoding = ProblemDefinition.Encoding;83 84 OnOperatorsChanged(); 84 85 OnReset(); … … 86 87 87 88 public override bool Maximization { 88 get { return Parameters.ContainsKey("ProblemScript") ? ProblemDefinition.Maximization : false; }89 get { return Parameters.ContainsKey("ProblemScript") && ProblemDefinition.Maximization; } 89 90 } 90 91 91 public override double Evaluate( Individualindividual, IRandom random) {92 public override double Evaluate(TSolution individual, IRandom random) { 92 93 return ProblemDefinition.Evaluate(individual, random); 93 94 } 94 95 95 public override void Analyze( Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {96 public override void Analyze(TSolution[] individuals, double[] qualities, ResultCollection results, IRandom random) { 96 97 ProblemDefinition.Analyze(individuals, qualities, results, random); 97 98 } 98 public override IEnumerable< Individual> GetNeighbors(Individualindividual, IRandom random) {99 public override IEnumerable<TSolution> GetNeighbors(TSolution individual, IRandom random) { 99 100 return ProblemDefinition.GetNeighbors(individual, random); 100 101 } 102 103 #region IProgrammableProblem Members 104 Scripting.Script IProgrammableProblem.ProblemScript { 105 get { return ProblemScript; } 106 } 107 #endregion 101 108 } 102 109 } -
branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/Templates/CompiledSingleObjectiveProblemDefinition.cs
r12731 r13345 5 5 using HeuristicLab.Core; 6 6 using HeuristicLab.Data; 7 using HeuristicLab.Encodings.BinaryVectorEncoding; 8 using HeuristicLab.Encodings.IntegerVectorEncoding; 9 using HeuristicLab.Encodings.RealVectorEncoding; 10 using HeuristicLab.Encodings.PermutationEncoding; 11 using HeuristicLab.Encodings.LinearLinkageEncoding; 12 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 7 using {0} 13 8 using HeuristicLab.Optimization; 14 9 using HeuristicLab.Problems.Programmable; 15 10 16 11 namespace HeuristicLab.Problems.Programmable { 17 public class CompiledSingleObjectiveProblemDefinition : CompiledProblemDefinition , ISingleObjectiveProblemDefinition{12 public class CompiledSingleObjectiveProblemDefinition : CompiledProblemDefinition<{1}, {2}>, ISingleObjectiveProblemDefinition<{1}, {2}> { 18 13 public bool Maximization { get { return false; } } 19 14 20 15 public override void Initialize() { 21 16 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 22 // Define the solution encoding which can also consist of multiple vectors, examples below 23 //Encoding = new BinaryVectorEncoding("b", length: 5); 24 //Encoding = new IntegerVectorEncoding("i", length: 5, min: 2, max: 14, step: 2); 25 //Encoding = new RealVectorEncoding("r", length: 5, min: -1.0, max: 1.0); 26 //Encoding = new PermutationEncoding("p", length: 5, type: PermutationTypes.Absolute); 27 //Encoding = new LinearLinkageEncoding("l", length: 5); 28 //Encoding = new SymbolicExpressionTreeEncoding("s", new SimpleSymbolicExpressionGrammar(), 50, 12); 29 // The encoding can also be a combination 30 //Encoding = new MultiEncoding() 31 //.Add(new BinaryVectorEncoding("b", length: 5)) 32 //.Add(new IntegerVectorEncoding("i", length: 5, min: 2, max: 14, step: 4)) 33 //.Add(new RealVectorEncoding("r", length: 5, min: -1.0, max: 1.0)) 34 //.Add(new PermutationEncoding("p", length: 5, type: PermutationTypes.Absolute)) 35 //.Add(new LinearLinkageEncoding("l", length: 5)) 36 //.Add(new SymbolicExpressionTreeEncoding("s", new SimpleSymbolicExpressionGrammar(), 50, 12)) 37 ; 17 // Define e.g. the length of the solution encoding or the solution creator by modifying the Encoding property 38 18 // Add additional initialization code e.g. private variables that you need for evaluating 39 19 } 40 20 41 public double Evaluate( Individualindividual, IRandom random) {21 public double Evaluate({2} individual, IRandom random) { 42 22 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 43 23 var quality = 0.0; 44 //quality = individual.RealVector("r").Sum(x => x * x);45 24 return quality; 46 25 } 47 26 48 public void Analyze( Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {27 public void Analyze({2}[] individuals, double[] qualities, ResultCollection results, IRandom random) { 49 28 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 50 29 // Write or update results given the range of vectors and resulting qualities … … 55 34 56 35 //if (!results.ContainsKey("Best Solution")) { 57 // results.Add(new Result("Best Solution", typeof( RealVector)));36 // results.Add(new Result("Best Solution", typeof({20))); 58 37 //} 59 //results["Best Solution"].Value = (IItem)best. RealVector("r").Clone();38 //results["Best Solution"].Value = (IItem)best.Clone(); 60 39 } 61 40 62 public IEnumerable< Individual> GetNeighbors(Individualindividual, IRandom random) {41 public IEnumerable<{2}> GetNeighbors({2} individual, IRandom random) { 63 42 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 64 43 // Create new vectors, based on the given one that represent small changes … … 67 46 // Algorithm will draw only a finite amount of samples 68 47 // Change to a for-loop to return a concrete amount of neighbors 69 var neighbor = individual.Copy(); 70 // For instance, perform a single bit-flip in a binary parameter 71 //var bIndex = random.Next(neighbor.BinaryVector("b").Length); 72 //neighbor.BinaryVector("b")[bIndex] = !neighbor.BinaryVector("b")[bIndex]; 48 var neighbor = ({2})individual.Clone(); 49 // modify the solution specified as neighbor 73 50 yield return neighbor; 74 51 }
Note: See TracChangeset
for help on using the changeset viewer.