[5653] | 1 | using System;
|
---|
[5655] | 2 | using System.Diagnostics;
|
---|
| 3 | using HeuristicLab.Common;
|
---|
| 4 | using HeuristicLab.Core;
|
---|
| 5 | using HeuristicLab.Data;
|
---|
[5653] | 6 | using HeuristicLab.Operators;
|
---|
| 7 | using HeuristicLab.Optimization;
|
---|
| 8 | using HeuristicLab.Parameters;
|
---|
[5655] | 9 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[5653] | 10 |
|
---|
| 11 | namespace HeuristicLab.Problems.MetaOptimization {
|
---|
| 12 | [Item("AlgorithmEvaluator", "")]
|
---|
| 13 | [StorableClass]
|
---|
| 14 | public class AlgorithmEvaluator : SingleSuccessorOperator {
|
---|
| 15 |
|
---|
| 16 | #region Parameter properties
|
---|
| 17 | public ILookupParameter<IRandom> RandomParameter {
|
---|
| 18 | get { return (LookupParameter<IRandom>)Parameters["Random"]; }
|
---|
| 19 | }
|
---|
| 20 | public ILookupParameter<IAlgorithm> AlgorithmParameter {
|
---|
| 21 | get { return (LookupParameter<IAlgorithm>)Parameters["Algorithm"]; }
|
---|
| 22 | }
|
---|
| 23 | public ILookupParameter<IntValue> ProblemIndexParameter {
|
---|
| 24 | get { return (LookupParameter<IntValue>)Parameters["ProblemIndex"]; }
|
---|
| 25 | }
|
---|
| 26 | public ILookupParameter<IntValue> RepetitionIndexParameter {
|
---|
| 27 | get { return (LookupParameter<IntValue>)Parameters["RepetitionIndex"]; }
|
---|
| 28 | }
|
---|
| 29 | public ILookupParameter<ParameterConfigurationTree> ParameterConfigurationParameter {
|
---|
| 30 | get { return (ILookupParameter<ParameterConfigurationTree>)Parameters["ParameterConfigurationTree"]; }
|
---|
| 31 | }
|
---|
| 32 | public IValueParameter<IItemList<IRun>> RunsParameter {
|
---|
| 33 | get { return (IValueParameter<IItemList<IRun>>)Parameters["Runs"]; }
|
---|
| 34 | }
|
---|
| 35 | #endregion
|
---|
| 36 |
|
---|
| 37 | [StorableConstructor]
|
---|
| 38 | protected AlgorithmEvaluator(bool deserializing) : base(deserializing) { }
|
---|
| 39 | public AlgorithmEvaluator()
|
---|
| 40 | : base() {
|
---|
| 41 | Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used to initialize the new random permutation."));
|
---|
| 42 | Parameters.Add(new LookupParameter<IAlgorithm>("Algorithm", ""));
|
---|
| 43 | Parameters.Add(new LookupParameter<IntValue>("ProblemIndex", ""));
|
---|
| 44 | Parameters.Add(new LookupParameter<IntValue>("RepetitionIndex", ""));
|
---|
| 45 | Parameters.Add(new LookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", ""));
|
---|
| 46 | Parameters.Add(new ValueParameter<IItemList<IRun>>("Runs", ""));
|
---|
| 47 | }
|
---|
| 48 | protected AlgorithmEvaluator(AlgorithmEvaluator original, Cloner cloner) : base(original, cloner) { }
|
---|
| 49 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 50 | return new AlgorithmEvaluator(this, cloner);
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | public override IOperation Apply() {
|
---|
| 54 | IAlgorithm algorithm = AlgorithmParameter.ActualValue;
|
---|
| 55 |
|
---|
| 56 | var sw = new Stopwatch();
|
---|
| 57 | sw.Start();
|
---|
| 58 | algorithm.StartSync();
|
---|
| 59 | sw.Stop();
|
---|
| 60 | Console.WriteLine("{0},{1}: {2}", ProblemIndexParameter.ActualValue.Value, RepetitionIndexParameter.ActualValue.Value, sw.Elapsed);
|
---|
| 61 |
|
---|
| 62 | RunsParameter.Value = new ItemList<IRun>(algorithm.Runs);
|
---|
| 63 |
|
---|
| 64 | return base.Apply();
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | /// <summary>
|
---|
| 68 | /// This method should repair an invalid parameterConfiguration.
|
---|
| 69 | /// The strategy is to just randomize parameter settings. It's not guaranteed to be a vaild setting
|
---|
| 70 | /// </summary>
|
---|
| 71 | private void Repair(ParameterConfigurationTree parameterConfiguration, IRandom random) {
|
---|
| 72 | parameterConfiguration.Randomize(random);
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 | }
|
---|