Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/16/15 18:26:35 (10 years ago)
Author:
gkronber
Message:

#2283 work-in-progress commit (does not compile)

File:
1 edited

Legend:

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

    r11770 r11792  
    2727      out ReadonlySequence selectedState) {
    2828      // only select states that are not yet done
    29       afterStates = afterStates.Where(a => !done.Contains(CanonicalState(a.ToString()))).ToArray();
     29      afterStates = afterStates.Where(a => !done.Contains(CanonicalState(a))).ToArray();
    3030      if (!afterStates.Any()) {
    3131        // fail because all follow states have already been visited => also disable the current state (if we can be sure that it has been fully explored)
    32         throw new NotImplementedException();
    33         //var curStateCanonical = CanonicalState(curState.ToString());
    34         //if (curState.ToString().Length == curStateCanonical.Length)
    35           done.Add(CanonicalState(curState.ToString()));
     32
     33        done.Add(CanonicalState(curState));
    3634        selectedState = null;
    3735        return false;
     
    4543
    4644    private IBanditPolicyActionInfo GetStateInfo(ReadonlySequence state) {
    47       var s = CanonicalState(state.ToString());
     45      var s = CanonicalState(state);
    4846      IBanditPolicyActionInfo info;
    4947      if (!stateInfo.TryGetValue(s, out info)) {
     
    5755      // the last state could be terminal
    5856      var lastState = stateTrajectory.Last();
    59       if (lastState.IsTerminal) done.Add(CanonicalState(lastState.ToString()));
     57      if (lastState.IsTerminal) done.Add(CanonicalState(lastState));
    6058
    6159      foreach (var state in stateTrajectory) {
     
    7068
    7169    public int GetTries(ReadonlySequence state) {
    72       var s = CanonicalState(state.ToString());
     70      var s = CanonicalState(state);
    7371      if (stateInfo.ContainsKey(s)) return stateInfo[s].Tries;
    7472      else return 0;
     
    7674
    7775    public double GetValue(ReadonlySequence state) {
    78       var s = CanonicalState(state.ToString());
     76      var s = CanonicalState(state);
    7977      if (stateInfo.ContainsKey(s)) return stateInfo[s].Value;
    8078      else return 0.0; // TODO: check alternatives
    8179    }
    8280
    83     protected string CanonicalState(string state) {
    84       if (useCanonicalState) return problem.CanonicalRepresentation(state);
    85       else return state;
     81    protected string CanonicalState(ReadonlySequence state) {
     82      if (useCanonicalState) {
     83        if (state.IsTerminal)
     84          return problem.CanonicalRepresentation(state.ToString());
     85        else {
     86          // for non-terminal phrases make sure we don't disable canonical states that have not yet been fully explored
     87          // e.g. if for the ant problem we have the phrase lllS (and we are limited to 4 symbols) and lllr as well as llll are explored
     88          // then we are not allowed to disable rS (canonical of lllS) because rS might not have been fully explored
     89          // solution: we disable the state rS4
     90          return problem.CanonicalRepresentation(state.ToString()) + state.Length;
     91        }
     92      } else
     93        return state.ToString();
    8694    }
    8795  }
Note: See TracChangeset for help on using the changeset viewer.