Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/18/15 18:24:58 (9 years ago)
Author:
gkronber
Message:

#2283 fixed compile errors and refactoring

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.Bandits/GrammarPolicies/GrammarPolicy.cs

    r11770 r11793  
    88
    99namespace HeuristicLab.Algorithms.Bandits.GrammarPolicies {
    10   // stores: tries, avg reward and max reward for each state
     10  // stores: tries, avg reward and max reward for each state (base class for RandomPolicy and TDPolicy
    1111  public abstract class GrammarPolicy : IGrammarPolicy {
    1212    protected Dictionary<string, double> avgReward;
    1313    protected Dictionary<string, int> tries;
    1414    protected Dictionary<string, double> maxReward;
    15     private readonly bool useCanonicalState;
    16     private readonly IProblem problem;
     15    protected readonly bool useCanonicalState;
     16    protected readonly IProblem problem;
    1717
    18     public GrammarPolicy(IProblem problem, bool useCanonicalState = false) {
     18    protected GrammarPolicy(IProblem problem, bool useCanonicalState = false) {
    1919      this.useCanonicalState = useCanonicalState;
    2020      this.problem = problem;
     
    2424    }
    2525
    26     public abstract bool TrySelect(Random random, ReadonlySequence curState, IEnumerable<ReadonlySequence> afterStates, out ReadonlySequence selectedState);
     26    public abstract bool TrySelect(Random random, string curState, IEnumerable<string> afterStates, out int selectedStateIdx);
    2727
    28     public virtual void UpdateReward(IEnumerable<ReadonlySequence> stateTrajectory, double reward) {
     28    public virtual void UpdateReward(IEnumerable<string> stateTrajectory, double reward) {
    2929      foreach (var state in stateTrajectory) {
    30         var s = CanonicalState(state.ToString());
     30        var s = CanonicalState(state);
    3131
    3232        if (!tries.ContainsKey(s)) tries.Add(s, 0);
     
    4747    }
    4848
    49     public double AvgReward(ReadonlySequence state) {
    50       var s = CanonicalState(state.ToString());
     49    public double AvgReward(string state) {
     50      var s = CanonicalState(state);
    5151      if (avgReward.ContainsKey(s)) return avgReward[s];
    5252      else return 0.0;
    5353    }
    5454
    55     public double MaxReward(ReadonlySequence state) {
    56       var s = CanonicalState(state.ToString());
     55    public double MaxReward(string state) {
     56      var s = CanonicalState(state);
    5757      if (maxReward.ContainsKey(s)) return maxReward[s];
    5858      else return 0.0;
    5959    }
    6060
    61     public virtual int GetTries(ReadonlySequence state) {
    62       var s = CanonicalState(state.ToString());
     61    public virtual int GetTries(string state) {
     62      var s = CanonicalState(state);
    6363      if (tries.ContainsKey(s)) return tries[s];
    6464      else return 0;
    6565    }
    6666
    67     public virtual double GetValue(ReadonlySequence state) {
     67    public virtual double GetValue(string state) {
    6868      return AvgReward(state);
    6969    }
Note: See TracChangeset for help on using the changeset viewer.