Changeset 11396
- Timestamp:
- 09/27/14 18:30:43 (10 years ago)
- Location:
- branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3
- Files:
-
- 3 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/HeuristicLab.Problems.Programmable-3.3.csproj
r11393 r11396 138 138 <Compile Include="Datastructures\ParameterConfiguration.cs" /> 139 139 <Compile Include="Datastructures\ParameterVector.cs" /> 140 <Compile Include="Helper.cs" /> 140 141 <Compile Include="Interfaces\IParameterVectorMoveOperator.cs" /> 141 142 <Compile Include="Interfaces\ISingleObjectiveProblemDefinitionHost.cs" /> 143 <Compile Include="Interfaces\ISingleObjectiveProgrammableProblemAnalyzer.cs" /> 142 144 <Compile Include="Interfaces\ISingleObjectiveProgrammableProblemEvaluator.cs" /> 143 145 <Compile Include="Operators\ParameterVectorManipulator.cs" /> … … 146 148 <Compile Include="Operators\ParameterVectorMoveGenerator.cs" /> 147 149 <Compile Include="Operators\ParameterVectorMoveMaker.cs" /> 150 <Compile Include="Operators\SingleObjectiveAnalyzer.cs" /> 148 151 <Compile Include="Operators\SingleObjectiveEvaluator.cs" /> 149 152 <Compile Include="Operators\ParameterVectorCreater.cs" /> -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Interfaces/ISingleObjectiveProgrammableProblemEvaluator.cs
r10753 r11396 20 20 #endregion 21 21 22 using HeuristicLab.Core; 22 23 using HeuristicLab.Optimization; 23 24 24 25 namespace HeuristicLab.Problems.Programmable { 25 26 public interface ISingleObjectiveProgrammableProblemEvaluator : ISingleObjectiveEvaluator { 27 ILookupParameter<ISingleObjectiveProblemDefinitionHost> ProblemDefinitionParameter { get; } 28 ILookupParameter<Configuration> ConfigurationParameter { get; } 26 29 } 27 30 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/ParameterVectorMoveEvaluator.cs
r11393 r11396 21 21 22 22 using System; 23 using System.Collections.Generic;24 23 using HeuristicLab.Common; 25 24 using HeuristicLab.Core; 26 25 using HeuristicLab.Data; 27 using HeuristicLab.Encodings.BinaryVectorEncoding;28 using HeuristicLab.Encodings.IntegerVectorEncoding;29 using HeuristicLab.Encodings.PermutationEncoding;30 using HeuristicLab.Encodings.RealVectorEncoding;31 26 using HeuristicLab.Operators; 32 27 using HeuristicLab.Optimization; … … 79 74 if (host.Instance == null) throw new InvalidOperationException("Problem definition instance is null."); 80 75 var config = ConfigurationParameter.ActualValue; 81 var binDict = new Dictionary<string, BinaryVector>(); 82 var intDict = new Dictionary<string, IntegerVector>(); 83 var realDict = new Dictionary<string, RealVector>(); 84 var permDict = new Dictionary<string, Permutation>(); 85 foreach (var param in config.Parameters) { 86 var binConfig = param.Value as BinaryParameterConfiguration; 87 if (binConfig != null) { 88 binDict.Add(param.Key, (BinaryVector)ExecutionContext.Scope.Variables[param.Key].Value); 89 continue; 90 } 91 var intConfig = param.Value as IntegerParameterConfiguration; 92 if (intConfig != null) { 93 intDict.Add(param.Key, (IntegerVector)ExecutionContext.Scope.Variables[param.Key].Value); 94 continue; 95 } 96 var realConfig = param.Value as RealParameterConfiguration; 97 if (realConfig != null) { 98 realDict.Add(param.Key, (RealVector)ExecutionContext.Scope.Variables[param.Key].Value); 99 continue; 100 } 101 var permConfig = param.Value as PermutationParameterConfiguration; 102 if (permConfig != null) { 103 permDict.Add(param.Key, (Permutation)ExecutionContext.Scope.Variables[param.Key].Value); 104 continue; 105 } 106 throw new InvalidOperationException("Parameter " + param.Key + " not found."); 107 } 108 var vector = new ParameterVector( 109 binaryVectors: binDict.Count > 0 ? binDict : null, 110 integerVectors: intDict.Count > 0 ? intDict : null, 111 realVectors: realDict.Count > 0 ? realDict : null, 112 permutations: permDict.Count > 0 ? permDict : null); 76 var vector = Helper.Extract(ExecutionContext.Scope, config); 113 77 MoveQualityParameter.ActualValue = new DoubleValue(host.Instance.Evaluate(random, vector)); 114 78 return base.InstrumentedApply(); -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/ParameterVectorMoveGenerator.cs
r11393 r11396 21 21 22 22 using System; 23 using System.Collections.Generic;24 23 using System.Linq; 25 24 using HeuristicLab.Common; 26 25 using HeuristicLab.Core; 27 26 using HeuristicLab.Data; 28 using HeuristicLab.Encodings.BinaryVectorEncoding;29 using HeuristicLab.Encodings.IntegerVectorEncoding;30 using HeuristicLab.Encodings.PermutationEncoding;31 using HeuristicLab.Encodings.RealVectorEncoding;32 27 using HeuristicLab.Operators; 33 28 using HeuristicLab.Optimization; … … 77 72 var sampleSize = SampleSizeParameter.ActualValue.Value; 78 73 var config = ConfigurationParameter.ActualValue; 79 var binDict = new Dictionary<string, BinaryVector>(); 80 var intDict = new Dictionary<string, IntegerVector>(); 81 var realDict = new Dictionary<string, RealVector>(); 82 var permDict = new Dictionary<string, Permutation>(); 83 foreach (var param in config.Parameters) { 84 var binConfig = param.Value as BinaryParameterConfiguration; 85 if (binConfig != null) { 86 binDict.Add(param.Key, (BinaryVector)ExecutionContext.Scope.Variables[param.Key].Value); 87 continue; 88 } 89 var intConfig = param.Value as IntegerParameterConfiguration; 90 if (intConfig != null) { 91 intDict.Add(param.Key, (IntegerVector)ExecutionContext.Scope.Variables[param.Key].Value); 92 continue; 93 } 94 var realConfig = param.Value as RealParameterConfiguration; 95 if (realConfig != null) { 96 realDict.Add(param.Key, (RealVector)ExecutionContext.Scope.Variables[param.Key].Value); 97 continue; 98 } 99 var permConfig = param.Value as PermutationParameterConfiguration; 100 if (permConfig != null) { 101 permDict.Add(param.Key, (Permutation)ExecutionContext.Scope.Variables[param.Key].Value); 102 continue; 103 } 104 throw new InvalidOperationException("Parameter " + param.Key + " not found."); 105 } 106 var vector = new ParameterVector( 107 binaryVectors: binDict.Count > 0 ? binDict : null, 108 integerVectors: intDict.Count > 0 ? intDict : null, 109 realVectors: realDict.Count > 0 ? realDict : null, 110 permutations: permDict.Count > 0 ? permDict : null); 74 var vector = Helper.Extract(ExecutionContext.Scope, config); 111 75 var nbhood = host.Instance.GetNeighbors(random, vector).Take(sampleSize).ToList(); 112 76 -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/SingleObjectiveEvaluator.cs
r11393 r11396 21 21 22 22 using System; 23 using System.Collections.Generic;24 23 using HeuristicLab.Common; 25 24 using HeuristicLab.Core; 26 25 using HeuristicLab.Data; 27 using HeuristicLab.Encodings.BinaryVectorEncoding;28 using HeuristicLab.Encodings.IntegerVectorEncoding;29 using HeuristicLab.Encodings.PermutationEncoding;30 using HeuristicLab.Encodings.RealVectorEncoding;31 26 using HeuristicLab.Operators; 32 27 using HeuristicLab.Optimization; … … 74 69 if (host.Instance == null) throw new InvalidOperationException("Script instance is null, maybe the code doesn't compile."); 75 70 var config = ConfigurationParameter.ActualValue; 76 var binDict = new Dictionary<string, BinaryVector>(); 77 var intDict = new Dictionary<string, IntegerVector>(); 78 var realDict = new Dictionary<string, RealVector>(); 79 var permDict = new Dictionary<string, Permutation>(); 80 foreach (var param in config.Parameters) { 81 var binConfig = param.Value as BinaryParameterConfiguration; 82 if (binConfig != null) { 83 binDict.Add(param.Key, (BinaryVector)ExecutionContext.Scope.Variables[param.Key].Value); 84 continue; 85 } 86 var intConfig = param.Value as IntegerParameterConfiguration; 87 if (intConfig != null) { 88 intDict.Add(param.Key, (IntegerVector)ExecutionContext.Scope.Variables[param.Key].Value); 89 continue; 90 } 91 var realConfig = param.Value as RealParameterConfiguration; 92 if (realConfig != null) { 93 realDict.Add(param.Key, (RealVector)ExecutionContext.Scope.Variables[param.Key].Value); 94 continue; 95 } 96 var permConfig = param.Value as PermutationParameterConfiguration; 97 if (permConfig != null) { 98 permDict.Add(param.Key, (Permutation)ExecutionContext.Scope.Variables[param.Key].Value); 99 continue; 100 } 101 throw new InvalidOperationException("Parameter " + param.Key + " not found."); 102 } 103 var vector = new ParameterVector( 104 binaryVectors: binDict.Count > 0 ? binDict : null, 105 integerVectors: intDict.Count > 0 ? intDict : null, 106 realVectors: realDict.Count > 0 ? realDict : null, 107 permutations: permDict.Count > 0 ? permDict : null); 71 var vector = Helper.Extract(ExecutionContext.Scope, config); 108 72 QualityParameter.ActualValue = new DoubleValue(host.Instance.Evaluate(random, vector)); 109 73 return base.Apply(); -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblem.cs
r11395 r11396 87 87 88 88 Operators.Add(new BestScopeSolutionAnalyzer()); 89 Operators.Add(new SingleObjectiveAnalyzer()); 89 90 Operators.Add(Evaluator); 90 91 Operators.Add(SolutionCreator); … … 127 128 base.OnNameChanged(); 128 129 ProblemDefinitionParameter.Value.Name = Name; 130 } 131 132 protected override void OnEvaluatorChanged() { 133 base.OnEvaluatorChanged(); 134 Parameterize(); 129 135 } 130 136 … … 143 149 ConfigurationParameter.Value = configuration; 144 150 Maximization.Value = instance.IsMaximizationProblem; 151 152 Evaluator.ConfigurationParameter.ActualName = ConfigurationParameter.Name; 153 Evaluator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name; 154 foreach (var evalOp in Operators.OfType<ISingleObjectiveProgrammableProblemEvaluator>()) { 155 evalOp.ConfigurationParameter.ActualName = ConfigurationParameter.Name; 156 evalOp.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name; 157 } 158 foreach (var analyzeOp in Operators.OfType<ISingleObjectiveProgrammableProblemAnalyzer>()) { 159 analyzeOp.ConfigurationParameter.ActualName = ConfigurationParameter.Name; 160 analyzeOp.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name; 161 analyzeOp.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 162 } 145 163 146 164 var solutionCreators = UpdateDynamicConfigurationParameters(configuration);
Note: See TracChangeset
for help on using the changeset viewer.