Last change
on this file since 17189 was
15771,
checked in by bburlacu, 7 years ago
|
#2895: Add solution skeleton for PushGP with genealogy analysis.
|
File size:
921 bytes
|
Rev | Line | |
---|
[14834] | 1 | using System.Collections.Generic;
|
---|
| 2 |
|
---|
[15771] | 3 | namespace HeuristicLab.Problems.ProgramSynthesis { |
---|
[14834] | 4 | using HeuristicLab.Core;
|
---|
| 5 | using HeuristicLab.Random;
|
---|
| 6 |
|
---|
| 7 | public static class CollectionExtensions {
|
---|
| 8 | public static T Random<T>(this IReadOnlyList<T> source, IRandom random = null) {
|
---|
| 9 | random = random ?? new MersenneTwister();
|
---|
| 10 | var x = random.Next(source.Count);
|
---|
| 11 |
|
---|
| 12 | return source[x];
|
---|
| 13 | }
|
---|
[15017] | 14 |
|
---|
| 15 | public static int HashCode<T>(this IReadOnlyList<T> source) {
|
---|
| 16 | var hash = 19 * 31 + typeof(T).FullName.GetHashCode();
|
---|
| 17 |
|
---|
| 18 | for (var i = 0; i < source.Count; i++)
|
---|
| 19 | hash = hash * 31 + source[i].GetHashCode();
|
---|
| 20 |
|
---|
| 21 | return hash;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | public static int HashCode<T>(this IEnumerable<T> source) {
|
---|
| 25 | var hash = 19 * 31 + typeof(T).FullName.GetHashCode();
|
---|
| 26 |
|
---|
| 27 | foreach (var item in source)
|
---|
| 28 | hash = hash * 31 + item.GetHashCode();
|
---|
| 29 |
|
---|
| 30 | return hash;
|
---|
| 31 | }
|
---|
[14834] | 32 | }
|
---|
| 33 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.