Free cookie consent management tool by TermsFeed Policy Generator

source: branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/DecisionListInput.cs @ 10377

Last change on this file since 10377 was 9392, checked in by sforsten, 12 years ago

#1980:

  • several small bug fixes
  • added windowing technique ILAS to GAssist
  • GAssist and XCS work now with real-valued features
  • severely improved the performance of XCS
File size: 3.1 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.Linq;
25using System.Text;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Optimization.Operators.LCS;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Encodings.DecisionList {
32  [StorableClass]
33  [Item("DecisionListInput", "")]
34  public class DecisionListInput : Item, IGAssistInput {
35
36    [Storable]
37    private Dictionary<string, string> inputDictionary;
38    public Dictionary<string, string> InputDictionary {
39      get { return inputDictionary; }
40      protected set {
41        inputDictionary = value;
42      }
43    }
44
45    public IOrderedEnumerable<string> Order { get { return InputDictionary.Keys.OrderBy(x => x); } }
46
47    [StorableConstructor]
48    protected DecisionListInput(bool deserializing) { }
49    protected DecisionListInput(DecisionListInput original, Cloner cloner) {
50      InputDictionary = new Dictionary<string, string>(original.InputDictionary.Count);
51      foreach (var item in original.InputDictionary) {
52        InputDictionary.Add(item.Key, item.Value);
53      }
54    }
55    public DecisionListInput()
56      : base() {
57      InputDictionary = new Dictionary<string, string>();
58    }
59    public DecisionListInput(int capacity)
60      : base() {
61      InputDictionary = new Dictionary<string, string>(capacity);
62    }
63    public DecisionListInput(IDictionary<string, string> dictionary)
64      : base() {
65      InputDictionary = new Dictionary<string, string>(dictionary);
66    }
67    public override IDeepCloneable Clone(Cloner cloner) {
68      return new DecisionListInput(this, cloner);
69    }
70
71    public override string ToString() {
72      StringBuilder sb = new StringBuilder();
73      bool first = true;
74      foreach (var item in InputDictionary) {
75        if (first) {
76          first = false;
77        } else {
78          sb.Append("; ");
79        }
80        sb.Append(String.Format("{0}: {1}", item.Key, item.Value));
81      }
82      return sb.ToString();
83    }
84
85    #region IGAssistInput Members
86    public IEnumerable<string> VariableNames {
87      get { return inputDictionary.Keys; }
88    }
89    public string GetVariableValue(string variableName) {
90      return inputDictionary[variableName];
91    }
92    #endregion
93  }
94}
Note: See TracBrowser for help on using the repository browser.