Last change
on this file since 18183 was
15771,
checked in by bburlacu, 7 years ago
|
#2895: Add solution skeleton for PushGP with genealogy analysis.
|
File size:
1.6 KB
|
Rev | Line | |
---|
[15771] | 1 | namespace HeuristicLab.Problems.ProgramSynthesis { |
---|
[14897] | 2 | using HeuristicLab.Common;
|
---|
| 3 | using HeuristicLab.Core;
|
---|
| 4 | using HeuristicLab.Data;
|
---|
| 5 | using HeuristicLab.Parameters;
|
---|
| 6 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 7 |
|
---|
| 8 | [StorableClass]
|
---|
[14952] | 9 | public abstract class ConstantsWeightedErc<T, TArray> : WeightedErcItem<T>
|
---|
[14897] | 10 | where T : struct
|
---|
| 11 | where TArray : ValueTypeArray<T>, new() {
|
---|
| 12 |
|
---|
| 13 | private const string ConstantsParameterName = "Constants";
|
---|
| 14 |
|
---|
[14952] | 15 | protected ConstantsWeightedErc(TArray array) : this(true, array) { }
|
---|
| 16 | protected ConstantsWeightedErc(bool isEnabled, TArray array, double weight = 1d) : base(isEnabled, weight) {
|
---|
[14897] | 17 | Parameters.Add(new FixedValueParameter<TArray>(ConstantsParameterName, array));
|
---|
[14952] | 18 | array.ToStringChanged += (sender, args) => UpdateName();
|
---|
| 19 | UpdateName();
|
---|
[14897] | 20 | }
|
---|
| 21 |
|
---|
[14952] | 22 | private void UpdateName() {
|
---|
| 23 | Name = Constants.ToString();
|
---|
| 24 | }
|
---|
| 25 |
|
---|
[14897] | 26 | [StorableConstructor]
|
---|
[14952] | 27 | protected ConstantsWeightedErc(bool deserializing) : base(deserializing) { }
|
---|
[14897] | 28 |
|
---|
[14952] | 29 | protected ConstantsWeightedErc(ConstantsWeightedErc<T, TArray> origin, Cloner cloner) : base(origin, cloner) { }
|
---|
[14897] | 30 |
|
---|
| 31 | public IValueParameter<TArray> ConstantsParameter
|
---|
| 32 | {
|
---|
| 33 | get { return (IValueParameter<TArray>)Parameters[ConstantsParameterName]; }
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | public TArray Constants
|
---|
| 37 | {
|
---|
| 38 | get { return ConstantsParameter.Value; }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | public override T GetErcValue(IRandom random) {
|
---|
[14905] | 42 | if (Constants.Length == 0) return default(T);
|
---|
| 43 |
|
---|
| 44 | var x = random.Next(Constants.Length);
|
---|
| 45 | return Constants[x];
|
---|
[14897] | 46 | }
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.