- Timestamp:
- 05/31/10 15:51:50 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Manipulators/ChangeNodeTypeManipulation.cs
r3512 r3875 26 26 using HeuristicLab.Data; 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using System; 29 using System.Collections.Generic; 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 28 31 29 32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators { … … 65 68 return; 66 69 } 67 var newSymbol = constrainedSymbols.SelectRandom(random);70 var newSymbol = SelectRandomSymbol(random, constrainedSymbols); 68 71 69 72 // replace the old node with the new node … … 77 80 success = true; 78 81 } 82 83 private static Symbol SelectRandomSymbol(IRandom random, IEnumerable<Symbol> symbols) { 84 var symbolList = symbols.ToList(); 85 var ticketsSum = symbolList.Select(x => x.InitialFrequency).Sum(); 86 if (ticketsSum == 0.0) throw new ArgumentException("The initial frequency of all allowed symbols is zero."); 87 var r = random.NextDouble() * ticketsSum; 88 double aggregatedTickets = 0; 89 for (int i = 0; i < symbolList.Count; i++) { 90 aggregatedTickets += symbolList[i].InitialFrequency; 91 if (aggregatedTickets > r) { 92 return symbolList[i]; 93 } 94 } 95 // this should never happen 96 throw new ArgumentException("There is a problem with the initial frequency setting of allowed symbols."); 97 } 79 98 } 80 99 }
Note: See TracChangeset
for help on using the changeset viewer.