Changeset 14905 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration
- Timestamp:
- 05/02/17 20:42:40 (8 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration
- Files:
-
- 2 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
Note: See TracChangeset
for help on using the changeset viewer.