1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using HeuristicLab.Common;
|
---|
5 | using HeuristicLab.Core;
|
---|
6 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
7 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
8 | using HeuristicLab.Random;
|
---|
9 |
|
---|
10 | namespace HeuristicLab.Algorithms.IteratedSymbolicExpressionConstruction {
|
---|
11 | [StorableClass]
|
---|
12 | [Item("RandomSymbolicExpressionConstructionPolicy", "")]
|
---|
13 | public class RandomSymbolicExpressionConstructionPolicy : SymbolicExpressionConstructionPolicyBase {
|
---|
14 |
|
---|
15 | public RandomSymbolicExpressionConstructionPolicy()
|
---|
16 | : base() {
|
---|
17 | }
|
---|
18 |
|
---|
19 | protected override int Select(IReadOnlyList<object> followStates, IRandom random) {
|
---|
20 | var idxs = Enumerable.Range(0, followStates.Count);
|
---|
21 | return idxs.SampleRandom(random);
|
---|
22 | }
|
---|
23 |
|
---|
24 | public sealed override void Update(IEnumerable<object> stateSequence, double quality) {
|
---|
25 | // ignore
|
---|
26 | }
|
---|
27 |
|
---|
28 | protected override object CreateState(ISymbolicExpressionTreeNode root, List<ISymbol> actionSequence, ISymbolicExpressionTreeNode parent, int childIdx) {
|
---|
29 | return null; // doesn't use state information
|
---|
30 | }
|
---|
31 |
|
---|
32 | #region IItem
|
---|
33 | protected RandomSymbolicExpressionConstructionPolicy(RandomSymbolicExpressionConstructionPolicy original, Cloner cloner)
|
---|
34 | : base(original, cloner) {
|
---|
35 | }
|
---|
36 |
|
---|
37 | [StorableConstructor]
|
---|
38 | protected RandomSymbolicExpressionConstructionPolicy(bool deserializing) : base(deserializing) { }
|
---|
39 |
|
---|
40 | public override HeuristicLab.Common.IDeepCloneable Clone(HeuristicLab.Common.Cloner cloner) {
|
---|
41 | return new RandomSymbolicExpressionConstructionPolicy(this, cloner);
|
---|
42 | }
|
---|
43 |
|
---|
44 | #endregion
|
---|
45 | }
|
---|
46 | }
|
---|