- Timestamp:
- 07/10/17 21:36:03 (7 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis
- Files:
-
- 11 added
- 42 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/HeuristicLab.Problems.ProgramSynthesis.csproj
r15032 r15189 136 136 <Compile Include="Push\Data\Tree\TreeExtensions.cs" /> 137 137 <Compile Include="Push\Data\Tree\TreeNode.cs" /> 138 <Compile Include="Push\Constants\ Environment.cs" />138 <Compile Include="Push\Constants\PushEnvironment.cs" /> 139 139 <Compile Include="Push\Exporter\Exporter.cs" /> 140 140 <Compile Include="Push\Expressions\BooleanExpressions.cs" /> … … 153 153 <Compile Include="Push\Expressions\FloatExpressions.cs" /> 154 154 <Compile Include="Push\Expressions\FlushExpressions.cs" /> 155 <Compile Include="Push\Expressions\InExpressions.cs" /> 155 156 <Compile Include="Push\Expressions\IntegerExpressions.cs" /> 156 157 <Compile Include="Push\Expressions\NameExpressions.cs" /> … … 194 195 <Compile Include="Push\Extensions\ControlExntensions.cs" /> 195 196 <Compile Include="Push\Extensions\EnumExtensions.cs" /> 197 <Compile Include="Push\Extensions\ProblemDataExtensions.cs" /> 196 198 <Compile Include="Push\Extensions\LongExtensions.cs" /> 197 199 <Compile Include="Push\Extensions\RandomExtensions.cs" /> 200 <Compile Include="Push\Extensions\StringBuilderExtensions.cs" /> 198 201 <Compile Include="Push\Generators\CodeGenerator\CodeGeneratorUtils.cs" /> 199 202 <Compile Include="Push\Generators\CodeGenerator\LinearCodeGenerator.cs" /> 200 203 <Compile Include="Push\Generators\CodeGenerator\RecursiveCodeGenerator.cs" /> 204 <Compile Include="Push\Individual\InduvidualMapper.cs" /> 201 205 <Compile Include="Push\Interpreter\Extensions.cs" /> 202 206 <Compile Include="Push\Interpreter\IInternalPushInterpreter.cs" /> … … 208 212 <Compile Include="Push\Interpreter\PushInterpreter.cs" /> 209 213 <Compile Include="Push\Interpreter\PushInterpreterPool.cs" /> 214 <Compile Include="Push\ObjectPools\StringBuilderPool.cs" /> 210 215 <Compile Include="Push\Parser\PushParser.cs" /> 211 216 <Compile Include="Push\Problem\BenchmarkSuite\PushBenchmarkSuiteSolution.cs" /> 212 217 <Compile Include="Push\Problem\DataBounds.cs" /> 213 218 <Compile Include="Push\Problem\EvaluationResult.cs" /> 214 <Compile Include="Push\ Problem\IndividualMapper.cs" />219 <Compile Include="Push\Individual\IndividualExtensions.cs" /> 215 220 <Compile Include="Push\Problem\BenchmarkSuite\PushBenchmarkSuiteEvaluator.cs" /> 216 221 <Compile Include="Push\Problem\BenchmarkSuite\PushBenchmarkSuiteProblem.cs" /> … … 223 228 <Compile Include="Push\Selector\LexicaseSelector.cs" /> 224 229 <Compile Include="Push\Simplifier\Simplifier.cs" /> 230 <Compile Include="Push\Stack\IPrintStack.cs" /> 225 231 <Compile Include="Push\Stack\IPushStack.cs" /> 226 232 <Compile Include="Push\Stack\IPushStackBase.cs" /> 233 <Compile Include="Push\Stack\PrintStack.cs" /> 227 234 <Compile Include="Push\Stack\PushStack.cs" /> 228 235 <Compile Include="Push\Stack\InterpreterStackStringifier.cs" /> -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Analyzer/PushExpressionFrequencyAnalyzer.cs
r15033 r15189 14 14 using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration; 15 15 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 16 using HeuristicLab.Problems.ProgramSynthesis.Push. Problem;16 using HeuristicLab.Problems.ProgramSynthesis.Push.Individual; 17 17 18 18 /// <summary> … … 35 35 Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The result collection where the symbol frequencies should be stored.")); 36 36 37 Parameters.Add(new FixedValueParameter<BoolValue>(AggregateStackTypesParameterName, "Determines if expressions should be aggregated by their primary stack type." ));37 Parameters.Add(new FixedValueParameter<BoolValue>(AggregateStackTypesParameterName, "Determines if expressions should be aggregated by their primary stack type.", new BoolValue(true))); 38 38 } 39 39 … … 84 84 var config = PushConfigurationParameter.ActualValue; 85 85 var integerVectors = IntegerVectorParameter.ActualValue; 86 var pushPrograms = integerVectors.Select(iv => iv.ToPushProgram(config)) .ToArray();86 var pushPrograms = integerVectors.Select(iv => iv.ToPushProgram(config)); 87 87 88 88 var results = ResultsParameter.ActualValue; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/PushConfigurationBase.cs
r15032 r15189 48 48 set 49 49 { 50 var removedExpressions = enabledExpressions.To Array();50 var removedExpressions = enabledExpressions.ToList(); 51 51 enabledExpressions.Clear(); 52 52 enabledExpressions.AddRange(value); … … 68 68 var attribute = ExpressionTable.TypeToAttributeTable[type]; 69 69 70 expressionsPerStackCount[attribute.StackType]++; 70 if (expressionsPerStackCount.ContainsKey(attribute.StackType)) { 71 expressionsPerStackCount[attribute.StackType]++; 72 } 71 73 72 74 foreach (var additionalStackType in attribute.AdditionalStackDependencies.ToValues()) … … 150 152 151 153 enabledExpressions.Add(expressionName); 152 expressionsPerStackCount[attribute.StackType]++; 153 foreach (var additionalStackType in attribute.AdditionalStackDependencies.ToValues()) 154 155 if (expressionsPerStackCount.ContainsKey(attribute.StackType)) 156 expressionsPerStackCount[attribute.StackType]++; 157 158 foreach (var additionalStackType in attribute.AdditionalStackDependencies.ToValues().Where(expressionsPerStackCount.ContainsKey)) 154 159 expressionsPerStackCount[additionalStackType]++; 155 160 … … 172 177 173 178 enabledExpressions.Remove(expressionName); 174 expressionsPerStackCount[attribute.StackType]--; 175 foreach (var additionalStackType in attribute.AdditionalStackDependencies.ToValues()) 179 180 if (expressionsPerStackCount.ContainsKey(attribute.StackType)) 181 expressionsPerStackCount[attribute.StackType]--; 182 183 foreach (var additionalStackType in attribute.AdditionalStackDependencies.ToValues().Where(expressionsPerStackCount.ContainsKey)) 176 184 expressionsPerStackCount[additionalStackType]--; 177 185 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Pool/IPooledObject.cs
r14777 r15189 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Data.Pool { 2 2 public interface IPooledObject { 3 void Init(); 3 4 void Reset(); 4 5 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Pool/ManagedPoolProvider.cs
r15017 r15189 10 10 public interface IManagedPool<T> : IDisposable where T : class, IPooledObject { 11 11 T Get(bool reset = true); 12 void Release(); 12 13 } 13 14 … … 17 18 private readonly BinaryFormatter binaryFormatter = new BinaryFormatter(); 18 19 private byte[] dummyPartition; 20 private static volatile object dummyCreationLockObject = new object(); 19 21 20 22 private static readonly FieldInfo InternalListArrayProperty = typeof(List<T[]>).GetField( … … 37 39 public int InstanceCount { get { return partitions.Count * PartitionSize; } } 38 40 39 private void InitDummyPartition(Func<T> factory) {40 var temp = new T[PartitionSize];41 42 for (var i = 0u; i < PartitionSize; i++) {43 temp[i] = factory();44 }45 46 using (var memoryStream = new MemoryStream()) {47 binaryFormatter.Serialize(memoryStream, temp);48 dummyPartition = memoryStream.ToArray();49 }50 }51 52 41 public void Clear() { 42 dummyPartition = null; 43 managedPools.Clear(); 53 44 partitions.Clear(); 54 45 } … … 65 56 66 57 private T[] CloneDummyPartition() { 67 if (dummyPartition == null) 68 InitDummyPartition(factory); 58 if (dummyPartition == null) { 59 lock (dummyCreationLockObject) { 60 if (dummyPartition == null) { 61 var temp = new T[PartitionSize]; 62 63 for (var i = 0u; i < PartitionSize; i++) { 64 temp[i] = factory(); 65 } 66 67 using (var memoryStream = new MemoryStream()) { 68 binaryFormatter.Serialize(memoryStream, temp); 69 dummyPartition = memoryStream.ToArray(); 70 } 71 } 72 } 73 } 69 74 70 75 using (var memoryStream = new MemoryStream(dummyPartition)) { 71 76 memoryStream.Seek(0, SeekOrigin.Begin); 72 77 73 return (T[])binaryFormatter.Deserialize(memoryStream); 78 var result = (T[])binaryFormatter.Deserialize(memoryStream); 79 80 for (var i = 0; i < result.Length; i++) 81 result[i].Init(); 82 83 return result; 74 84 } 75 85 } … … 102 112 } 103 113 104 public void Dispose() {114 public void Release() { 105 115 if (partitions.Count > 0) { 106 116 provider.ReleasePartitions(partitions); … … 109 119 entryIndex = provider.PartitionSize; 110 120 } 121 } 122 123 public void Dispose() { 124 Release(); 111 125 112 126 provider.managedPools.Free(this); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Pool/ObjectPool.cs
r14777 r15189 6 6 7 7 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Data.Pool { 8 using System.Collections.Generic; 8 9 using System.Threading; 9 10 … … 102 103 } 103 104 } 105 106 public void Clear() { 107 for (int i = 0; i < _items.Length; i++) { 108 _items[i] = default(Element); 109 } 110 } 111 112 public IEnumerable<T> Items 113 { 114 get 115 { 116 var items = _items; 117 for (var i = 0; i < items.Length; i++) { 118 if (items[i].Value != null) { 119 yield return items[i].Value; 120 } 121 } 122 } 123 } 104 124 } 105 125 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Pool/PooledList.cs
r14908 r15189 6 6 [Serializable] 7 7 public class PooledList<T> : List<T>, IPooledObject { 8 public void Reset() { 8 public Guid Id { get; private set; } 9 10 void IPooledObject.Init() { 11 Id = Guid.NewGuid(); 12 } 13 14 void IPooledObject.Reset() { 9 15 Clear(); 10 16 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Pool/PooledObject.cs
r14908 r15189 20 20 } 21 21 22 void IPooledObject.Init() { } 23 22 24 public void Reset() { 23 25 resetor(item); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Tree/TreeExtensions.cs
r15017 r15189 81 81 } 82 82 83 return new PushProgram(expressions.To Array());83 return new PushProgram(expressions.ToList()); 84 84 } 85 85 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/CharExpressions.cs
r15032 r15189 151 151 152 152 public override void Eval(IInternalPushInterpreter interpreter) { 153 var chars = interpreter.StringStack.Pop().Reverse().To Array();153 var chars = interpreter.StringStack.Pop().Reverse().ToList(); 154 154 interpreter.CharStack.Push(chars); 155 155 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/Expression.cs
r15017 r15189 43 43 44 44 public object Clone() { 45 return Clone(new Cloner()); 46 } 47 48 public virtual IDeepCloneable Clone(Cloner cloner) { 45 49 return this; 46 50 } 47 51 48 public IDeepCloneable Clone(Cloner cloner) { 49 return this; 50 } 52 void IPooledObject.Init() { } 51 53 52 54 void IPooledObject.Reset() { } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/ExpressionTable.cs
r15032 r15189 25 25 26 26 static ExpressionTable() { 27 StatelessExpressionTypes = GetExpressionTypes(typeof(StatelessExpression)).To Array();28 StatefulExpressionTypes = GetExpressionTypes(typeof(StatefulExpression<>)).To Array();27 StatelessExpressionTypes = GetExpressionTypes(typeof(StatelessExpression)).ToList(); 28 StatefulExpressionTypes = GetExpressionTypes(typeof(StatefulExpression<>)).ToList(); 29 29 30 30 StatelessExpressionTable = GetStatelessExpressionTable(); … … 35 35 .Where(t => typeToNameTable.ContainsKey(t)) 36 36 .Select(type => typeToNameTable[type]) 37 .To Array();37 .ToList(); 38 38 39 39 ExpressionCount = StatelessExpressionTable.Count + StatefulExpressionFactory.Count; … … 57 57 dictionary.Add(type, expression); 58 58 59 // do not index hidden expressions like push expression in tables60 if (attribute.IsHidden) continue;59 //// do not index hidden expressions like push expression in tables 60 //if (attribute.IsHidden) continue; 61 61 62 62 indexToNameTable.Add(indexToNameTable.Keys.Count, attribute.Name); … … 156 156 .Where(entry => (entry.Key & ~allowedTypes) == 0x0) 157 157 .SelectMany(entry => entry.Value) 158 .To Array();158 .ToList(); 159 159 } 160 160 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/PrintExpressions.cs
r15032 r15189 2 2 using System.Collections.Generic; 3 3 using System.Globalization; 4 using System.Text;5 4 using Attributes; 6 5 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 7 6 using HeuristicLab.Problems.ProgramSynthesis.Push.Constants; 7 8 8 using Interpreter; 9 9 using Stack; … … 21 21 22 22 public override void Eval(IInternalPushInterpreter interpreter) { 23 interpreter.PrintStack. Push(string.Empty);23 interpreter.PrintStack.NewLine(); 24 24 } 25 25 } … … 28 28 public abstract class PrintExpression<T> : StatelessExpression { 29 29 protected PrintExpression() { } 30 30 31 [StorableConstructor] 31 32 protected PrintExpression(bool deserializing) : base(deserializing) { } 32 33 33 34 protected void Eval(IInternalPushInterpreter interpreter, IPushStack<T> stack) { 34 var value = stack.Pop().ToString(); 35 36 if (interpreter.PrintStack.IsEmpty) 37 interpreter.PrintStack.Push(value); 38 else 39 interpreter.PrintStack.Top += value; 35 var value = stack.Pop(); 36 37 interpreter.PrintStack.Push(value); 40 38 } 41 39 42 40 protected void EvalVector(IInternalPushInterpreter interpreter, IPushStack<IReadOnlyList<T>> vectorStack) { 43 var sb = new StringBuilder();44 41 var vector = vectorStack.Pop(); 45 42 46 sb.Append(PushEnvironment.VectorStartSymbol);43 interpreter.PrintStack.Push(PushEnvironment.VectorStartSymbol); 47 44 48 45 if (vector.Count > 0) { 49 sb.Append(vector[0]);46 interpreter.PrintStack.Push(vector[0]); 50 47 51 48 for (var i = 1; i < vector.Count; i++) { 52 sb.Append(PushEnvironment.VectorSeparatorSymbol);53 sb.Append(vector[i]);49 interpreter.PrintStack.Push(PushEnvironment.VectorSeparatorSymbol); 50 interpreter.PrintStack.Push(vector[i]); 54 51 } 55 52 } 56 53 57 sb.Append(PushEnvironment.VectorEndSymbol); 58 59 var value = sb.ToString(); 60 interpreter.PrintStack.Push(value); 54 interpreter.PrintStack.Push(PushEnvironment.VectorEndSymbol); 61 55 } 62 56 } … … 165 159 166 160 public override void Eval(IInternalPushInterpreter interpreter) { 167 Eval(interpreter, interpreter.IntegerStack); 161 var value = interpreter.IntegerStack.Pop(); 162 interpreter.PrintStack.Push(value); 168 163 } 169 164 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/PushProgram.cs
r15017 r15189 8 8 using Data.Pool; 9 9 using Extensions; 10 11 using HeuristicLab.Common; 12 10 13 using Interpreter; 11 14 using Persistence.Default.CompositeSerializers.Storable; … … 41 44 } 42 45 46 public PushProgram(PushProgram origin, Cloner cloner) { 47 stringRepresentation = origin.stringRepresentation; 48 hashCode = origin.hashCode; 49 depth = origin.depth; 50 treeIndex = origin.treeIndex; 51 expressions = new List<Expression>(origin.expressions); 52 } 53 54 public override IDeepCloneable Clone(Cloner cloner) { 55 return new PushProgram(this, cloner); 56 } 57 43 58 public bool IsEmpty { get { return Count == 0; } } 44 59 public int Count { get { return expressions.Count; } } … … 51 66 return program; 52 67 } 68 69 void IPooledObject.Init() { } 53 70 54 71 void IPooledObject.Reset() { … … 263 280 yield return sub; 264 281 else yield return expr; 282 } 283 } 284 285 public IReadOnlyList<Expression> Flatten() { 286 var result = new List<Expression>(); 287 Flatten(result); 288 return result; 289 } 290 291 private void Flatten(List<Expression> result) { 292 result.AddRange(expressions); 293 294 for (var i = 0; i < expressions.Count; i++) { 295 var expr = expressions[i]; 296 if (expr.IsProgram) { 297 ((PushProgram)expr).Flatten(result); 298 } 265 299 } 266 300 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/StatefulExpression.cs
r15017 r15189 69 69 } 70 70 71 void IPooledObject.Init() { } 72 71 73 public void Reset() { 72 74 State = default(T); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/StringExpressions.cs
r15032 r15189 453 453 .Where(x => !string.IsNullOrWhiteSpace(x)) 454 454 .Reverse() 455 .To Array();456 457 if (words. Length== 0) {455 .ToList(); 456 457 if (words.Count == 0) { 458 458 interpreter.StringStack.Pop(); 459 459 } else { -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorButLastExpressions.cs
r15032 r15189 25 25 vectorStack.Top = vectorStack.Top 26 26 .Take(vectorStack.Top.Count - 1) 27 .To Array();27 .ToList(); 28 28 } 29 29 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorIterateExpressions.cs
r15032 r15189 56 56 } 57 57 58 vectorStack.Top = vector.Take(last).To Array();58 vectorStack.Top = vector.Take(last).ToList(); 59 59 } 60 60 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorPushAllExpressions.cs
r15032 r15189 23 23 24 24 protected void Eval(IPushStack<IReadOnlyList<T>> vectorStack, IPushStack<T> literalStack) { 25 var vector = vectorStack.Pop().Reverse().To Array();25 var vector = vectorStack.Pop().Reverse().ToList(); 26 26 literalStack.Push(vector); 27 27 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorRemoveExpressions.cs
r15032 r15189 25 25 protected void Eval(IPushStack<IReadOnlyList<T>> vectorStack, IPushStack<T> literalStack) { 26 26 var literal = literalStack.Pop(); 27 vectorStack.Top = vectorStack.Top.Where(x => !x.Equals(literal)).To Array();27 vectorStack.Top = vectorStack.Top.Where(x => !x.Equals(literal)).ToList(); 28 28 } 29 29 } … … 92 92 [PushExpression( 93 93 StackTypes.StringVector, 94 "STRING[].REMOVE", 94 95 "Removes all occurrences of the top STRING in the top STRING[].", 95 "STRING[].REMOVE",96 96 StackTypes.String)] 97 97 public class StringVectorRemoveExpression : VectorRemoveExpression<string> { -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorRestExpressions.cs
r15032 r15189 42 42 } 43 43 44 vectorStack.Top = vector.Skip(1).To Array();44 vectorStack.Top = vector.Skip(1).ToList(); 45 45 } 46 46 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorReverseExpressions.cs
r15032 r15189 25 25 26 26 protected void Eval(IPushStack<IReadOnlyList<T>> vectorStack) { 27 vectorStack.Top = vectorStack.Top.Reverse().To Array();27 vectorStack.Top = vectorStack.Top.Reverse().ToList(); 28 28 } 29 29 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorSubExpressions.cs
r15032 r15189 51 51 } 52 52 53 vectorStack.Top = vector.Skip(first).Take(lenght).To Array();53 vectorStack.Top = vector.Skip(first).Take(lenght).ToList(); 54 54 } 55 55 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorTakeExpressions.cs
r15032 r15189 53 53 } 54 54 55 vectorStack.Top = vector.Take(count).To Array();55 vectorStack.Top = vector.Take(count).ToList(); 56 56 } 57 57 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Generators/CodeGenerator/CodeGeneratorUtils.cs
r15017 r15189 38 38 IRandom random, 39 39 IReadOnlyErcOptions ercOptions) { 40 var x = random.NextDouble();41 Expression expression = null;40 //var x = random.NextDouble(); 41 //Expression expression = null; 42 42 43 if (x < ercOptions.ErcProbability) {44 var expressionType = ExpressionTable.NameToTypeTable[expressionName];45 expression = CreateRandomErcExpression(46 ExpressionTable.TypeToAttributeTable[expressionType].StackType,47 random,48 ercOptions);49 }43 //if (x < ercOptions.ErcProbability) { 44 // var expressionType = ExpressionTable.NameToTypeTable[expressionName]; 45 // expression = CreateRandomErcExpression( 46 // ExpressionTable.TypeToAttributeTable[expressionType].StackType, 47 // random, 48 // ercOptions); 49 //} 50 50 51 if (expression == null || expression is ExecNoopExpression) { 52 expression = ExpressionTable.GetExpression(expressionName); 53 } 51 //if (expression == null || expression is ExecNoopExpression) { 52 // expression = ExpressionTable.GetExpression(expressionName); 53 //} 54 55 //return expression; 56 57 var expression = ExpressionTable.GetExpression(expressionName); 54 58 55 59 return expression; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Generators/CodeGenerator/RecursiveCodeGenerator.cs
r14834 r15189 23 23 var code = RandomCode(maxPoints, random, pushGpConfiguration, customExpressions); 24 24 25 return PushProgram.Create(pool, code.To Array());25 return PushProgram.Create(pool, code.ToList()); 26 26 } 27 27 … … 29 29 var code = RandomCode(maxPoints, random, pushGpConfiguration, customExpressions); 30 30 31 return new PushProgram(code.To Array());31 return new PushProgram(code.ToList()); 32 32 } 33 33 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/Extensions.cs
r15017 r15189 25 25 26 26 public static Type GetStackEntryType(this StackTypes stackType) { 27 if (StackProperties.ContainsKey(stackType) && 28 StackProperties[stackType].PropertyType.IsGenericType) { 29 var genericTypeDef = StackProperties[stackType].PropertyType.GetGenericTypeDefinition(); 30 if (genericTypeDef == typeof(IPushStack<>)) 31 return genericTypeDef.GetGenericArguments()[0]; 32 } 33 27 34 return StackProperties.ContainsKey(stackType) 28 ? StackProperties[stackType].PropertyType.GetGenericArguments().Single() 35 ? StackProperties[stackType] 36 .PropertyType 37 .GetInterfaces() 38 .First(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IPushStack<>)) 39 .GetGenericArguments() 40 .First() 29 41 : null; 30 42 } 31 43 32 44 public static void PrintStacks(this IPushInterpreter interpreter) { 33 var stackTypesType = typeof(StackTypes); 34 35 foreach (StackTypes type in Enum.GetValues(stackTypesType)) { 36 if (!interpreter.Stacks.ContainsKey(type)) continue; 37 38 var stackName = Enum.GetName(stackTypesType, type); 39 var stack = interpreter.Stacks[type]; 45 foreach (var pair in interpreter.Stacks) { 46 var stackName = pair.Key.ToString(); 47 var stack = interpreter.Stacks[pair.Key]; 40 48 41 49 if (stack.IsEmpty || !stack.IsEnabled) continue; 42 50 43 var stackString = string.Join(" ", interpreter.StringifyStack( type).Reverse());51 var stackString = string.Join(" ", interpreter.StringifyStack(pair.Key).Reverse()); 44 52 Console.WriteLine("--------- {0} ---------\n{1}\n", stackName, stackString); 45 53 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/IInternalPushInterpreter.cs
r14834 r15189 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter { 2 using System.Collections.Generic; 3 4 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 5 2 6 public interface IInternalPushInterpreter : IPushInterpreter { 3 7 InterpreterPoolContainer PoolContainer { get; } 4 8 bool IsNameQuoteFlagSet { get; set; } 9 IReadOnlyList<Expression> InputExpressions { get; } 5 10 } 6 11 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/IPushInterpreter.cs
r15017 r15189 24 24 IPushStack<IReadOnlyList<bool>> BooleanVectorStack { get; } 25 25 IPushStack<IReadOnlyList<string>> StringVectorStack { get; } 26 IP ushStack<string>PrintStack { get; }26 IPrintStack PrintStack { get; } 27 27 IDictionary<string, Expression> CustomExpressions { get; } 28 28 IReadOnlyDictionary<StackTypes, IPushStack> Stacks { get; } … … 30 30 void Clear(); 31 31 void Reset(); 32 33 void SetInput( 34 IReadOnlyList<long> integers = null, 35 IReadOnlyList<double> floats = null, 36 IReadOnlyList<bool> booleans = null, 37 IReadOnlyList<char> chars = null, 38 IReadOnlyList<string> strings = null, 39 IReadOnlyList<IReadOnlyList<long>> integerVectors = null, 40 IReadOnlyList<IReadOnlyList<double>> floatVectors = null, 41 IReadOnlyList<IReadOnlyList<string>> stringVectors = null); 32 42 33 43 void Run(bool stepwise); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreter.cs
r15032 r15189 2 2 using System; 3 3 using System.Collections.Generic; 4 using System.Linq; 4 5 using System.Runtime.CompilerServices; 5 6 using System.Threading; … … 35 36 BooleanVectorStack = new PushStack<IReadOnlyList<bool>>(); 36 37 StringVectorStack = new PushStack<IReadOnlyList<string>>(); 37 PrintStack = new P ushStack<string>();38 PrintStack = new PrintStack(); 38 39 39 40 Stacks = new Dictionary<StackTypes, IPushStack> { … … 53 54 }; 54 55 56 supportedStackTypes = Stacks.Keys.ToArray(); 57 55 58 CustomExpressions = new Dictionary<string, Expression>(); 56 59 PoolContainer = poolContainer ?? new InterpreterPoolContainer(); … … 63 66 } 64 67 68 private readonly StackTypes[] supportedStackTypes; 65 69 public IReadOnlyDictionary<StackTypes, IPushStack> Stacks { get; private set; } 66 70 … … 128 132 public IPushStack<IReadOnlyList<string>> StringVectorStack { get; private set; } 129 133 [PushStack(StackTypes.Print)] 130 public IP ushStack<string>PrintStack { get; private set; }134 public IPrintStack PrintStack { get; private set; } 131 135 132 136 public IDictionary<string, Expression> CustomExpressions { get; private set; } 133 137 134 138 public bool IsNameQuoteFlagSet { get; set; } 139 140 private readonly List<Expression> inputExpressions = new List<Expression>(); 141 IReadOnlyList<Expression> IInternalPushInterpreter.InputExpressions { get { return inputExpressions; } } 142 143 public void SetInput( 144 IReadOnlyList<long> integers = null, 145 IReadOnlyList<double> floats = null, 146 IReadOnlyList<bool> booleans = null, 147 IReadOnlyList<char> chars = null, 148 IReadOnlyList<string> strings = null, 149 IReadOnlyList<IReadOnlyList<long>> integerVectors = null, 150 IReadOnlyList<IReadOnlyList<double>> floatVectors = null, 151 IReadOnlyList<IReadOnlyList<string>> stringVectors = null) { 152 153 // Integer 154 if (integers != null && integers.Count > 0) { 155 var integerPushExpressionPool = PoolContainer.GetStatefulExpressionPool<IntegerPushExpression>(); 156 157 for (var i = 0; i < integers.Count; i++) { 158 var expression = IntegerPushExpression.Create(integerPushExpressionPool, integers[i]); 159 inputExpressions.Add(expression); 160 } 161 } 162 163 // Float 164 if (floats != null && floats.Count > 0) { 165 var floatPushExpressionPool = PoolContainer.GetStatefulExpressionPool<FloatPushExpression>(); 166 167 for (var i = 0; i < floats.Count; i++) { 168 var expression = FloatPushExpression.Create(floatPushExpressionPool, floats[i]); 169 inputExpressions.Add(expression); 170 } 171 } 172 173 // Booleans 174 if (booleans != null && booleans.Count > 0) { 175 var booleanPushExpressionPool = PoolContainer.GetStatefulExpressionPool<BooleanPushExpression>(); 176 177 for (var i = 0; i < booleans.Count; i++) { 178 var expression = BooleanPushExpression.Create(booleanPushExpressionPool, booleans[i]); 179 inputExpressions.Add(expression); 180 } 181 } 182 183 // Char 184 if (chars != null && chars.Count > 0) { 185 var charPushExpressionPool = PoolContainer.GetStatefulExpressionPool<CharPushExpression>(); 186 187 for (var i = 0; i < chars.Count; i++) { 188 var expression = CharPushExpression.Create(charPushExpressionPool, chars[i]); 189 inputExpressions.Add(expression); 190 } 191 } 192 193 // String 194 if (strings != null && strings.Count > 0) { 195 var stringPushExpressionPool = PoolContainer.GetStatefulExpressionPool<StringPushExpression>(); 196 197 for (var i = 0; i < strings.Count; i++) { 198 var expression = StringPushExpression.Create(stringPushExpressionPool, strings[i]); 199 inputExpressions.Add(expression); 200 } 201 } 202 203 // IntegerVector 204 if (integerVectors != null && integerVectors.Count > 0) { 205 var integerVectorPushExpressionPool = PoolContainer.GetStatefulExpressionPool<IntegerVectorPushExpression>(); 206 207 for (var i = 0; i < integerVectors.Count; i++) { 208 var expression = IntegerVectorPushExpression.Create(integerVectorPushExpressionPool, integerVectors[i]); 209 inputExpressions.Add(expression); 210 } 211 } 212 213 // FloatVector 214 if (floatVectors != null && floatVectors.Count > 0) { 215 var floatVectorPushExpressionPool = PoolContainer.GetStatefulExpressionPool<FloatVectorPushExpression>(); 216 217 for (var i = 0; i < floatVectors.Count; i++) { 218 var expression = FloatVectorPushExpression.Create(floatVectorPushExpressionPool, floatVectors[i]); 219 inputExpressions.Add(expression); 220 } 221 } 222 223 // StringVector 224 if (stringVectors != null && stringVectors.Count > 0) { 225 var stringVectorPushExpressionPool = PoolContainer.GetStatefulExpressionPool<StringVectorPushExpression>(); 226 227 for (var i = 0; i < stringVectors.Count; i++) { 228 var expression = StringVectorPushExpression.Create(stringVectorPushExpressionPool, stringVectors[i]); 229 inputExpressions.Add(expression); 230 } 231 } 232 } 233 135 234 136 235 public Task RunAsync(string code, CancellationToken token = default(CancellationToken)) { … … 240 339 currentProgram = null; 241 340 341 inputExpressions.Clear(); 242 342 Clear(); 243 343 ConfigureStacks(); … … 245 345 246 346 private void ConfigureStacks() { 247 foreach (var pair in this.Stacks) { 248 pair.Value.IsEnabled = Configuration.IsStackEnabled(pair.Key); 347 for (var i = 0u; i < supportedStackTypes.Length; i++) { 348 var key = supportedStackTypes[i]; 349 Stacks[key].IsEnabled = Configuration.IsStackEnabled(key); 249 350 } 250 351 … … 257 358 /// </summary> 258 359 public void Clear() { 259 foreach (var stack in Stacks) 260 stack.Value.Clear(); 360 for (var i = 0u; i < supportedStackTypes.Length; i++) { 361 var key = supportedStackTypes[i]; 362 Stacks[key].Clear(); 363 } 261 364 262 365 CustomExpressions.Clear(); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreterPool.cs
r15032 r15189 47 47 PushProgramPoolProvider.Clear(); 48 48 ExpressionListPoolProvider.Clear(); 49 pool.Clear(); 49 50 } 50 51 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Parser/PushParser.cs
r15017 r15189 175 175 .Substring(1, word.Length - 2) 176 176 .Split(PushEnvironment.VectorSeparatorSymbol) 177 .To Array();178 179 if (vectorEntries. Length== 0) {177 .ToList(); 178 179 if (vectorEntries.Count == 0) { 180 180 expression = null; 181 181 return false; … … 190 190 191 191 if (e.GetType() == typeof(IntegerPushExpression)) { 192 var integerValues = vectorEntries.Select(long.Parse).To Array();192 var integerValues = vectorEntries.Select(long.Parse).ToList(); 193 193 expression = new IntegerVectorPushExpression(integerValues); 194 194 } else if (e.GetType() == typeof(FloatPushExpression)) { 195 var doubleValues = vectorEntries.Select(x => double.Parse(x, NumberStyles.Float, cultureInfo)).To Array();195 var doubleValues = vectorEntries.Select(x => double.Parse(x, NumberStyles.Float, cultureInfo)).ToList(); 196 196 expression = new FloatVectorPushExpression(doubleValues); 197 197 } else if (e.GetType() == typeof(StringPushExpression)) { 198 var stringValues = vectorEntries.Select(str => str.Substring(1, str.Length - 2)).To Array();198 var stringValues = vectorEntries.Select(str => str.Substring(1, str.Length - 2)).ToList(); 199 199 expression = new StringVectorPushExpression(stringValues); 200 200 } else if (e.GetType() == typeof(BooleanPushExpression)) { 201 var booleanValues = vectorEntries.Select(bool.Parse).To Array();201 var booleanValues = vectorEntries.Select(bool.Parse).ToList(); 202 202 expression = new BooleanVectorPushExpression(booleanValues); 203 203 } else { -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/BenchmarkSuite/BenchmarkSuitePushSolutionView.cs
r15032 r15189 53 53 var example = Evaluator.Data.Examples[exampleComboBox.SelectedIndex]; 54 54 55 interpreter.BooleanStack.Push(example.InputBoolean); 56 interpreter.IntegerStack.Push(example.InputInteger); 57 interpreter.FloatStack.Push(example.InputFloat); 58 interpreter.CharStack.Push(example.InputChar); 59 interpreter.StringStack.Push(example.InputString); 60 interpreter.IntegerVectorStack.Push(example.InputIntegerVector.Select(x => x.ToList()).ToArray()); 61 interpreter.FloatVectorStack.Push(example.InputFloatVector.Select(x => x.ToList()).ToArray()); 62 interpreter.StringVectorStack.Push(example.InputStringVector.Select(x => x.ToList()).ToArray()); 63 interpreter.BooleanVectorStack.Push(example.InputBooleanVector.Select(x => x.ToList()).ToArray()); 55 interpreter.SetInput( 56 integers: example.InputInteger, 57 floats: example.InputFloat, 58 booleans: example.InputBoolean, 59 chars: example.InputChar, 60 strings: example.InputString, 61 integerVectors: example.InputIntegerVector, 62 floatVectors: example.InputFloatVector, 63 stringVectors: example.InputStringVector); 64 65 //interpreter.BooleanStack.Push(example.InputBoolean); 66 //interpreter.IntegerStack.Push(example.InputInteger); 67 //interpreter.FloatStack.Push(example.InputFloat); 68 //interpreter.CharStack.Push(example.InputChar); 69 //interpreter.StringStack.Push(example.InputString); 70 //interpreter.IntegerVectorStack.Push(example.InputIntegerVector.Select(x => x.ToList()).ToList()); 71 //interpreter.FloatVectorStack.Push(example.InputFloatVector.Select(x => x.ToList()).ToList()); 72 //interpreter.StringVectorStack.Push(example.InputStringVector.Select(x => x.ToList()).ToList()); 73 //interpreter.BooleanVectorStack.Push(example.InputBooleanVector.Select(x => x.ToList()).ToList()); 64 74 } 65 75 … … 198 208 var type = data.OutputArgumentTypes[j]; 199 209 var offset = outputArgumentCountDict[type]; 210 211 // estimated 200 212 row.Cells[data.InputArgumentTypes.Length + j * 2].Value = ViewHelper.StringifyOutput(type, offset, Content.Config.FloatStringFormat, example, Separator); 213 214 // output 201 215 row.Cells[data.InputArgumentTypes.Length + j * 2 + 1].Value = StringifyResult(type, offset, pushInterpreter, example, Separator); 216 202 217 outputArgumentCountDict[type]++; 203 218 } … … 243 258 244 259 case ExampleArgumentType.Print: 245 return string.Join(valueSeparator, string.Join(PushEnvironment.NewLine, interpreter.PrintStack. Take(example.OutputPrintLineCount)));260 return string.Join(valueSeparator, string.Join(PushEnvironment.NewLine, interpreter.PrintStack.AsStrings().Take(example.OutputPrintLineCount))); 246 261 247 262 case ExampleArgumentType.String: -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/BenchmarkSuite/PushBenchmarkSuiteEvaluator.cs
r15017 r15189 2 2 using System; 3 3 using System.Collections.Generic; 4 using System.Globalization; 4 5 using System.Linq; 5 6 … … 130 131 var example = Data.Examples[exampleIndex]; 131 132 132 interpreter.BooleanStack.Push(example.InputBoolean); 133 interpreter.IntegerStack.Push(example.InputInteger); 134 interpreter.FloatStack.Push(example.InputFloat); 135 interpreter.CharStack.Push(example.InputChar); 136 interpreter.StringStack.Push(example.InputString); 137 interpreter.StringVectorStack.Push(example.InputStringVector); 138 interpreter.IntegerVectorStack.Push(example.InputIntegerVector); 139 interpreter.FloatVectorStack.Push(example.InputFloatVector); 133 //interpreter.BooleanStack.Push(example.InputBoolean); 134 //interpreter.IntegerStack.Push(example.InputInteger); 135 //interpreter.FloatStack.Push(example.InputFloat); 136 //interpreter.CharStack.Push(example.InputChar); 137 //interpreter.StringStack.Push(example.InputString); 138 //interpreter.StringVectorStack.Push(example.InputStringVector); 139 //interpreter.IntegerVectorStack.Push(example.InputIntegerVector); 140 //interpreter.FloatVectorStack.Push(example.InputFloatVector); 141 142 interpreter.SetInput( 143 integers: example.InputInteger, 144 floats: example.InputFloat, 145 booleans: example.InputBoolean, 146 chars: example.InputChar, 147 strings: example.InputString, 148 integerVectors: example.InputIntegerVector, 149 floatVectors: example.InputFloatVector, 150 stringVectors: example.InputStringVector); 140 151 141 152 interpreter.Run(program); 142 153 143 154 switch (Data.ProblemType) { 144 //case ProblemType.NumberIO: 145 // if (interpreter.PrintStack.IsEmpty) 146 // return Data.WorstResult; 147 148 // double value; 149 // var levenshteinDistance = GetPrintDiffer(example.OutputPrint, interpreter.PrintStack, example.OutputPrintLineCount, Data.WorstResult); 150 // return levenshteinDistance + (double.TryParse(interpreter.PrintStack.Top, out value) 151 // ? FloatDiffer(value, example.OutputFloat[0], example.OutputFloatPrecision) 152 // : Data.WorstResult / 2); 153 154 case ProblemType.Median: return interpreter.PrintStack.IsEmpty ? 1 : interpreter.PrintStack.Top.Equals(example.OutputPrint) ? 0 : 1; 155 } 156 155 case ProblemType.NumberIO: return NumberIo(interpreter, example); 156 case ProblemType.Median: return Median(interpreter, example); 157 } 158 159 return Default(interpreter, example); 160 } 161 162 private double Default(IPushInterpreter interpreter, Example example) { 157 163 var result = GetDiff(example.OutputInteger, interpreter.IntegerStack, Data.WorstResult, IntegerDiffer) 158 159 160 161 162 163 164 165 164 + GetDiff(example.OutputFloat, interpreter.FloatStack, Data.WorstResult, (a, b) => FloatDiffer(a, b, example.OutputFloatPrecision)) 165 + GetDiff(example.OutputBoolean, interpreter.BooleanStack, Data.WorstResult, BooleanDiffer) 166 + GetDiff(example.OutputString, interpreter.StringStack, Data.WorstResult, StringDiffer) 167 + GetDiff(example.OutputChar, interpreter.CharStack, Data.WorstResult, CharDiffer) 168 + GetPrintDiffer(example.OutputPrint, interpreter.PrintStack, example.OutputPrintLineCount, Data.WorstResult) 169 + GetVectorDiff(example.OutputIntegerVector, interpreter.IntegerVectorStack, Data.WorstResult, (a, b) => VectorDiffer(a, b, IntegerDiffer)) 170 + GetVectorDiff(example.OutputFloatVector, interpreter.FloatVectorStack, Data.WorstResult, (a, b) => VectorDiffer(a, b, (x, y) => FloatDiffer(x, y, example.OutputFloatVectorPrecision))) 171 + GetVectorDiff(example.OutputStringVector, interpreter.StringVectorStack, Data.WorstResult, (a, b) => VectorDiffer(a, b, StringDiffer)); 166 172 167 173 return result; 174 } 175 176 private double Median(IPushInterpreter interpreter, Example example) { 177 return interpreter.PrintStack.IsEmpty || !interpreter.PrintStack.Top.Equals(example.OutputPrint) ? 1 : 0; 178 } 179 180 private double NumberIo(IPushInterpreter interpreter, Example example) { 181 if (interpreter.PrintStack.IsEmpty) 182 return Data.WorstResult; 183 184 double value; 185 if (double.TryParse(interpreter.PrintStack.Top, NumberStyles.Number | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out value)) { 186 var diff = Math.Abs(example.OutputFloat[0] - value); 187 var result = Math.Min(diff, Data.WorstResult); 188 189 return result; 190 } 191 192 var penaltyError = Data.WorstResult / 4.0d; 193 var levenshteinDistance = GetPrintDiffer( 194 example.OutputPrint, 195 interpreter.PrintStack.Top, 196 Data.WorstResult); 197 198 return levenshteinDistance + penaltyError; 168 199 } 169 200 … … 217 248 } 218 249 250 private static double GetPrintDiffer(string estimated, string printResult, double worstResult) { 251 var distance = LevenshteinDistance(estimated, printResult); 252 253 return Math.Min(distance, worstResult); 254 } 255 219 256 private static double GetPrintDiffer(string estimated, IPushStack<string> printStack, int estimatedCount, double worstResult) { 220 var printResult = string.Join(PushEnvironment.NewLine, printStack. Take(estimatedCount));257 var printResult = string.Join(PushEnvironment.NewLine, printStack.AsStrings().Take(estimatedCount)); 221 258 var distance = LevenshteinDistance(estimated, printResult); 222 259 … … 234 271 var count = Math.Min(estimated.Count, resultStack.Count); 235 272 var result = resultStack.Peek(count); 236 comparableLength = Math.Min(estimated.Count, result. Length);273 comparableLength = Math.Min(estimated.Count, result.Count); 237 274 238 275 for (var i = 0; i < comparableLength; i++) { … … 259 296 var count = Math.Min(estimated.Count, resultStack.Count); 260 297 var result = resultStack.Peek(count); 261 comparableLength = Math.Min(estimated.Count, result. Length);298 comparableLength = Math.Min(estimated.Count, result.Count); 262 299 263 300 for (var i = 0; i < comparableLength; i++) { -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/BenchmarkSuite/PushBenchmarkSuiteProblem.cs
r15032 r15189 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Problem.BenchmarkSuite { 2 2 3 using Common; 3 4 using Configuration; … … 7 8 using HeuristicLab.BenchmarkSuite.Problems; 8 9 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 10 using HeuristicLab.Problems.ProgramSynthesis.Push.Extensions; 9 11 10 12 using Instances; … … 53 55 54 56 config.SetEnabledStacks((StackTypes)data.EnabledDataTypes); 57 data.InitInExpressions(config); 55 58 56 59 Encoding.Bounds[0, 0] = 0; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PushProblem.cs
r15032 r15189 12 12 using HeuristicLab.Problems.ProgramSynthesis.Push.Analyzer; 13 13 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 14 using HeuristicLab.Problems.ProgramSynthesis.Push.Individual; 14 15 using HeuristicLab.Problems.ProgramSynthesis.Push.Problem.BenchmarkSuite; 15 16 … … 125 126 // clear pools and free reserved memory 126 127 pool.Clear(); 128 IndividualMapper.Clear(); 127 129 } 128 130 … … 158 160 159 161 public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) { 162 IndividualMapper.Reset(); 163 160 164 var bestQuality = Maximization ? qualities.Max() : qualities.Min(); 161 165 var bestIdx = Array.IndexOf(qualities, bestQuality); … … 165 169 rand.Reset(seed); 166 170 167 var program = vector.ToPushProgram(config, rand);171 var program = (PushProgram)vector.ToPushProgram(config, rand).Clone(); 168 172 var isIndividualBetter = AnalyzeBestTrainingSolution(program, bestQuality, results, rand); 169 173 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Selector/LexicaseSelector.cs
r14908 r15189 74 74 for (var k = 0; k < repeats; k++) { 75 75 // The fitness cases are shuffled. 76 var fitnessCaseIndexes = Enumerable.Range(0, caseCount).Shuffle(random).To Array();76 var fitnessCaseIndexes = Enumerable.Range(0, caseCount).Shuffle(random).ToList(); 77 77 78 78 // copy list if required … … 83 83 var bestIndividuals = pool; 84 84 85 for (var j = 0; j < fitnessCaseIndexes. Length&& bestIndividuals.Count > 1; j++)85 for (var j = 0; j < fitnessCaseIndexes.Count && bestIndividuals.Count > 1; j++) 86 86 bestIndividuals = GetBestIndividuals(maximization, caseQualities, bestIndividuals, fitnessCaseIndexes[j]); 87 87 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/IPushStack.cs
r15017 r15189 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Stack { 2 using System;3 2 using System.Collections.Generic; 4 3 … … 18 17 void Push(IEnumerable<T> items); 19 18 new void Clear(); 20 T Peek(); 21 T[] Peek(int count); 22 void PushResult(int count, Func<T[], T> templateFunc); 19 IReadOnlyList<T> Peek(int count); 23 20 void Insert(int index, T item); 24 T ReverseElementAt(int offset);25 21 T Pop(); 26 T[]Pop(int count);22 IReadOnlyList<T> Pop(int count); 27 23 bool TryPop(out T item); 28 24 T ElementAt(int index); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/InterpreterStackStringifier.cs
r15017 r15189 45 45 46 46 private static IEnumerable<string> StringifyLiteralStack<T>(IPushStack<T> stack, string prefix = "", string postfix = "", bool reverse = true) { 47 var result = stack.As Enumerable();47 var result = stack.AsStrings(); 48 48 49 49 if (reverse) -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/PushStack.cs
r15017 r15189 122 122 } 123 123 124 public T ReverseElementAt(int offset) {125 return data[offset];126 }127 128 124 public T this[int index] 129 125 { … … 145 141 if (index == Count - 1) return; 146 142 147 var item = ReverseElementAt(index);143 var item = data[index]; 148 144 data.RemoveAt(index); 149 145 data.Add(item); … … 157 153 } 158 154 159 public T[]Pop(int count) {155 public IReadOnlyList<T> Pop(int count) { 160 156 var items = Peek(count); 161 157 Remove(count); … … 164 160 } 165 161 166 public T Peek() { 167 return Top; 168 } 169 170 public T[] Peek(int count) { 162 public IReadOnlyList<T> Peek(int count) { 171 163 var startIndex = Count - count; 172 164 … … 207 199 } 208 200 209 public void PushResult(int count, Func<T[], T> templateFunc) {210 if (!IsEnabled) return;211 212 var startIndex = Count - count;213 var items = new T[count];214 215 data.CopyTo(startIndex, items, 0, count);216 Remove(count - 1);217 218 data[Count - 1] = templateFunc(items);219 }220 221 201 public void Push(IReadOnlyList<T> items, int startIndex) { 222 202 if (!IsEnabled) return; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/StackTypes.cs
r15032 r15189 20 20 BooleanVector = 0x2000, 21 21 } 22 23 //public static class StackTypeExtensions { 24 // private static readonly IReadOnlyDictionary<StackTypes, string> StackTypesNameDict = new Dictionary<StackTypes, string> { 25 // { StackTypes.Integer, "Integer" }, 26 // { StackTypes.Float, "Float" }, 27 // { StackTypes.Char, "Char" }, 28 // { StackTypes.String, "String" }, 29 // { StackTypes.Boolean, "Boolean" }, 30 // { StackTypes.Name, "Name" }, 31 // { StackTypes.Code, "Code" }, 32 // { StackTypes.Exec, "Exec" }, 33 // { StackTypes.Print, "Print" }, 34 // { StackTypes.IntegerVector, "IntegerVector" }, 35 // { StackTypes.FloatVector, "FloatVector" }, 36 // { StackTypes.StringVector, "StringVector" }, 37 // { StackTypes.BooleanVector, "BooleanVector" }, 38 // }; 39 40 // public static string GetName(this StackTypes types) { 41 // return StackTypesNameDict[types]; 42 // } 43 //} 22 44 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Views/ExpressionSelectionView.cs
r15032 r15189 98 98 private IEnumerable<TreeNode> GetTreeNodes(IReadOnlyList<string> enabledExpressions) { 99 99 foreach (var stackType in ExpressionTable.StackTypeToNamesTable.Keys) { 100 if (stackType == StackTypes.None) 101 continue; 102 100 103 var stackTreeNode = new TreeNode { 101 104 Tag = stackType
Note: See TracChangeset
for help on using the changeset viewer.