Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/10/13 15:15:13 (11 years ago)
Author:
sforsten
Message:

#1980:

  • added DecisionListView
  • added event handlers in *ProblemData
  • renamed project Problems.XCS.Views to Problems.lCS.Views and Problems.Instances.ConditionActionClassification to Problems.Instances.LCS
  • integrated niching in GAssist and added NichingTournamentSelector
  • minor code improvements and property changes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Action/StringAction.cs

    r9334 r9352  
    2525using HeuristicLab.Common;
    2626using HeuristicLab.Core;
     27using HeuristicLab.Optimization.Operators.LCS;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2829
     
    3132  [Item("StringAction", "")]
    3233  public class StringAction : Item, IAction<string> {
     34
     35    public static IEqualityComparer<IGAssistNiche> Comparer {
     36      get { return new DecisionListNicheComparer(); }
     37    }
     38
     39    IEqualityComparer<IGAssistNiche> IGAssistNiche.Comparer {
     40      get { return Comparer; }
     41    }
    3342
    3443    [Storable]
     
    92101    }
    93102
     103    public void Randomize(IRandom random, IEnumerable<IAction> except) {
     104      if (except.Count() == 0) {
     105        Randomize(random);
     106        return;
     107      }
     108      try {
     109        var exceptInt = except.Cast<StringAction>().Select(x => x.CurrentActionIndex);
     110        var newPossibleFeatures = Enumerable.Range(0, possibleFeatures.Count()).Except(exceptInt);
     111        currentActionIndex = newPossibleFeatures.ElementAt(random.Next(0, newPossibleFeatures.Count()));
     112      }
     113      catch (InvalidCastException) {
     114        throw new InvalidCastException("Actions have to be of type IntAction");
     115      }
     116    }
     117
    94118    public bool Match(IAction action) {
    95119      var targetCast = action as StringAction;
     
    107131
    108132    public override string ToString() {
    109       return CurrentAction;
     133      return variableName + ": " + CurrentAction;
     134    }
     135
     136    public bool SameNiche(IGAssistNiche niche) {
     137      return Match(niche as IAction);
     138    }
     139
     140    public int GetNicheHashCode() {
     141      int result = 1;
     142      result = 37 * result + currentActionIndex;
     143      result = 37 * result + variableName.GetHashCode();
     144      foreach (var feature in possibleFeatures) {
     145        result = 37 * result + feature.GetHashCode();
     146      }
     147      return result;
    110148    }
    111149  }
Note: See TracChangeset for help on using the changeset viewer.