Changeset 9352 for branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Action
- Timestamp:
- 04/10/13 15:15:13 (11 years ago)
- Location:
- branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Action
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Action/IAction.cs
r9334 r9352 22 22 using System.Collections.Generic; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Optimization.Operators.LCS; 24 25 25 26 namespace HeuristicLab.Encodings.DecisionList { 26 public interface IAction : I Item{27 public interface IAction : IGAssistNiche { 27 28 string VariableName { get; } 28 29 29 30 int Possibilities { get; } 30 31 void Randomize(IRandom random); 32 void Randomize(IRandom random, IEnumerable<IAction> except); 31 33 32 34 bool Match(IAction action); -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Action/IntAction.cs
r9334 r9352 25 25 using HeuristicLab.Common; 26 26 using HeuristicLab.Core; 27 using HeuristicLab.Optimization.Operators.LCS; 27 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 29 … … 31 32 [Item("IntAction", "")] 32 33 public class IntAction : Item, IAction<int> { 34 35 public static IEqualityComparer<IGAssistNiche> Comparer { 36 get { return new DecisionListNicheComparer(); } 37 } 38 IEqualityComparer<IGAssistNiche> IGAssistNiche.Comparer { 39 get { return Comparer; } 40 } 33 41 34 42 [Storable] … … 88 96 } 89 97 98 public void Randomize(IRandom random, IEnumerable<IAction> except) { 99 if (except.Count() == 0) { 100 Randomize(random); 101 return; 102 } 103 try { 104 var exceptInt = except.Cast<IntAction>().Select(x => x.currentAction); 105 var newPossibleFeatures = possibleFeatures.Except(exceptInt); 106 currentAction = newPossibleFeatures.ElementAt(random.Next(0, newPossibleFeatures.Count())); 107 } 108 catch (InvalidCastException) { 109 throw new InvalidCastException("Actions have to be of type IntAction"); 110 } 111 } 112 90 113 public bool Match(IAction action) { 91 114 var targetCast = action as IntAction; … … 103 126 104 127 public override string ToString() { 105 return currentAction.ToString(); 128 return variableName + ": " + currentAction.ToString(); 129 } 130 131 public bool SameNiche(IGAssistNiche niche) { 132 return Match(niche as IAction); 133 } 134 135 public int GetNicheHashCode() { 136 int result = 1; 137 result = 37 * result + currentAction; 138 result = 37 * result + variableName.GetHashCode(); 139 foreach (var feature in possibleFeatures) { 140 result = 37 * result + feature; 141 } 142 return result; 106 143 } 107 144 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Action/StringAction.cs
r9334 r9352 25 25 using HeuristicLab.Common; 26 26 using HeuristicLab.Core; 27 using HeuristicLab.Optimization.Operators.LCS; 27 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 29 … … 31 32 [Item("StringAction", "")] 32 33 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 } 33 42 34 43 [Storable] … … 92 101 } 93 102 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 94 118 public bool Match(IAction action) { 95 119 var targetCast = action as StringAction; … … 107 131 108 132 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; 110 148 } 111 149 }
Note: See TracChangeset
for help on using the changeset viewer.