[4516] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using HeuristicLab.Core;
|
---|
| 6 | using HeuristicLab.Common;
|
---|
[4525] | 7 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[4516] | 8 |
|
---|
| 9 | namespace HeuristicLab.Problems.MetaOptimization {
|
---|
[4525] | 10 | [StorableClass]
|
---|
[4516] | 11 | public abstract class ParameterConfiguration : IParameterConfiguration {
|
---|
[4525] | 12 | [Storable]
|
---|
[4516] | 13 | public IParameter Parameter { get; set; }
|
---|
[4525] | 14 |
|
---|
| 15 | [Storable]
|
---|
[4516] | 16 | public string Category { get; set; }
|
---|
| 17 |
|
---|
| 18 | public ParameterConfiguration() { }
|
---|
[4525] | 19 |
|
---|
| 20 | [StorableConstructor]
|
---|
| 21 | protected ParameterConfiguration(bool deserializing) { }
|
---|
| 22 |
|
---|
[4516] | 23 | public ParameterConfiguration(IParameter parameter, string category) {
|
---|
| 24 | this.Parameter = parameter;
|
---|
| 25 | this.Category = category;
|
---|
| 26 | Parameter.NameChanged += this.NameChanged;
|
---|
| 27 | Parameter.NameChanging += this.NameChanging;
|
---|
| 28 | Parameter.DescriptionChanged += this.DescriptionChanged;
|
---|
| 29 | Parameter.ItemImageChanged += this.ItemImageChanged;
|
---|
| 30 | parameter.ToStringChanged += this.ToStringChanged;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | public bool CanChangeDescription {
|
---|
| 34 | get { return false; }
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | public bool CanChangeName {
|
---|
| 38 | get { return false; }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | public string Description {
|
---|
| 42 | get { return Parameter.Description; }
|
---|
| 43 | set { throw new NotSupportedException(); }
|
---|
| 44 | }
|
---|
| 45 | public string Name {
|
---|
| 46 | get { return Parameter.Name; }
|
---|
| 47 | set { throw new NotSupportedException(); }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | public string ItemDescription {
|
---|
| 51 | get { return Parameter.ItemDescription; }
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | public System.Drawing.Image ItemImage {
|
---|
| 55 | get { return Parameter.ItemImage; }
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | public string ItemName {
|
---|
| 59 | get { return Parameter.ItemName; }
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | public Version ItemVersion {
|
---|
| 63 | get { return Parameter.ItemVersion; }
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | #region Events
|
---|
| 67 | public virtual event EventHandler NameChanged;
|
---|
| 68 | public virtual event EventHandler<CancelEventArgs<string>> NameChanging;
|
---|
| 69 | public virtual event EventHandler DescriptionChanged;
|
---|
| 70 | public virtual event EventHandler ItemImageChanged;
|
---|
| 71 | public virtual event EventHandler ToStringChanged;
|
---|
| 72 |
|
---|
| 73 | protected virtual void OnToStringChanged() {
|
---|
| 74 | var handler = ToStringChanged;
|
---|
| 75 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
| 76 | }
|
---|
| 77 | #endregion
|
---|
| 78 |
|
---|
| 79 | #region Cloning
|
---|
| 80 | public virtual IDeepCloneable Clone(Cloner cloner) {
|
---|
| 81 | ParameterConfiguration clone = (ParameterConfiguration)Activator.CreateInstance(this.GetType(), true);
|
---|
| 82 | cloner.RegisterClonedObject(this, clone);
|
---|
| 83 | clone.Parameter = (IParameter)cloner.Clone(this.Parameter);
|
---|
[4525] | 84 | clone.Category = this.Category;
|
---|
[4516] | 85 | return clone;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | public object Clone() {
|
---|
| 89 | return Clone(new Cloner());
|
---|
| 90 | }
|
---|
| 91 | #endregion
|
---|
| 92 |
|
---|
| 93 | public override string ToString() {
|
---|
| 94 | return string.Format("{0}.{1}", Category, Parameter.Name);
|
---|
| 95 | }
|
---|
| 96 |
|
---|
[4525] | 97 | public abstract void SetParameterWithRandomValue(IRandom random);
|
---|
[4516] | 98 |
|
---|
| 99 | }
|
---|
| 100 | }
|
---|