Index: /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable.Views/3.3/HeuristicLab.Problems.Programmable.Views-3.3.csproj
===================================================================
--- /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable.Views/3.3/HeuristicLab.Problems.Programmable.Views-3.3.csproj (revision 13344)
+++ /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable.Views/3.3/HeuristicLab.Problems.Programmable.Views-3.3.csproj (revision 13345)
@@ -93,10 +93,4 @@
ProblemDefinitionScriptView.cs
-
-
- UserControl
-
-
- MultiObjectiveProgrammableProblemView.cs
Index: /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable.Views/3.3/ProblemDefinitionScriptView.cs
===================================================================
--- /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable.Views/3.3/ProblemDefinitionScriptView.cs (revision 13344)
+++ /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable.Views/3.3/ProblemDefinitionScriptView.cs (revision 13345)
@@ -23,4 +23,5 @@
using System.Drawing;
using HeuristicLab.MainForm;
+using HeuristicLab.Optimization;
using HeuristicLab.Scripting.Views;
@@ -52,5 +53,6 @@
try {
base.Compile();
- } catch (ProblemDefinitionScriptException e) {
+ }
+ catch (ProblemDefinitionScriptException e) {
PluginInfrastructure.ErrorHandling.ShowErrorDialog(e);
return false;
Index: /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable.Views/3.3/SingleObjectiveProgrammableProblemView.cs
===================================================================
--- /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable.Views/3.3/SingleObjectiveProgrammableProblemView.cs (revision 13344)
+++ /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable.Views/3.3/SingleObjectiveProgrammableProblemView.cs (revision 13345)
@@ -28,10 +28,10 @@
namespace HeuristicLab.Problems.Programmable.Views {
[View("Single-Objective Scriptable Problem View")]
- [Content(typeof(SingleObjectiveProgrammableProblem), true)]
+ [Content(typeof(IProgrammableProblem), true)]
public partial class SingleObjectiveProgrammableProblemView : ItemView {
protected ViewHost ScriptView;
- public new SingleObjectiveProgrammableProblem Content {
- get { return (SingleObjectiveProgrammableProblem)base.Content; }
+ public new IProgrammableProblem Content {
+ get { return (IProgrammableProblem)base.Content; }
set { base.Content = value; }
}
Index: /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/CompiledProblemDefinition.cs
===================================================================
--- /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/CompiledProblemDefinition.cs (revision 13344)
+++ /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/CompiledProblemDefinition.cs (revision 13345)
@@ -24,9 +24,11 @@
namespace HeuristicLab.Problems.Programmable {
- public abstract class CompiledProblemDefinition : IProblemDefinition {
- private IEncoding encoding;
- public IEncoding Encoding {
+ public abstract class CompiledProblemDefinition : IProblemDefinition
+ where TEncoding : class, IEncoding
+ where TSolution : class, ISolution {
+ private TEncoding encoding;
+ public TEncoding Encoding {
get { return encoding; }
- protected set {
+ internal set {
if (value == null) throw new ArgumentNullException("The encoding must not be null.");
encoding = value;
@@ -38,5 +40,5 @@
protected CompiledProblemDefinition() { }
- protected CompiledProblemDefinition(IEncoding encoding)
+ protected CompiledProblemDefinition(TEncoding encoding)
: base() {
Encoding = encoding;
Index: /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/HeuristicLab.Problems.Programmable-3.3.csproj
===================================================================
--- /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/HeuristicLab.Problems.Programmable-3.3.csproj (revision 13344)
+++ /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/HeuristicLab.Problems.Programmable-3.3.csproj (revision 13345)
@@ -86,8 +86,14 @@
-
+
+ Code
+
+
+
+ Code
+
-
-
+
+
True
@@ -95,8 +101,5 @@
ScriptTemplates.resx
-
-
-
@@ -145,26 +148,4 @@
HeuristicLab.Encodings.BinaryVectorEncoding-3.3
-
- {ddfb14dd-2a85-493c-a52d-e69729bbaeb0}
- HeuristicLab.Encodings.IntegerVectorEncoding-3.3
-
-
- {be698769-975a-429e-828c-72bb2b6182c8}
- HeuristicLab.Encodings.LinearLinkageEncoding-3.3
- False
-
-
- {dbecb8b0-b166-4133-baf1-ed67c3fd7fca}
- HeuristicLab.Encodings.PermutationEncoding-3.3
-
-
- {bb6d334a-4bb6-4674-9883-31a6ebb32cab}
- HeuristicLab.Encodings.RealVectorEncoding-3.3
-
-
- {06d4a186-9319-48a0-bade-a2058d462eea}
- HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4
- False
-
{23da7ff4-d5b8-41b6-aa96-f0561d24f3ee}
Index: /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/Interfaces/IProgrammableProblem.cs
===================================================================
--- /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/Interfaces/IProgrammableProblem.cs (revision 13345)
+++ /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/Interfaces/IProgrammableProblem.cs (revision 13345)
@@ -0,0 +1,31 @@
+#region License Information
+
+/* HeuristicLab
+ * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+
+#endregion
+
+using HeuristicLab.Core;
+using HeuristicLab.Scripting;
+
+namespace HeuristicLab.Problems.Programmable {
+ public interface IProgrammableProblem : INamedItem {
+ Script ProblemScript { get; }
+ }
+}
Index: /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/ProblemDefinitionScript.cs
===================================================================
--- /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/ProblemDefinitionScript.cs (revision 13344)
+++ /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/ProblemDefinitionScript.cs (revision 13345)
@@ -30,9 +30,6 @@
namespace HeuristicLab.Problems.Programmable {
- [Item("ProblemDefinitionScript", "Script that defines the parameter vector and evaluates the solution for a programmable problem.")]
[StorableClass]
- public abstract class ProblemDefinitionScript : Script, IProblemDefinition {
- protected bool SuppressEvents { get; set; }
-
+ public abstract class ProblemDefinitionScript : Script {
[Storable]
private VariableStore variableStore;
@@ -41,7 +38,4 @@
}
- [Storable]
- private bool codeChanged;
-
[StorableConstructor]
protected ProblemDefinitionScript(bool deserializing) : base(deserializing) { }
@@ -49,5 +43,4 @@
: base(original, cloner) {
variableStore = cloner.Clone(original.variableStore);
- codeChanged = original.codeChanged;
}
protected ProblemDefinitionScript()
@@ -59,12 +52,46 @@
variableStore = new VariableStore();
}
+ }
- IEncoding IProblemDefinition.Encoding {
- get { return CompiledProblemDefinition.Encoding; }
+ [Item("ProblemDefinitionScript", "Script that defines the parameter vector and evaluates the solution for a programmable problem.")]
+ [StorableClass]
+ public abstract class ProblemDefinitionScript : ProblemDefinitionScript, IProblemDefinition
+ where TEncoding : class, IEncoding
+ where TSolution : class, ISolution {
+
+ [Storable]
+ private bool codeChanged;
+
+ [Storable]
+ private TEncoding encoding;
+ internal TEncoding Encoding {
+ get { return encoding; }
+ set { encoding = value; }
+ }
+
+ TEncoding IProblemDefinition.Encoding {
+ get { return Encoding; }
+ }
+
+ internal void Initialize() {
+ CompiledProblemDefinition.Initialize();
+ }
+
+ [StorableConstructor]
+ protected ProblemDefinitionScript(bool deserializing) : base(deserializing) { }
+ protected ProblemDefinitionScript(ProblemDefinitionScript original, Cloner cloner)
+ : base(original, cloner) {
+ codeChanged = original.codeChanged;
+ }
+ protected ProblemDefinitionScript()
+ : base() {
+ }
+ protected ProblemDefinitionScript(string code)
+ : base(code) {
}
private readonly object compileLock = new object();
- private volatile IProblemDefinition compiledProblemDefinition;
- protected IProblemDefinition CompiledProblemDefinition {
+ private volatile CompiledProblemDefinition compiledProblemDefinition;
+ protected CompiledProblemDefinition CompiledProblemDefinition {
get {
// double checked locking pattern
@@ -88,13 +115,14 @@
var assembly = base.Compile();
var types = assembly.GetTypes();
- if (!types.Any(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)))
+ if (!types.Any(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)))
throw new ProblemDefinitionScriptException("The compiled code doesn't contain a problem definition." + Environment.NewLine + "The problem definition must be a subclass of CompiledProblemDefinition.");
- if (types.Count(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)) > 1)
+ if (types.Count(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)) > 1)
throw new ProblemDefinitionScriptException("The compiled code contains multiple problem definitions." + Environment.NewLine + "Only one subclass of CompiledProblemDefinition is allowed.");
- CompiledProblemDefinition inst;
+ CompiledProblemDefinition inst;
try {
- inst = (CompiledProblemDefinition)Activator.CreateInstance(types.Single(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)));
- } catch (Exception e) {
+ inst = (CompiledProblemDefinition)Activator.CreateInstance(types.Single(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)));
+ }
+ catch (Exception e) {
compiledProblemDefinition = null;
throw new ProblemDefinitionScriptException("Instantiating the problem definition failed." + Environment.NewLine + "Check your default constructor.", e);
@@ -103,6 +131,7 @@
try {
inst.vars = new Variables(VariableStore);
- inst.Initialize();
- } catch (Exception e) {
+ inst.Encoding = encoding;
+ }
+ catch (Exception e) {
compiledProblemDefinition = null;
throw new ProblemDefinitionScriptException("Initializing the problem definition failed." + Environment.NewLine + "Check your Initialize() method.", e);
@@ -112,5 +141,6 @@
compiledProblemDefinition = inst;
if (fireChanged) OnProblemDefinitionChanged();
- } catch (Exception e) {
+ }
+ catch (Exception e) {
compiledProblemDefinition = null;
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);
Index: /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProblemDefinitionScript.cs
===================================================================
--- /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProblemDefinitionScript.cs (revision 13344)
+++ /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProblemDefinitionScript.cs (revision 13345)
@@ -29,32 +29,35 @@
[Item("Single-objective Problem Definition Script", "Script that defines the parameter vector and evaluates the solution for a programmable problem.")]
[StorableClass]
- public sealed class SingleObjectiveProblemDefinitionScript : ProblemDefinitionScript, ISingleObjectiveProblemDefinition, IStorableContent {
+ public class SingleObjectiveProblemDefinitionScript : ProblemDefinitionScript, ISingleObjectiveProblemDefinition, IStorableContent
+ where TEncoding : class, IEncoding
+ where TSolution : class, ISolution {
public string Filename { get; set; }
- private new ISingleObjectiveProblemDefinition CompiledProblemDefinition {
- get { return (ISingleObjectiveProblemDefinition)base.CompiledProblemDefinition; }
+ protected new ISingleObjectiveProblemDefinition CompiledProblemDefinition {
+ get { return (ISingleObjectiveProblemDefinition)base.CompiledProblemDefinition; }
}
[StorableConstructor]
- private SingleObjectiveProblemDefinitionScript(bool deserializing) : base(deserializing) { }
- private SingleObjectiveProblemDefinitionScript(SingleObjectiveProblemDefinitionScript original, Cloner cloner) : base(original, cloner) { }
- public SingleObjectiveProblemDefinitionScript() : base(ScriptTemplates.CompiledSingleObjectiveProblemDefinition) { }
+ protected SingleObjectiveProblemDefinitionScript(bool deserializing) : base(deserializing) { }
+ protected SingleObjectiveProblemDefinitionScript(SingleObjectiveProblemDefinitionScript original, Cloner cloner) : base(original, cloner) { }
+ public SingleObjectiveProblemDefinitionScript(string codeTemplate) : base(codeTemplate) { }
+ public SingleObjectiveProblemDefinitionScript() { }
public override IDeepCloneable Clone(Cloner cloner) {
- return new SingleObjectiveProblemDefinitionScript(this, cloner);
+ return new SingleObjectiveProblemDefinitionScript(this, cloner);
}
- bool ISingleObjectiveProblemDefinition.Maximization {
+ bool ISingleObjectiveProblemDefinition.Maximization {
get { return CompiledProblemDefinition.Maximization; }
}
- double ISingleObjectiveProblemDefinition.Evaluate(Individual individual, IRandom random) {
+ double ISingleObjectiveProblemDefinition.Evaluate(TSolution individual, IRandom random) {
return CompiledProblemDefinition.Evaluate(individual, random);
}
- void ISingleObjectiveProblemDefinition.Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
+ void ISingleObjectiveProblemDefinition.Analyze(TSolution[] individuals, double[] qualities, ResultCollection results, IRandom random) {
CompiledProblemDefinition.Analyze(individuals, qualities, results, random);
}
- IEnumerable ISingleObjectiveProblemDefinition.GetNeighbors(Individual individual, IRandom random) {
+ IEnumerable ISingleObjectiveProblemDefinition.GetNeighbors(TSolution individual, IRandom random) {
return CompiledProblemDefinition.GetNeighbors(individual, random);
}
Index: /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblem.cs
===================================================================
--- /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblem.cs (revision 13344)
+++ /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblem.cs (revision 13345)
@@ -33,34 +33,35 @@
namespace HeuristicLab.Problems.Programmable {
[Item("Programmable Problem (single-objective)", "Represents a single-objective problem that can be programmed with a script.")]
- [Creatable(CreatableAttribute.Categories.Problems, Priority = 100)]
[StorableClass]
- public sealed class SingleObjectiveProgrammableProblem : SingleObjectiveProblem, IProgrammableItem {
+ public class SingleObjectiveProgrammableProblem : SingleObjectiveProblem, IProgrammableItem, IProgrammableProblem
+ where TEncoding : class, IEncoding
+ where TSolution : class, ISolution {
public static new Image StaticItemImage {
get { return VSImageLibrary.Script; }
}
- private FixedValueParameter SingleObjectiveProblemScriptParameter {
- get { return (FixedValueParameter)Parameters["ProblemScript"]; }
+ private FixedValueParameter> SingleObjectiveProblemScriptParameter {
+ get { return (FixedValueParameter>)Parameters["ProblemScript"]; }
}
- public SingleObjectiveProblemDefinitionScript ProblemScript {
+ public SingleObjectiveProblemDefinitionScript ProblemScript {
get { return SingleObjectiveProblemScriptParameter.Value; }
}
- public ISingleObjectiveProblemDefinition ProblemDefinition {
+ public ISingleObjectiveProblemDefinition ProblemDefinition {
get { return SingleObjectiveProblemScriptParameter.Value; }
}
- private SingleObjectiveProgrammableProblem(SingleObjectiveProgrammableProblem original, Cloner cloner)
+ protected SingleObjectiveProgrammableProblem(SingleObjectiveProgrammableProblem original, Cloner cloner)
: base(original, cloner) {
RegisterEvents();
}
- public override IDeepCloneable Clone(Cloner cloner) { return new SingleObjectiveProgrammableProblem(this, cloner); }
+ public override IDeepCloneable Clone(Cloner cloner) { return new SingleObjectiveProgrammableProblem(this, cloner); }
[StorableConstructor]
- private SingleObjectiveProgrammableProblem(bool deserializing) : base(deserializing) { }
- public SingleObjectiveProgrammableProblem()
+ protected SingleObjectiveProgrammableProblem(bool deserializing) : base(deserializing) { }
+ public SingleObjectiveProgrammableProblem(string codeTemplate)
: base() {
- Parameters.Add(new FixedValueParameter("ProblemScript", "Defines the problem.", new SingleObjectiveProblemDefinitionScript() { Name = Name }));
+ Parameters.Add(new FixedValueParameter>("ProblemScript", "Defines the problem.", new SingleObjectiveProblemDefinitionScript(codeTemplate) { Name = Name, Encoding = Encoding }));
Operators.Add(new BestScopeSolutionAnalyzer());
RegisterEvents();
@@ -79,6 +80,6 @@
Parameters.Remove("Maximization");
Parameters.Add(new FixedValueParameter("Maximization", "Set to false if the problem should be minimized.", (BoolValue)new BoolValue(Maximization).AsReadOnly()) { Hidden = true });
+ ProblemScript.Initialize();
- Encoding = ProblemDefinition.Encoding;
OnOperatorsChanged();
OnReset();
@@ -86,17 +87,23 @@
public override bool Maximization {
- get { return Parameters.ContainsKey("ProblemScript") ? ProblemDefinition.Maximization : false; }
+ get { return Parameters.ContainsKey("ProblemScript") && ProblemDefinition.Maximization; }
}
- public override double Evaluate(Individual individual, IRandom random) {
+ public override double Evaluate(TSolution individual, IRandom random) {
return ProblemDefinition.Evaluate(individual, random);
}
- public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
+ public override void Analyze(TSolution[] individuals, double[] qualities, ResultCollection results, IRandom random) {
ProblemDefinition.Analyze(individuals, qualities, results, random);
}
- public override IEnumerable GetNeighbors(Individual individual, IRandom random) {
+ public override IEnumerable GetNeighbors(TSolution individual, IRandom random) {
return ProblemDefinition.GetNeighbors(individual, random);
}
+
+ #region IProgrammableProblem Members
+ Scripting.Script IProgrammableProblem.ProblemScript {
+ get { return ProblemScript; }
+ }
+ #endregion
}
}
Index: /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblems.cs
===================================================================
--- /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblems.cs (revision 13345)
+++ /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblems.cs (revision 13345)
@@ -0,0 +1,125 @@
+#region License Information
+
+/* HeuristicLab
+ * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+
+#endregion
+
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Encodings.BinaryVectorEncoding;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Problems.Programmable {
+ [Item("Binary Vector Programmable Problem (single-objective)", "Represents a binary vector single-objective problem that can be programmed with a script.")]
+ [Creatable(CreatableAttribute.Categories.Problems, Priority = 100)]
+ [StorableClass]
+ public sealed class SingleObjectiveBinaryVectorProgrammableProblem : SingleObjectiveProgrammableProblem {
+
+ [StorableConstructor]
+ private SingleObjectiveBinaryVectorProgrammableProblem(bool deserializing) : base(deserializing) { }
+ private SingleObjectiveBinaryVectorProgrammableProblem(SingleObjectiveBinaryVectorProgrammableProblem original, Cloner cloner) : base(original, cloner) { }
+ public SingleObjectiveBinaryVectorProgrammableProblem()
+ : base(string.Format(ScriptTemplates.CompiledSingleObjectiveProblemDefinition, "HeuristicLab.Encodings.BinaryVectorEncoding", "BinaryVectorEncoding", "BinaryVector")) { }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new SingleObjectiveBinaryVectorProgrammableProblem(this, cloner);
+ }
+ }
+ /*
+ [Item("Integer Vector Programmable Problem (single-objective)", "Represents an integer vector single-objective problem that can be programmed with a script.")]
+ [Creatable(CreatableAttribute.Categories.Problems, Priority = 100)]
+ [StorableClass]
+ public sealed class SingleObjectiveIntegerVectorProgrammableProblem : SingleObjectiveProgrammableProblem {
+
+ [StorableConstructor]
+ private SingleObjectiveIntegerVectorProgrammableProblem(bool deserializing) : base(deserializing) { }
+ private SingleObjectiveIntegerVectorProgrammableProblem(SingleObjectiveIntegerVectorProgrammableProblem original, Cloner cloner) : base(original, cloner) { }
+ public SingleObjectiveIntegerVectorProgrammableProblem()
+ : base(string.Format(ScriptTemplates.CompiledSingleObjectiveProblemDefinition, "HeuristicLab.Encodings.IntegerVectorEncoding", "IntegerVectorEncoding", "IntegerVector")) { }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new SingleObjectiveIntegerVectorProgrammableProblem(this, cloner);
+ }
+ }
+
+ [Item("Real Vector Programmable Problem (single-objective)", "Represents a real vector single-objective problem that can be programmed with a script.")]
+ [Creatable(CreatableAttribute.Categories.Problems, Priority = 100)]
+ [StorableClass]
+ public sealed class SingleObjectiveRealVectorProgrammableProblem : SingleObjectiveProgrammableProblem {
+
+ [StorableConstructor]
+ private SingleObjectiveRealVectorProgrammableProblem(bool deserializing) : base(deserializing) { }
+ private SingleObjectiveRealVectorProgrammableProblem(SingleObjectiveRealVectorProgrammableProblem original, Cloner cloner) : base(original, cloner) { }
+ public SingleObjectiveRealVectorProgrammableProblem()
+ : base(string.Format(ScriptTemplates.CompiledSingleObjectiveProblemDefinition, "HeuristicLab.Encodings.RealVectorEncoding", "RealVectorEncoding", "RealVector")) { }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new SingleObjectiveRealVectorProgrammableProblem(this, cloner);
+ }
+ }
+
+ [Item("Permutation Programmable Problem (single-objective)", "Represents a permutation single-objective problem that can be programmed with a script.")]
+ [Creatable(CreatableAttribute.Categories.Problems, Priority = 100)]
+ [StorableClass]
+ public sealed class SingleObjectivePermutationProgrammableProblem : SingleObjectiveProgrammableProblem {
+
+ [StorableConstructor]
+ private SingleObjectivePermutationProgrammableProblem(bool deserializing) : base(deserializing) { }
+ private SingleObjectivePermutationProgrammableProblem(SingleObjectivePermutationProgrammableProblem original, Cloner cloner) : base(original, cloner) { }
+ public SingleObjectivePermutationProgrammableProblem()
+ : base(string.Format(ScriptTemplates.CompiledSingleObjectiveProblemDefinition, "HeuristicLab.Encodings.PermutationEncoding", "PermutationEncoding", "Permutation")) { }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new SingleObjectivePermutationProgrammableProblem(this, cloner);
+ }
+ }
+
+ [Item("Symbolic Expression Tree Programmable Problem (single-objective)", "Represents a symbolic expression tree single-objective problem that can be programmed with a script.")]
+ [Creatable(CreatableAttribute.Categories.Problems, Priority = 100)]
+ [StorableClass]
+ public sealed class SingleObjectiveSymbolicExpressionTreeProgrammableProblem : SingleObjectiveProgrammableProblem {
+
+ [StorableConstructor]
+ private SingleObjectiveSymbolicExpressionTreeProgrammableProblem(bool deserializing) : base(deserializing) { }
+ private SingleObjectiveSymbolicExpressionTreeProgrammableProblem(SingleObjectiveSymbolicExpressionTreeProgrammableProblem original, Cloner cloner) : base(original, cloner) { }
+ public SingleObjectiveSymbolicExpressionTreeProgrammableProblem()
+ : base(string.Format(ScriptTemplates.CompiledSingleObjectiveProblemDefinition, "HeuristicLab.Encodings.SymbolicExpressionTreeEncoding", "SymbolicExpressionTreeEncoding", "SymbolicExpressionTree")) { }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new SingleObjectiveSymbolicExpressionTreeProgrammableProblem(this, cloner);
+ }
+ }
+
+ [Item("Linear Linkage Programmable Problem (single-objective)", "Represents a linear linkage single-objective problem that can be programmed with a script.")]
+ [Creatable(CreatableAttribute.Categories.Problems, Priority = 100)]
+ [StorableClass]
+ public sealed class SingleObjectiveLinearLinkageProgrammableProblem : SingleObjectiveProgrammableProblem {
+
+ [StorableConstructor]
+ private SingleObjectiveLinearLinkageProgrammableProblem(bool deserializing) : base(deserializing) { }
+ private SingleObjectiveLinearLinkageProgrammableProblem(SingleObjectiveLinearLinkageProgrammableProblem original, Cloner cloner) : base(original, cloner) { }
+ public SingleObjectiveLinearLinkageProgrammableProblem()
+ : base(string.Format(ScriptTemplates.CompiledSingleObjectiveProblemDefinition, "HeuristicLab.Encodings.LinearLinkageEncoding", "LinearLinkageEncoding", "LinearLinkage")) { }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new SingleObjectiveLinearLinkageProgrammableProblem(this, cloner);
+ }
+ }*/
+}
Index: /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/Templates/CompiledSingleObjectiveProblemDefinition.cs
===================================================================
--- /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/Templates/CompiledSingleObjectiveProblemDefinition.cs (revision 13344)
+++ /branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/Templates/CompiledSingleObjectiveProblemDefinition.cs (revision 13345)
@@ -5,46 +5,25 @@
using HeuristicLab.Core;
using HeuristicLab.Data;
-using HeuristicLab.Encodings.BinaryVectorEncoding;
-using HeuristicLab.Encodings.IntegerVectorEncoding;
-using HeuristicLab.Encodings.RealVectorEncoding;
-using HeuristicLab.Encodings.PermutationEncoding;
-using HeuristicLab.Encodings.LinearLinkageEncoding;
-using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
+using {0}
using HeuristicLab.Optimization;
using HeuristicLab.Problems.Programmable;
namespace HeuristicLab.Problems.Programmable {
- public class CompiledSingleObjectiveProblemDefinition : CompiledProblemDefinition, ISingleObjectiveProblemDefinition {
+ public class CompiledSingleObjectiveProblemDefinition : CompiledProblemDefinition<{1}, {2}>, ISingleObjectiveProblemDefinition<{1}, {2}> {
public bool Maximization { get { return false; } }
public override void Initialize() {
// Use vars.yourVariable to access variables in the variable store i.e. yourVariable
- // Define the solution encoding which can also consist of multiple vectors, examples below
- //Encoding = new BinaryVectorEncoding("b", length: 5);
- //Encoding = new IntegerVectorEncoding("i", length: 5, min: 2, max: 14, step: 2);
- //Encoding = new RealVectorEncoding("r", length: 5, min: -1.0, max: 1.0);
- //Encoding = new PermutationEncoding("p", length: 5, type: PermutationTypes.Absolute);
- //Encoding = new LinearLinkageEncoding("l", length: 5);
- //Encoding = new SymbolicExpressionTreeEncoding("s", new SimpleSymbolicExpressionGrammar(), 50, 12);
- // The encoding can also be a combination
- //Encoding = new MultiEncoding()
- //.Add(new BinaryVectorEncoding("b", length: 5))
- //.Add(new IntegerVectorEncoding("i", length: 5, min: 2, max: 14, step: 4))
- //.Add(new RealVectorEncoding("r", length: 5, min: -1.0, max: 1.0))
- //.Add(new PermutationEncoding("p", length: 5, type: PermutationTypes.Absolute))
- //.Add(new LinearLinkageEncoding("l", length: 5))
- //.Add(new SymbolicExpressionTreeEncoding("s", new SimpleSymbolicExpressionGrammar(), 50, 12))
- ;
+ // Define e.g. the length of the solution encoding or the solution creator by modifying the Encoding property
// Add additional initialization code e.g. private variables that you need for evaluating
}
- public double Evaluate(Individual individual, IRandom random) {
+ public double Evaluate({2} individual, IRandom random) {
// Use vars.yourVariable to access variables in the variable store i.e. yourVariable
var quality = 0.0;
- //quality = individual.RealVector("r").Sum(x => x * x);
return quality;
}
- public void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
+ public void Analyze({2}[] individuals, double[] qualities, ResultCollection results, IRandom random) {
// Use vars.yourVariable to access variables in the variable store i.e. yourVariable
// Write or update results given the range of vectors and resulting qualities
@@ -55,10 +34,10 @@
//if (!results.ContainsKey("Best Solution")) {
- // results.Add(new Result("Best Solution", typeof(RealVector)));
+ // results.Add(new Result("Best Solution", typeof({20)));
//}
- //results["Best Solution"].Value = (IItem)best.RealVector("r").Clone();
+ //results["Best Solution"].Value = (IItem)best.Clone();
}
- public IEnumerable GetNeighbors(Individual individual, IRandom random) {
+ public IEnumerable<{2}> GetNeighbors({2} individual, IRandom random) {
// Use vars.yourVariable to access variables in the variable store i.e. yourVariable
// Create new vectors, based on the given one that represent small changes
@@ -67,8 +46,6 @@
// Algorithm will draw only a finite amount of samples
// Change to a for-loop to return a concrete amount of neighbors
- var neighbor = individual.Copy();
- // For instance, perform a single bit-flip in a binary parameter
- //var bIndex = random.Next(neighbor.BinaryVector("b").Length);
- //neighbor.BinaryVector("b")[bIndex] = !neighbor.BinaryVector("b")[bIndex];
+ var neighbor = ({2})individual.Clone();
+ // modify the solution specified as neighbor
yield return neighbor;
}