- Timestamp:
- 12/21/10 01:13:49 (14 years ago)
- Location:
- branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3
- Files:
-
- 1 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurationTree.cs
r5112 r5144 8 8 using HeuristicLab.Optimization; 9 9 using HeuristicLab.Data; 10 using System.Collections; 10 11 11 12 namespace HeuristicLab.Problems.MetaOptimization { 12 13 // todo: storable, name, descr, ... 13 14 [StorableClass] 14 public class ParameterConfigurationTree : ValueConfiguration {15 public class ParameterConfigurationTree : ValueConfiguration, IEnumerable { 15 16 //[Storable] 16 17 //public EngineAlgorithm Algorithm { … … 180 181 ((IAlgorithm)item).CollectParameterValues(this.Parameters); 181 182 } 183 184 public Experiment GenerateExperiment(IAlgorithm algorithm) { 185 Experiment experiment = new Experiment(); 186 foreach (IValueConfiguration combination in this) { 187 IAlgorithm clonedAlg = (IAlgorithm)algorithm.Clone(); 188 clonedAlg.Name = combination.ToParameterInfoString(); 189 combination.Parameterize(clonedAlg); 190 experiment.Optimizers.Add(clonedAlg); 191 } 192 return experiment; 193 } 194 195 public IEnumerator GetEnumerator() { 196 IEnumerator enumerator = new ParameterCombinationsEnumerator(this); 197 enumerator.Reset(); 198 return enumerator; 199 } 200 201 public long GetCombinationCount() { 202 long cnt = 0; 203 foreach (var c in this) { 204 cnt++; 205 } 206 return cnt; 207 } 182 208 } 183 209 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurations/ParameterConfiguration.cs
r5112 r5144 9 9 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 10 10 using HeuristicLab.PluginInfrastructure; 11 using System.Text; 11 12 12 13 namespace HeuristicLab.Problems.MetaOptimization { … … 299 300 } 300 301 302 public string ToParameterInfoString() { 303 StringBuilder sb = new StringBuilder(); 304 if (this.Optimize) { 305 sb.Append(string.Format("{0}: {1}", parameterName, this.ActualValue.Value)); 306 //sb.Append(" ("); 307 //var subParams = new List<string>(); 308 //if (this.ActualValue.Value is IParameterizedItem) { 309 // subParams.Add(this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).ToParameterInfoString()); 310 //} 311 //sb.Append(string.Join(", ", subParams.ToArray())); 312 //sb.Append(")"); 313 } 314 return sb.ToString(); 315 } 316 301 317 public static IParameterConfiguration Create(IParameterizedNamedItem parent, IParameter parameter) { 302 318 if (parameter is IValueParameter) { … … 348 364 } 349 365 } 366 367 public void UpdateActualValueIndexToItem(IValueConfiguration vc) { 368 for (int i = 0; i < this.ValueConfigurations.CheckedItems.Count(); i++) { 369 if (this.ValueConfigurations.CheckedItems.ElementAt(i) == vc) { 370 this.actualValueConfigurationIndex = i; 371 return; 372 } 373 } 374 } 375 350 376 } 351 377 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/DoubleValueRange.cs
r5112 r5144 37 37 if (value.Value < this.LowerBound.Value) value.Value = this.LowerBound.Value; 38 38 } 39 40 public override IEnumerable<DoubleValue> GetCombinations() { 41 var solutions = new List<DoubleValue>(); 42 double value = ((int)Math.Round(LowerBound.Value / StepSize.Value, 0)) * StepSize.Value; 43 if (value < LowerBound.Value) value += StepSize.Value; 44 45 while (value <= UpperBound.Value) { 46 //yield return new DoubleValue(value); 47 solutions.Add(new DoubleValue(value)); 48 value += StepSize.Value; 49 } 50 return solutions; 51 } 39 52 } 40 53 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/IntValueRange.cs
r5112 r5144 37 37 if (value.Value < this.LowerBound.Value) value.Value = this.LowerBound.Value; 38 38 } 39 40 public override IEnumerable<IntValue> GetCombinations() { 41 var solutions = new List<IntValue>(); 42 int value = (this.LowerBound.Value / StepSize.Value) * StepSize.Value; 43 if (value < this.LowerBound.Value) value += StepSize.Value; 44 45 while (value <= this.UpperBound.Value) { 46 //yield return new IntValue(value); 47 solutions.Add(new IntValue(value)); 48 value += this.StepSize.Value; 49 } 50 return solutions; 51 } 39 52 } 40 53 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/PercentValueRange.cs
r5112 r5144 32 32 return new DoubleValueRange(LowerBound, UpperBound, StepSize); 33 33 } 34 35 public override IEnumerable<PercentValue> GetCombinations() { 36 var solutions = new List<PercentValue>(); 37 double value = ((int)Math.Round(LowerBound.Value / StepSize.Value, 0)) * StepSize.Value; 38 if (value < LowerBound.Value) value += StepSize.Value; 39 40 while (value <= UpperBound.Value) { 41 //yield return new PercentValue(value); 42 solutions.Add(new PercentValue(value)); 43 value += StepSize.Value; 44 } 45 return solutions; 46 } 34 47 } 35 48 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/Range.cs
r5112 r5144 1 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 2 4 using HeuristicLab.Common; 3 5 using HeuristicLab.Core; … … 206 208 207 209 protected abstract T GetRandomSample(IRandom random); 208 209 210 IItem IRange.GetRandomValue(IRandom random) { 210 211 return GetRandomValue(random); 211 212 } 213 214 public abstract IEnumerable<T> GetCombinations(); 215 IEnumerable<IItem> IRange.GetCombinations() { 216 return GetCombinations().Cast<IItem>().ToArray(); 217 } 212 218 } 213 219 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ValueConfigurations/ValueConfiguration.cs
r5112 r5144 9 9 using HeuristicLab.Encodings.IntegerVectorEncoding; 10 10 using HeuristicLab.PluginInfrastructure; 11 using System.Collections.Generic; 12 using System.Text; 11 13 12 14 namespace HeuristicLab.Problems.MetaOptimization { … … 89 91 this.IsOptimizable = true; 90 92 if (actualValue.ValueDataType == typeof(IntValue)) { 91 rangeConstraint = new IntValueRange(new IntValue(0), (IntValue)value, new IntValue(1));93 RangeConstraint = new IntValueRange(new IntValue(0), (IntValue)value, new IntValue(1)); 92 94 } else if (actualValue.ValueDataType == typeof(DoubleValue)) { 93 rangeConstraint = new DoubleValueRange(new DoubleValue(0), (DoubleValue)value, new DoubleValue(0.01));95 RangeConstraint = new DoubleValueRange(new DoubleValue(0), (DoubleValue)value, new DoubleValue(0.01)); 94 96 } else if (actualValue.ValueDataType == typeof(PercentValue)) { 95 rangeConstraint = new PercentValueRange(new PercentValue(0), new PercentValue(1), new PercentValue(0.001));97 RangeConstraint = new PercentValueRange(new PercentValue(0), new PercentValue(1), new PercentValue(0.001)); 96 98 } else if (actualValue.ValueDataType == typeof(BoolValue)) { 97 99 this.IsOptimizable = false; // there is nothing to configure for bools 98 100 } else { 99 rangeConstraint = null; 100 } 101 RegisterRangeConstraintEvents(); 101 RangeConstraint = null; 102 } 102 103 } 103 104 … … 155 156 } 156 157 #endregion 157 158 158 159 #region IItem Members 159 160 public override string ItemDescription { … … 169 170 } 170 171 #endregion 171 172 172 173 #region Event Handlers 173 174 public virtual event EventHandler ValueChanged; … … 208 209 return base.ToString(); 209 210 } 211 } 212 213 public string ToParameterInfoString() { 214 StringBuilder sb = new StringBuilder(); 215 if (this.Optimize) { 216 if (this.ParameterConfigurations.Count > 0) { 217 var parameterInfos = new List<string>(); 218 foreach (var pc in this.ParameterConfigurations) { 219 if (pc.Optimize) parameterInfos.Add(pc.ToParameterInfoString()); 220 } 221 sb.Append(string.Join(", ", parameterInfos.ToArray())); 222 } 223 } 224 return sb.ToString(); 210 225 } 211 226 -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/HeuristicLab.Problems.MetaOptimization-3.3.csproj
r5111 r5144 134 134 <Compile Include="ConstrainedItemList.cs" /> 135 135 <Compile Include="Encoding\NullValue.cs" /> 136 <Compile Include="Encoding\ParameterCombinationsEnumerator.cs" /> 136 137 <Compile Include="Encoding\RangeConstraints\PercentValueRange.cs"> 137 138 <SubType>Code</SubType> -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IOptimizable.cs
r5111 r5144 18 18 void Mutate(IRandom random, MutateDelegate mutate, ParameterConfigurationManipulator pcmanip); 19 19 void Cross(IRandom random, IOptimizable other, CrossDelegate cross, ParameterConfigurationCrossover pccross); 20 20 string ToParameterInfoString(); 21 21 22 event EventHandler IsOptimizableChanged; 22 23 event EventHandler OptimizeChanged; -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IParameterConfiguration.cs
r5111 r5144 14 14 15 15 void Parameterize(IValueParameter parameter); 16 void UpdateActualValueIndexToItem(IValueConfiguration vc); 16 17 } 17 18 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IRange.cs
r5009 r5144 3 3 using HeuristicLab.Core; 4 4 using HeuristicLab.Data; 5 using System.Collections.Generic; 5 6 6 7 namespace HeuristicLab.Problems.MetaOptimization { … … 15 16 16 17 IItem GetRandomValue(IRandom random); 18 19 IEnumerable<IItem> GetCombinations(); 17 20 } 18 21 … … 22 25 new T StepSize { get; set; } 23 26 new T GetRandomValue(IRandom random); 27 new IEnumerable<T> GetCombinations(); 24 28 } 25 29 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IValueConfiguration.cs
r5009 r5144 2 2 using HeuristicLab.Core; 3 3 using HeuristicLab.Data; 4 using System.Collections.Generic; 4 5 5 6 namespace HeuristicLab.Problems.MetaOptimization { … … 8 9 IRange RangeConstraint { get; } 9 10 event EventHandler ValueChanged; 10 11 11 12 void Parameterize(IParameterizedItem item); 12 13 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs
r5111 r5144 40 40 public const string ProblemTypeParameterName = "ProblemType"; 41 41 public const string ProblemsParameterName = "Problems"; 42 public const string ParameterConfiguration ParameterName = "InitialParameterConfigurationTree";42 public const string ParameterConfigurationTreeParameterName = "ParameterConfigurationTree"; 43 43 public const string RepetitionsParameterName = "Repetitions"; 44 44 … … 58 58 get { return (ValueParameter<ConstrainedItemList<ISingleObjectiveProblem>>)Parameters[ProblemsParameterName]; } 59 59 } 60 public IValueParameter<ParameterConfigurationTree> ParameterConfiguration Parameter {61 get { return (ValueParameter<ParameterConfigurationTree>)Parameters[ParameterConfiguration ParameterName]; }60 public IValueParameter<ParameterConfigurationTree> ParameterConfigurationTreeParameter { 61 get { return (ValueParameter<ParameterConfigurationTree>)Parameters[ParameterConfigurationTreeParameterName]; } 62 62 } 63 63 public IValueParameter<IntValue> RepetitionsParameter { … … 87 87 set { ProblemsParameter.Value = value; } 88 88 } 89 public ParameterConfigurationTree AlgorithmParameterConfiguration{90 get { return ParameterConfiguration Parameter.Value; }91 set { ParameterConfiguration Parameter.Value = value; }89 public ParameterConfigurationTree ParameterConfigurationTree { 90 get { return ParameterConfigurationTreeParameter.Value; } 91 set { ParameterConfigurationTreeParameter.Value = value; } 92 92 } 93 93 public IntValue Repetitions { … … 101 101 Parameters.Add(new ValueParameter<ISingleObjectiveProblem>(ProblemTypeParameterName, "The problem type.", new SingleObjectiveTestFunctionProblem())); 102 102 Parameters.Add(new ValueParameter<ConstrainedItemList<ISingleObjectiveProblem>>(ProblemsParameterName, "The problems that should be evaluated.", new ConstrainedItemList<ISingleObjectiveProblem>())); 103 Parameters.Add(new ValueParameter<ParameterConfigurationTree>(ParameterConfiguration ParameterName, "List of algorithm parameters that should be optimized."));103 Parameters.Add(new ValueParameter<ParameterConfigurationTree>(ParameterConfigurationTreeParameterName, "List of algorithm parameters that should be optimized.")); 104 104 Parameters.Add(new ValueParameter<IntValue>(RepetitionsParameterName, "The number of evaluations for each problem.", new IntValue(3))); 105 105 … … 122 122 Problems.Type = Problem.GetType(); 123 123 Algorithm.Problem = Problem; 124 ParameterConfiguration Parameter.ActualValue = new ParameterConfigurationTree(Algorithm);124 ParameterConfigurationTreeParameter.ActualValue = new ParameterConfigurationTree(Algorithm); 125 125 } 126 126 … … 185 185 void AlgorithmTypeParameter_ValueChanged(object sender, EventArgs e) { 186 186 Algorithm.Problem = Problem; 187 ParameterConfiguration Parameter.ActualValue = new ParameterConfigurationTree(Algorithm);187 ParameterConfigurationTreeParameter.ActualValue = new ParameterConfigurationTree(Algorithm); 188 188 } 189 189 void ProblemTypeParameter_ValueChanged(object sender, EventArgs e) { 190 190 Problems.Type = Problem.GetType(); 191 191 Algorithm.Problem = Problem; 192 ParameterConfiguration Parameter.ActualValue = new ParameterConfigurationTree(Algorithm);192 ParameterConfigurationTreeParameter.ActualValue = new ParameterConfigurationTree(Algorithm); 193 193 } 194 194 #endregion
Note: See TracChangeset
for help on using the changeset viewer.