Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Algorithms.IteratedSentenceConstruction/HeuristicLab.Algorithms.IteratedSymbolicExpressionConstruction/3.3/Policies/RandomSymbolicExpressionConstructionPolicy.cs @ 12955

Last change on this file since 12955 was 12955, checked in by gkronber, 7 years ago

#2471: implemented deterministic BFS and DFS for iterated symbolic expression construction

File size: 1.7 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using HeuristicLab.Common;
5using HeuristicLab.Core;
6using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
7using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
8using HeuristicLab.Random;
9
10namespace 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}
Note: See TracBrowser for help on using the repository browser.