Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/10/17 21:42:09 (7 years ago)
Author:
pkimmesw
Message:

#2665 Renamings due to typos, ManagedPool tests, Skip Noops in Debugger

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Views/PushProgramDebuggerView.cs

    r14727 r14744  
    88  using System.Linq;
    99
    10   using HeuristicLab.BenchmarkSuite.Problems;
     10  using HeuristicLab.BenchmarkSuite;
    1111  using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
    1212  using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
    1313  using HeuristicLab.Problems.ProgramSynthesis.Push.Problem;
     14  using HeuristicLab.Random;
    1415
    1516  [View("Push Program Debugger")]
    1617  [Content(typeof(PushSolution), true)]
    1718  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
    1825    private const string exampleSplitter = " => ";
    19     private PushGpInterpreter interpreter;
     26    private PushInterpreter interpreter;
    2027
    2128    public PushProgramDebuggerView() {
     
    2835      resetButton.Click += ResetButtonClick;
    2936      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() {
    35113      exampleComboBox.Enabled = !ReadOnly;
    36114      execList.Enabled = !ReadOnly;
     
    40118      floatList.Enabled = !ReadOnly;
    41119      booleanList.Enabled = !ReadOnly;
     120      stepButton.Enabled = !ReadOnly;
     121      runButton.Enabled = !ReadOnly;
     122      resetButton.Enabled = !ReadOnly;
     123      skipNoopsCheckBox.Enabled = !ReadOnly;
     124      stepWidthBox.Enabled = !ReadOnly;
    42125    }
    43126
     
    54137
    55138    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);
    63142    }
    64143
     
    70149
    71150      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();
    73159      }
    74160
     
    114200      interpreter.Clear();
    115201
    116       var example = Content.Data.Examples[this.exampleComboBox.SelectedIndex];
     202      var example = Content.DataDescriptor.Examples[this.exampleComboBox.SelectedIndex];
    117203
    118204      interpreter.BooleanStack.Push(example.InputBoolean);
     
    120206      interpreter.FloatStack.Push(example.InputFloat);
    121207
    122       interpreter.Run(Content.Program, true);
     208      interpreter.Run(program, true);
    123209      stepWidthBox.Maximum = interpreter.ExecStack.Count;
    124210
     
    131217      if (Content == null) return;
    132218
    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);
    136224
    137225      if (this.exampleComboBox.SelectedIndex < 0) {
     
    151239
    152240    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();
    157243
    158244      this.execGroupBox.Text = string.Format("Exec [{0}]", this.execList.Items.Count);
     
    226312    }
    227313
    228     private void UpdateExamples(Data data) {
    229       const string seperator = ", ";
     314    private void UpdateExamples(IBenchmarkSuiteDataDescriptor data) {
     315      if (data == null) return;
     316
    230317      var stringRepresentations = data.Examples.Select(e =>
    231         string.Join(seperator, e.InputArgs) +
     318        string.Join(Separator, e.InputArgs) +
    232319        exampleSplitter +
    233         string.Join(seperator, e.OutputArgs));
     320        string.Join(Separator, e.OutputArgs));
    234321
    235322      exampleComboBox.Items.Clear();
Note: See TracChangeset for help on using the changeset viewer.