Free cookie consent management tool by TermsFeed Policy Generator

source: branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/VariableVectorInput.cs @ 9226

Last change on this file since 9226 was 9226, checked in by sforsten, 11 years ago

#1980:

  • made classes in Problems.ConditionActionClassification abstract
  • added Problems.VariableVectorClassification and Problems.CombinedIntegerVectorClassification
  • LCS works now with arbitrary problems, which implement ConditionActionClassificationProblem
File size: 3.4 KB
Line 
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
22using System;
23using System.Collections.Generic;
24using System.Drawing;
25using System.Linq;
26using System.Text;
27using HeuristicLab.Common;
28using HeuristicLab.Core;
29using HeuristicLab.Encodings.ConditionActionEncoding;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31
32namespace HeuristicLab.Encodings.VariableVector {
33  [StorableClass]
34  [Item("VariableVectorInput", "")]
35  public class VariableVectorInput : Dictionary<string, string>, IInput {
36
37    public IOrderedEnumerable<string> Order { get { return this.Keys.OrderBy(x => x); } }
38
39    [StorableConstructor]
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      }
45    }
46    public VariableVectorInput() : base() { }
47    public VariableVectorInput(int capacity) : base(capacity) { }
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) {
81      return new VariableVectorInput(this, cloner);
82    }
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    }
98  }
99}
Note: See TracBrowser for help on using the repository browser.