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