Changeset 14744 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Views/PushProgramDebuggerView.cs
- Timestamp:
- 03/10/17 21:42:09 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Views/PushProgramDebuggerView.cs
r14727 r14744 8 8 using System.Linq; 9 9 10 using HeuristicLab.BenchmarkSuite .Problems;10 using HeuristicLab.BenchmarkSuite; 11 11 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 12 12 using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter; 13 13 using HeuristicLab.Problems.ProgramSynthesis.Push.Problem; 14 using HeuristicLab.Random; 14 15 15 16 [View("Push Program Debugger")] 16 17 [Content(typeof(PushSolution), true)] 17 18 public partial class PushProgramDebuggerView : NamedItemView { 19 private const string Separator = ", "; 20 private PushProgram program; 21 22 private ListViewItem[] execListCache; //array to cache items for the virtual list 23 private int firstExecListItemIndex; //stores the index of the first item in the cache 24 18 25 private const string exampleSplitter = " => "; 19 private Push GpInterpreter interpreter;26 private PushInterpreter interpreter; 20 27 21 28 public PushProgramDebuggerView() { … … 28 35 resetButton.Click += ResetButtonClick; 29 36 stepButton.Click += StepButtonClick; 30 } 31 32 protected override void OnReadOnlyChanged() { 33 base.OnReadOnlyChanged(); 34 37 38 execList.RetrieveVirtualItem += ExecListRetrieveVirtualItem; 39 execList.CacheVirtualItems += ExecListCacheVirtualItems; 40 41 execList.View = View.Details; 42 execList.HeaderStyle = ColumnHeaderStyle.Nonclickable; 43 execList.AutoResizeColumns(ColumnHeaderAutoResizeStyle.None); 44 execList.Columns.Add(new ColumnHeader { Width = execList.Width - 40 }); 45 execList.VirtualMode = true; 46 execList.VirtualListSize = 100; 47 } 48 49 private void ExecListCacheVirtualItems(object sender, CacheVirtualItemsEventArgs e) { 50 //We've gotten a request to refresh the cache. 51 //First check if it's really neccesary. 52 if (execListCache != null && 53 e.StartIndex >= firstExecListItemIndex && 54 e.EndIndex <= firstExecListItemIndex + execListCache.Length) { 55 //If the newly requested cache is a subset of the old cache, 56 //no need to rebuild everything, so do nothing. 57 return; 58 } 59 60 //Now we need to rebuild the cache. 61 UpdateListCache(e.StartIndex, e.EndIndex); 62 } 63 64 private void ExecListRetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e) { 65 //check to see if the requested item is currently in the cache 66 if (execListCache == null || 67 e.ItemIndex < firstExecListItemIndex || 68 e.ItemIndex >= firstExecListItemIndex + execListCache.Length) { 69 UpdateListCache(e.ItemIndex, execList.VirtualListSize); 70 } 71 72 e.Item = e.ItemIndex >= firstExecListItemIndex && e.ItemIndex < firstExecListItemIndex + execListCache.Length 73 ? execListCache[e.ItemIndex - firstExecListItemIndex] 74 : e.Item = new ListViewItem(); 75 } 76 77 private void UpdateListCache(int startIndex, int endIndex) { 78 if (interpreter == null) { 79 execListCache = new ListViewItem[0]; 80 return; 81 } 82 83 this.firstExecListItemIndex = startIndex; 84 var length = Math.Min(endIndex - startIndex + 1, interpreter.ExecStack.Count); //indexes are inclusive 85 this.execListCache = new ListViewItem[length]; 86 87 var expressions = this.interpreter.ExecStack.Peek(length); 88 89 //Fill the cache with the appropriate ListViewItems. 90 for (var i = 0; i < length; i++) 91 this.execListCache[i] = new ListViewItem(expressions[length - 1 - i].ToString()); 92 93 execList.AutoResizeColumns(ColumnHeaderAutoResizeStyle.None); 94 execList.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); 95 } 96 97 //protected override void OnEnabledChanged(EventArgs e) { 98 // SetReadonlyFields(); 99 //} 100 101 //protected override void OnReadOnlyChanged() { 102 // base.OnReadOnlyChanged(); 103 104 // SetReadonlyFields(); 105 //} 106 107 //protected override void SetEnabledStateOfControls() 108 //{ 109 // SetReadonlyFields(); 110 //} 111 112 private void SetReadonlyFields() { 35 113 exampleComboBox.Enabled = !ReadOnly; 36 114 execList.Enabled = !ReadOnly; … … 40 118 floatList.Enabled = !ReadOnly; 41 119 booleanList.Enabled = !ReadOnly; 120 stepButton.Enabled = !ReadOnly; 121 runButton.Enabled = !ReadOnly; 122 resetButton.Enabled = !ReadOnly; 123 skipNoopsCheckBox.Enabled = !ReadOnly; 124 stepWidthBox.Enabled = !ReadOnly; 42 125 } 43 126 … … 54 137 55 138 private void SyncExecList() { 56 execList.Items.RemoveAt(0); 57 58 if (!interpreter.ExecStack.SequenceEqual(execList.Items.Cast<Expression>().Reverse())) { 59 UpdateExecList(); 60 } 61 62 this.execGroupBox.Text = string.Format("Exec [{0}]", this.execList.Items.Count); 139 UpdateExecList(); 140 141 this.execGroupBox.Text = string.Format("Exec [{0}]", this.interpreter.ExecStack.Count); 63 142 } 64 143 … … 70 149 71 150 for (var i = 0; i < count; i++) { 72 interpreter.Step(); 151 if (skipNoopsCheckBox.Checked) { 152 bool noop; 153 154 do { 155 noop = !interpreter.Step(); 156 } 157 while (interpreter.CanStep && noop); 158 } else interpreter.Step(); 73 159 } 74 160 … … 114 200 interpreter.Clear(); 115 201 116 var example = Content.Data .Examples[this.exampleComboBox.SelectedIndex];202 var example = Content.DataDescriptor.Examples[this.exampleComboBox.SelectedIndex]; 117 203 118 204 interpreter.BooleanStack.Push(example.InputBoolean); … … 120 206 interpreter.FloatStack.Push(example.InputFloat); 121 207 122 interpreter.Run( Content.Program, true);208 interpreter.Run(program, true); 123 209 stepWidthBox.Maximum = interpreter.ExecStack.Count; 124 210 … … 131 217 if (Content == null) return; 132 218 133 interpreter = Content.Pool.GetInstance(Content.Random); 134 135 UpdateExamples(Content.Data); 219 var random = Content.Random ?? new FastRandom(); 220 interpreter = new PushInterpreter(Content.Config, random); 221 program = Content.IntegerVector.MapToPushProgram(Content.Config.EnabledExpressions); 222 223 UpdateExamples(Content.DataDescriptor); 136 224 137 225 if (this.exampleComboBox.SelectedIndex < 0) { … … 151 239 152 240 private void UpdateExecList() { 153 execList.Items.Clear(); 154 155 foreach (var item in interpreter.ExecStack.Reverse()) 156 this.execList.Items.Add(item); 241 UpdateListCache(0, execList.VirtualListSize); 242 execList.Update(); 157 243 158 244 this.execGroupBox.Text = string.Format("Exec [{0}]", this.execList.Items.Count); … … 226 312 } 227 313 228 private void UpdateExamples(Data data) { 229 const string seperator = ", "; 314 private void UpdateExamples(IBenchmarkSuiteDataDescriptor data) { 315 if (data == null) return; 316 230 317 var stringRepresentations = data.Examples.Select(e => 231 string.Join( seperator, e.InputArgs) +318 string.Join(Separator, e.InputArgs) + 232 319 exampleSplitter + 233 string.Join( seperator, e.OutputArgs));320 string.Join(Separator, e.OutputArgs)); 234 321 235 322 exampleComboBox.Items.Clear();
Note: See TracChangeset
for help on using the changeset viewer.