Ignore:
Timestamp:
04/04/18 16:23:55 (3 years ago)
Author:
lkammere
Message:

#2886: Priorize phrases whose (fully expanded) terms result in high R².

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/SearchDataStructure.cs

    r15828 r15883  
    1616
    1717  public enum StorageType {
    18     Stack, Queue, RandomList
     18    PriorityQueue, Stack, Queue, RandomList
    1919  }
    2020
     
    2222
    2323    private Dictionary<int, SymbolString> storedValues; // Store hash-references and associated, actual values
    24     private Action<int> storeInternal; // Store hash-references
     24    private Action<int, double> storeInternal; // Store hash-references
    2525    private Func<int> fetchInternal; // Fetch hash-reference
    2626
     
    2929
    3030      switch (storageType) {
     31        case StorageType.PriorityQueue:
     32          InitPriorityQueue();
     33          break;
    3134        case StorageType.Stack:
    3235          InitStack();
     
    4447    #region SearchStrategies
    4548
     49    private void InitPriorityQueue() {
     50      PriorityQueue<double, int> queue = new PriorityQueue<double, int>(double.MaxValue, double.MinValue, (int)Math.Pow(2.0, 20.0) / 4);
     51      storeInternal = (hash, prio) => queue.Insert(prio, hash);
     52      fetchInternal = () => {
     53        int ret = queue.PeekMinValue();
     54        queue.RemoveMin();
     55        return ret;
     56      };
     57    }
     58
    4659    private void InitStack() {
    4760      Stack<int> stack = new Stack<int>();
    4861
    49       storeInternal = hash => stack.Push(hash);
     62      storeInternal = (hash, prio) => stack.Push(hash);
    5063      fetchInternal = () => stack.Pop();
    5164    }
     
    5467      Queue<int> queue = new Queue<int>();
    5568
    56       storeInternal = hash => queue.Enqueue(hash);
     69      storeInternal = (hash, prio) => queue.Enqueue(hash);
    5770      fetchInternal = () => queue.Dequeue();
    5871    }
     
    6275      System.Random rand = new System.Random(999);
    6376
    64       storeInternal = hash => list.Add(hash);
     77      storeInternal = (hash, prio) => list.Add(hash);
    6578      fetchInternal = () => {
    6679        int indexOfHash = rand.Next(list.Count);
    6780        int result = list[indexOfHash];
    68         list.RemoveAt(indexOfHash);  // TODO: beware this is O(n), at some point in time we should fix this
     81        list.RemoveAt(indexOfHash);  // TODO: beware this is O(n), at some point in time we should fix this. Maybe change to priority queue with random key.
    6982        return result;
    7083      };
     
    8295    }
    8396
    84     public void Store(int hash, SymbolString s) {
    85       storeInternal(hash);
     97    public void Store(int hash, double priority, SymbolString s) {
     98      storeInternal(hash, priority);
    8699      storedValues[hash] = s;
    87100    }
Note: See TracChangeset for help on using the changeset viewer.