- Timestamp:
- 05/02/17 20:42:40 (8 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/IEnabledExpressionsConfiguration.cs
r14834 r14905 22 22 IList<string> EnabledExpressions { get; } 23 23 24 void EnableStack(StackTypes types, bool enableExpressions = false);25 void DisableStack(StackTypes type, bool disableExpressions = false);26 void SetStack(StackTypes type, bool state, bool cascadeForExpressions = false);24 void EnableStack(StackTypes types, bool enableExpressions = true, bool enableDependencies = true); 25 void DisableStack(StackTypes type, bool disableExpressions = true, bool enableDepenencies = true); 26 void SetStack(StackTypes type, bool state, bool setExpressions = true, bool setDependencies = true); 27 27 void EnableExpressionOfStack(StackTypes types); 28 void DisableExpression OfStack(StackTypes types);28 void DisableExpressionsOfStack(StackTypes types); 29 29 void EnableExpression(string name, bool enableStackIfDisabled = false); 30 30 void DisableExpression(string name, bool disableStackIfEnabled = false); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/PushConfiguration.cs
r14897 r14905 3 3 using System.Collections.Generic; 4 4 using System.Linq; 5 using Attributes;6 5 using Base.Erc; 7 6 using Common; … … 174 173 175 174 if (types.HasFlag(type)) 176 EnableStack(type, true);175 EnableStack(type, false, true); 177 176 } 178 177 } 179 178 180 179 public void EnableExpressionOfStack(StackTypes types) { 181 var names = ExpressionTable.StackTypeToNamesTable[types] 182 .Except(EnabledExpressions) 183 .ToArray(); 184 185 foreach (var name in names) 180 EnableExpressions(ExpressionTable.StackTypeToNamesTable[types]); 181 } 182 183 public void EnableExpressionDependentOnStack(StackTypes types) { 184 var names = ExpressionTable.StackDependencyToNamesTable[types].Where( 185 name => { 186 var type = ExpressionTable.NameToTypeTable[name]; 187 var attribute = ExpressionTable.TypeToAttributeTable[type]; 188 189 return (attribute.StackType | attribute.AdditionalStackDependencies) 190 .ToEnumerable() 191 .All(st => enabledStacks.ContainsKey(st) && enabledStacks[st]); 192 }); 193 194 EnableExpressions(names); 195 } 196 197 private void EnableExpressions(IEnumerable<string> names) { 198 foreach (var name in names.Except(EnabledExpressions)) 186 199 EnabledExpressions.Add(name); 187 200 … … 191 204 } 192 205 193 public void DisableExpressionOfStack(StackTypes types) { 194 var names = ExpressionTable.StackTypeToNamesTable[types] 195 .Intersect(EnabledExpressions) 196 .ToArray(); 197 198 foreach (var name in names) 206 public void DisableExpressionsOfStack(StackTypes types) { 207 DisableExpressions(ExpressionTable.StackTypeToNamesTable[types]); 208 } 209 210 public void DisableExpressionsDependentOnStack(StackTypes types) { 211 var names = ExpressionTable.StackDependencyToNamesTable 212 .Where(pair => pair.Key.HasFlag(types)) 213 .SelectMany(pair => pair.Value); 214 215 DisableExpressions(names); 216 } 217 218 private void DisableExpressions(IEnumerable<string> names) { 219 foreach (var name in names.Intersect(EnabledExpressions)) 199 220 EnabledExpressions.Remove(name); 200 221 … … 241 262 242 263 public void EnableExpression<T>(bool enableStackIfDisabled = false) where T : Expression { 243 var attribute = (PushExpressionAttribute)Attribute.GetCustomAttribute(typeof(T), typeof(PushExpressionAttribute));264 var attribute = ExpressionTable.TypeToAttributeTable[typeof(T)]; 244 265 EnableExpression(attribute.ExpressionName, enableStackIfDisabled); 245 266 } 246 267 247 268 public void DisableExpression<T>(bool disableStackIfEnabled = false) where T : Expression { 248 var attribute = (PushExpressionAttribute)Attribute.GetCustomAttribute(typeof(T), typeof(PushExpressionAttribute));269 var attribute = ExpressionTable.TypeToAttributeTable[typeof(T)]; 249 270 DisableExpression(attribute.ExpressionName, disableStackIfEnabled); 250 271 } … … 260 281 } 261 282 262 public void EnableStack(StackTypes type, bool enableExpressions = false) {283 public void EnableStack(StackTypes type, bool enableExpressions = true, bool enableDependencies = true) { 263 284 enabledStacks[type] = true; 264 285 265 if (enableExpressions) 266 EnableExpressionOfStack(type);267 } 268 269 public void DisableStack(StackTypes type, bool disableExpressions = false) {286 if (enableExpressions) EnableExpressionOfStack(type); 287 if (enableDependencies) EnableExpressionDependentOnStack(type); 288 } 289 290 public void DisableStack(StackTypes type, bool disableExpressions = true, bool disableDependencies = true) { 270 291 enabledStacks[type] = false; 271 292 272 if (disableExpressions) 273 DisableExpressionOfStack(type);274 } 275 276 public void SetStack(StackTypes type, bool state, bool cascadeForExpressions = false) {277 if (state) EnableStack(type, cascadeForExpressions);278 else DisableStack(type, cascadeForExpressions);293 if (disableExpressions) DisableExpressionsOfStack(type); 294 if (disableDependencies) DisableExpressionsDependentOnStack(type); 295 } 296 297 public void SetStack(StackTypes type, bool state, bool setExpressions = true, bool setDependencies = true) { 298 if (state) EnableStack(type, setExpressions, setDependencies); 299 else DisableStack(type, setExpressions, setDependencies); 279 300 } 280 301 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/BooleanExpressions.cs
r14875 r14905 11 11 [PushExpression(StackTypes.Boolean, "BOOLEAN.AND")] 12 12 public class BooleanAndExpression : StatelessExpression { 13 public override bool Eval(IInternalPushInterpreter interpreter) {14 if (interpreter.BooleanStack.Count < 2)15 return false;13 public bool IsNoop(IInternalPushInterpreter interpreter) { 14 return interpreter.BooleanStack.Count < 2; 15 } 16 16 17 public void TryEval(IInternalPushInterpreter interpreter) { 17 18 var first = interpreter.BooleanStack.Pop(); 18 19 var second = interpreter.BooleanStack.Top; … … 20 21 21 22 interpreter.BooleanStack.SetTop(result); 23 } 24 25 public override bool Eval(IInternalPushInterpreter interpreter) { 26 if (IsNoop(interpreter)) 27 return false; 28 29 TryEval(interpreter); 22 30 return true; 23 31 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/Expression.cs
r14834 r14905 2 2 using System; 3 3 using System.Collections.Generic; 4 5 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;6 4 using HeuristicLab.Problems.ProgramSynthesis.Push.Data.Pool; 7 5 … … 10 8 [Serializable] 11 9 public abstract class Expression : IPooledObject { 12 public bool IsProgram { get { return this.GetType() == typeof(PushProgram); } }10 public bool IsProgram { get { return GetType() == typeof(PushProgram); } } 13 11 14 12 public static readonly IReadOnlyCollection<Expression> EmptyContainer = new Expression[0]; … … 18 16 get 19 17 { 20 var attribute = (PushExpressionAttribute)Attribute.GetCustomAttribute(this.GetType(), typeof(PushExpressionAttribute)); 21 22 return attribute != null 23 ? attribute.ExpressionName 24 : string.Empty; 18 return ExpressionTable.TypeToAttributeTable[GetType()].ExpressionName; 25 19 } 26 20 } 21 22 //public abstract bool IsNoop(IInternalPushInterpreter interpreter); 27 23 28 24 public abstract bool Eval(IInternalPushInterpreter interpreter); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/BenchmarkSuite/PushBenchmarkSuiteProblem.cs
r14897 r14905 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Problem.BenchmarkSuite { 2 using System.Linq;3 2 using Common; 4 3 using Configuration; 5 4 using Core; 6 5 using Encodings.IntegerVectorEncoding; 7 using Expressions;8 6 using HeuristicLab.BenchmarkSuite.Problems; 9 7 using Instances; … … 46 44 config.SetEnabledStacks((StackTypes)data.EnabledDataTypes); 47 45 48 // update enabled stack types49 foreach (var stackType in ExpressionTable.StackTypeToNamesTable.Keys) {50 var enable = config.EnabledExpressions.Intersect(ExpressionTable.StackTypeToNamesTable[stackType]).Any();51 config.SetStack(stackType, enable);52 }53 54 46 Encoding.Bounds[0, 0] = 0; 55 47 Encoding.Bounds[0, 1] = config.EnabledExpressions.Count; … … 63 55 IReadOnlyPushConfiguration config, 64 56 IPushEvaluator evaluator) { 65 return new PushBenchmarkSuiteSolution(vector, bestQuality, random, config, (PushBenchmarkSuiteEvaluator)PushEvaluator.Clone());57 return new PushBenchmarkSuiteSolution(vector, bestQuality, random, (IReadOnlyPushConfiguration)config.Clone(), (PushBenchmarkSuiteEvaluator)PushEvaluator.Clone()); 66 58 } 67 59 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Views/ExpressionSelectionView.cs
r14834 r14905 52 52 53 53 if (e.Node.Parent == null) { 54 Content.SetStack(stackType, e.Node.Checked, true );54 Content.SetStack(stackType, e.Node.Checked, true, false); 55 55 SetStackNodeText(e.Node); 56 56 foreach (var subNode in e.Node.Nodes.OfType<TreeNode>().Where(n => n.Checked != e.Node.Checked))
Note: See TracChangeset
for help on using the changeset viewer.