[9194] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
[9226] | 22 | using System;
|
---|
[9194] | 23 | using System.Collections.Generic;
|
---|
[9226] | 24 | using System.Drawing;
|
---|
[9204] | 25 | using System.Linq;
|
---|
[9226] | 26 | using System.Text;
|
---|
[9194] | 27 | using HeuristicLab.Common;
|
---|
| 28 | using HeuristicLab.Core;
|
---|
| 29 | using HeuristicLab.Encodings.ConditionActionEncoding;
|
---|
| 30 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 31 |
|
---|
| 32 | namespace HeuristicLab.Encodings.VariableVector {
|
---|
| 33 | [StorableClass]
|
---|
| 34 | [Item("VariableVectorInput", "")]
|
---|
[9226] | 35 | public class VariableVectorInput : Dictionary<string, string>, IInput {
|
---|
[9194] | 36 |
|
---|
[9226] | 37 | public IOrderedEnumerable<string> Order { get { return this.Keys.OrderBy(x => x); } }
|
---|
[9204] | 38 |
|
---|
[9194] | 39 | [StorableConstructor]
|
---|
[9226] | 40 | protected VariableVectorInput(bool deserializing) { }
|
---|
| 41 | protected VariableVectorInput(VariableVectorInput original, Cloner cloner) {
|
---|
| 42 | foreach (var item in original) {
|
---|
| 43 | Add((string)item.Key.Clone(), (string)item.Value.Clone());
|
---|
| 44 | }
|
---|
[9194] | 45 | }
|
---|
| 46 | public VariableVectorInput() : base() { }
|
---|
| 47 | public VariableVectorInput(int capacity) : base(capacity) { }
|
---|
[9226] | 48 | public VariableVectorInput(IDictionary<string, string> dictionary) : base(dictionary) { }
|
---|
| 49 |
|
---|
| 50 | public override string ToString() {
|
---|
| 51 | StringBuilder sb = new StringBuilder();
|
---|
| 52 | bool first = true;
|
---|
| 53 | foreach (var item in this) {
|
---|
| 54 | if (first) {
|
---|
| 55 | first = false;
|
---|
| 56 | } else {
|
---|
| 57 | sb.Append("; ");
|
---|
| 58 | }
|
---|
| 59 | sb.Append(String.Format("{0}: {1}", item.Key, item.Value));
|
---|
| 60 | }
|
---|
| 61 | return sb.ToString();
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | public virtual string ItemName {
|
---|
| 65 | get { return ItemAttribute.GetName(this.GetType()); }
|
---|
| 66 | }
|
---|
| 67 | public virtual string ItemDescription {
|
---|
| 68 | get { return ItemAttribute.GetDescription(this.GetType()); }
|
---|
| 69 | }
|
---|
| 70 | public Version ItemVersion {
|
---|
| 71 | get { return ItemAttribute.GetVersion(this.GetType()); }
|
---|
| 72 | }
|
---|
| 73 | public static Image StaticItemImage {
|
---|
| 74 | get { return HeuristicLab.Common.Resources.VSImageLibrary.Class; }
|
---|
| 75 | }
|
---|
| 76 | public virtual Image ItemImage {
|
---|
| 77 | get { return ItemAttribute.GetImage(this.GetType()); }
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | public virtual IDeepCloneable Clone(Cloner cloner) {
|
---|
[9194] | 81 | return new VariableVectorInput(this, cloner);
|
---|
| 82 | }
|
---|
[9226] | 83 |
|
---|
| 84 | public object Clone() {
|
---|
| 85 | return Clone(new Cloner());
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | public event EventHandler ItemImageChanged;
|
---|
| 89 | protected virtual void OnItemImageChanged() {
|
---|
| 90 | EventHandler handler = ItemImageChanged;
|
---|
| 91 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
| 92 | }
|
---|
| 93 | public event EventHandler ToStringChanged;
|
---|
| 94 | protected virtual void OnToStringChanged() {
|
---|
| 95 | EventHandler handler = ToStringChanged;
|
---|
| 96 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
| 97 | }
|
---|
[9194] | 98 | }
|
---|
| 99 | }
|
---|