Changeset 15883 for branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/SearchDataStructure.cs
- Timestamp:
- 04/04/18 16:23:55 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/SearchDataStructure.cs
r15828 r15883 16 16 17 17 public enum StorageType { 18 Stack, Queue, RandomList18 PriorityQueue, Stack, Queue, RandomList 19 19 } 20 20 … … 22 22 23 23 private Dictionary<int, SymbolString> storedValues; // Store hash-references and associated, actual values 24 private Action<int > storeInternal; // Store hash-references24 private Action<int, double> storeInternal; // Store hash-references 25 25 private Func<int> fetchInternal; // Fetch hash-reference 26 26 … … 29 29 30 30 switch (storageType) { 31 case StorageType.PriorityQueue: 32 InitPriorityQueue(); 33 break; 31 34 case StorageType.Stack: 32 35 InitStack(); … … 44 47 #region SearchStrategies 45 48 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 46 59 private void InitStack() { 47 60 Stack<int> stack = new Stack<int>(); 48 61 49 storeInternal = hash=> stack.Push(hash);62 storeInternal = (hash, prio) => stack.Push(hash); 50 63 fetchInternal = () => stack.Pop(); 51 64 } … … 54 67 Queue<int> queue = new Queue<int>(); 55 68 56 storeInternal = hash=> queue.Enqueue(hash);69 storeInternal = (hash, prio) => queue.Enqueue(hash); 57 70 fetchInternal = () => queue.Dequeue(); 58 71 } … … 62 75 System.Random rand = new System.Random(999); 63 76 64 storeInternal = hash=> list.Add(hash);77 storeInternal = (hash, prio) => list.Add(hash); 65 78 fetchInternal = () => { 66 79 int indexOfHash = rand.Next(list.Count); 67 80 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. 69 82 return result; 70 83 }; … … 82 95 } 83 96 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); 86 99 storedValues[hash] = s; 87 100 }
Note: See TracChangeset
for help on using the changeset viewer.