Changeset 11397
- Timestamp:
- 09/28/14 09:18:30 (10 years ago)
- Location:
- branches/ProgrammableProblem
- Files:
-
- 3 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable.Views/3.3/HeuristicLab.Problems.Programmable.Views-3.3.csproj
r10753 r11397 38 38 </PropertyGroup> 39 39 <ItemGroup> 40 <Reference Include="HeuristicLab.CodeEditor-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 41 <SpecificVersion>False</SpecificVersion> 42 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.CodeEditor-3.3.dll</HintPath> 43 <Private>False</Private> 44 </Reference> 45 <Reference Include="HeuristicLab.Collections-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 46 <SpecificVersion>False</SpecificVersion> 47 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Collections-3.3.dll</HintPath> 48 <Private>False</Private> 49 </Reference> 40 50 <Reference Include="HeuristicLab.Common-3.3"> 41 51 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Common-3.3.dll</HintPath> … … 98 108 <ItemGroup> 99 109 <Compile Include="Plugin.cs" /> 110 <Compile Include="ProblemDefinitionScriptView.cs"> 111 <SubType>UserControl</SubType> 112 </Compile> 113 <Compile Include="ProblemDefinitionScriptView.Designer.cs"> 114 <DependentUpon>ProblemDefinitionScriptView.cs</DependentUpon> 115 </Compile> 100 116 <Compile Include="ProgrammableProblemView.cs"> 101 117 <SubType>UserControl</SubType> -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Datastructures/Configuration.cs
r10856 r11397 54 54 55 55 56 public Configuration AddBinary (string name, int length) {56 public Configuration AddBinaryVector(string name, int length) { 57 57 if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name"); 58 58 Parameters.Add(name, new BinaryParameterConfiguration(length)); … … 60 60 } 61 61 62 public Configuration AddInteger (string name, int length, int min, int max, int? step = null) {62 public Configuration AddIntegerVector(string name, int length, int min, int max, int? step = null) { 63 63 if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name"); 64 64 Parameters.Add(name, new IntegerParameterConfiguration(length, min, max, step)); … … 66 66 } 67 67 68 public Configuration AddInteger (string name, int length, IList<int> min, IList<int> max, IList<int> step = null) {68 public Configuration AddIntegerVector(string name, int length, IList<int> min, IList<int> max, IList<int> step = null) { 69 69 if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name"); 70 70 Parameters.Add(name, new IntegerParameterConfiguration(length, min, max, step)); … … 72 72 } 73 73 74 public Configuration AddReal (string name, int length, double min, double max) {74 public Configuration AddRealVector(string name, int length, double min, double max) { 75 75 if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name"); 76 76 Parameters.Add(name, new RealParameterConfiguration(length, min, max)); … … 78 78 } 79 79 80 public Configuration AddReal (string name, int length, IList<double> min, IList<double> max) {80 public Configuration AddRealVector(string name, int length, IList<double> min, IList<double> max) { 81 81 if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name"); 82 82 Parameters.Add(name, new RealParameterConfiguration(length, min, max)); -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Datastructures/ParameterVector.cs
r11363 r11397 76 76 } 77 77 78 public BinaryVector Binary (string name) {78 public BinaryVector BinaryVector(string name) { 79 79 return BinaryParameters[name]; 80 80 } 81 81 82 public bool Binary (string name, int index) {82 public bool BinaryValue(string name, int index) { 83 83 return BinaryParameters[name][index]; 84 84 } … … 88 88 } 89 89 90 public IntegerVector Integer (string name) {90 public IntegerVector IntegerVector(string name) { 91 91 return IntegerParameters[name]; 92 92 } 93 93 94 public int Integer (string name, int index) {94 public int IntegerValue(string name, int index) { 95 95 return IntegerParameters[name][index]; 96 96 } … … 100 100 } 101 101 102 public RealVector Real (string name) {102 public RealVector RealVector(string name) { 103 103 return RealParameters[name]; 104 104 } 105 105 106 public double Real (string name, int index) {106 public double RealValue(string name, int index) { 107 107 return RealParameters[name][index]; 108 108 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/HeuristicLab.Problems.Programmable-3.3.csproj
r11396 r11397 153 153 <Compile Include="Interfaces\IProblemDefinition.cs" /> 154 154 <Compile Include="Interfaces\ISingleObjectiveProblemDefinition.cs" /> 155 <Compile Include="ProblemDefinition.cs" /> 155 156 <Compile Include="ProblemDefinitionScript.cs" /> 156 157 <Compile Include="SingleObjectiveProblemDefinition.cs" /> -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Interfaces/IProblemDefinition.cs
r11393 r11397 23 23 namespace HeuristicLab.Problems.Programmable { 24 24 public interface IProblemDefinition { 25 dynamic vars { get; set; } 26 void Initialize(); 25 27 Configuration GetConfiguration(); 26 28 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/ParameterVectorMoveGenerator.cs
r11396 r11397 79 79 moveScopes[i] = new Scope(i.ToString()); 80 80 foreach (var param in nbhood[i].BinaryNames) 81 moveScopes[i].Variables.Add(new Variable(param, nbhood[i].Binary (param)));81 moveScopes[i].Variables.Add(new Variable(param, nbhood[i].BinaryVector(param))); 82 82 83 83 foreach (var param in nbhood[i].IntegerNames) 84 moveScopes[i].Variables.Add(new Variable(param, nbhood[i].Integer (param)));84 moveScopes[i].Variables.Add(new Variable(param, nbhood[i].IntegerVector(param))); 85 85 86 86 foreach (var param in nbhood[i].RealNames) 87 moveScopes[i].Variables.Add(new Variable(param, nbhood[i].Real (param)));87 moveScopes[i].Variables.Add(new Variable(param, nbhood[i].RealVector(param))); 88 88 89 89 foreach (var param in nbhood[i].PermutationNames) -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/ProblemDefinitionScript.cs
r11393 r11397 34 34 protected bool SuppressEvents { get; set; } 35 35 36 [Storable] 37 private VariableStore variableStore; 38 public VariableStore VariableStore { 39 get { return variableStore; } 40 } 41 36 42 [StorableConstructor] 37 43 protected ProblemDefinitionScript(bool deserializing) : base(deserializing) { } 38 44 protected ProblemDefinitionScript(ProblemDefinitionScript original, Cloner cloner) 39 : base(original, cloner) { } 40 public ProblemDefinitionScript() { } 45 : base(original, cloner) { 46 variableStore = cloner.Clone(original.variableStore); 47 } 48 protected ProblemDefinitionScript() { 49 variableStore = new VariableStore(); 50 } 41 51 42 52 private volatile IProblemDefinition instance; … … 74 84 try { 75 85 Instance = (IProblemDefinition)Activator.CreateInstance(types.First(x => typeof(IProblemDefinition).IsAssignableFrom(x))); 86 Instance.vars = new Variables(VariableStore); 87 Instance.Initialize(); 76 88 } catch { 77 89 Instance = null; -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProblemDefinition.cs
r11393 r11397 30 30 [Item("Single-objective Problem Definition", "This definition can be dynamically created through code and assigned to the problem.")] 31 31 public class SingleObjectiveProblemDefinition : ISingleObjectiveProblemDefinitionHost, ISingleObjectiveProblemDefinition { 32 33 32 private bool isMaximizationProblem; 34 33 public bool IsMaximizationProblem { … … 114 113 115 114 #region Problem definition explicit interface implementations 115 dynamic IProblemDefinition.vars { get; set; } 116 117 void IProblemDefinition.Initialize() { 118 119 } 120 121 Configuration IProblemDefinition.GetConfiguration() { 122 return Configuration(); 123 } 124 116 125 bool ISingleObjectiveProblemDefinition.IsMaximizationProblem { 117 126 get { return IsMaximizationProblem; } … … 128 137 IEnumerable<ParameterVector> ISingleObjectiveProblemDefinition.GetNeighbors(IRandom random, ParameterVector vector) { 129 138 return Neighbors(random, vector); 130 }131 132 Configuration IProblemDefinition.GetConfiguration() {133 return Configuration();134 139 } 135 140 #endregion -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProblemDefinitionScript.cs
r11393 r11397 60 60 using HeuristicLab.Problems.Programmable; 61 61 62 public class ProblemDefinition : ISingleObjectiveProblemDefinition { 63 public ProblemDefinition() { 64 // initialize private fields 62 public class CustomProblemDefinition : ProblemDefinition, ISingleObjectiveProblemDefinition { 63 public bool IsMaximizationProblem { get { return false; } } 64 65 public override void Initialize() { 66 // when the definition is created here you can initialize variables in the variable store 65 67 } 66 68 67 public bool IsMaximizationProblem { get { return false; } } 68 69 public Configuration GetConfiguration() { 69 public override Configuration GetConfiguration() { 70 70 return new Configuration() 71 // .AddBinary (""b"", length: 5)72 // .AddInteger (""i"", length: 5, min: 2, max: 14, step: 4)73 // .AddReal (""r"", length: 5, min: -1.0, max: 1.0)71 // .AddBinaryVector(""b"", length: 5) 72 // .AddIntegerVector(""i"", length: 5, min: 2, max: 14, step: 4) 73 // .AddRealVector(""r"", length: 5, min: -1.0, max: 1.0) 74 74 // .AddPermutation(""P"", length: 5, type: PermutationTypes.Absolute) 75 75 ; … … 78 78 public double Evaluate(IRandom random, ParameterVector vector) { 79 79 var quality = 0.0; 80 // quality = vector.Real(""r"").Sum(x => x * x); 80 // use vars.yourVariable to access variables in the variable store i.e. yourVariable 81 // quality = vector.RealVector(""r"").Sum(x => x * x); 81 82 return quality; 82 83 } … … 84 85 public void Analyze(ParameterVector[] vectors, double[] qualities, ResultCollection results) { 85 86 // write or update results given the range of vectors and resulting qualities 87 // use e.g. vars.yourVariable to access variables in the variable store i.e. yourVariable 86 88 } 87 89 … … 90 92 // This method is only called from move-based algorithms (LocalSearch, SimulatedAnnealing, etc.) 91 93 while (true) { 94 // this is not an infinite loop as only a finite amount of samples will be drawn 95 // it is possible to return a concrete amount of neighbors also 92 96 var neighbor = (ParameterVector)vector.Clone(); 93 97 //e.g. make a bit flip in a binary parameter 94 //var bIndex = random.Next(neighbor.Binary (""b"").Length);95 //neighbor.Binary (""b"")[bIndex] = !neighbor.Binary(""b"")[bIndex];98 //var bIndex = random.Next(neighbor.BinaryVector(""b"").Length); 99 //neighbor.BinaryVector(""b"")[bIndex] = !neighbor.BinaryVector(""b"")[bIndex]; 96 100 yield return neighbor; 97 yield break;98 101 } 99 102 }
Note: See TracChangeset
for help on using the changeset viewer.