private void runSlmBtn_Click(object sender, RoutedEventArgs e) { selectedSlotIndex = -1; _row = -1; _col = -1; itemRow = -1; itemCol = -1; SimulationPanel simPanel = new SimulationPanel(); simPanel.SetSimSettings(simSettings); bool?result = simPanel.ShowDialog(); if (result.HasValue && result.Value == true) { // resets grid to default usePerfColor = false; FillGrid(planogram, Colors.LightGray); if (headToHead) { FillGrid(planogramTensorflow, Colors.LightGray); } // disable control buttons //statusTxt.Text = statusTxtTensor.Text = ""; statusTxtTensor.Text = "Waiting for RLM to finish running..."; EnableControlButtons(false); // set simulation settings simSettings.SimType = simPanel.SimType; simSettings.Sessions = simPanel.Sessions; simSettings.Hours = simPanel.Hours; simSettings.Score = simPanel.Score; simSettings.EnableSimDisplay = simPanel.EnableSimDisplay; simSettings.DefaultScorePercentage = simPanel.simScoreSlider.Value; simSettings.HiddenLayers = simPanel.HiddenLayers; simSettings.HiddenLayerNeurons = simPanel.HiddenLayerNeurons; targetScoreTxt.Text = ""; if (simSettings.SimType == SimulationType.Score) { targetScoreLbl.Visibility = Visibility.Visible; targetScoreTxt.Visibility = Visibility.Visible; targetScoreTxt.Text = simSettings.Score.Value.ToString("n"); targetScoreTxt2.Visibility = Visibility.Visible; targetScoreTxt2.Text = simSettings.Score.Value.ToString("n"); } else { targetScoreLbl.Visibility = Visibility.Hidden; targetScoreTxt.Visibility = Visibility.Hidden; targetScoreTxt2.Visibility = Visibility.Hidden; } if (simSettings.SimType == SimulationType.Sessions) { sessionPerBatchLbl.Visibility = Visibility.Hidden; sessionPerBatchTxt.Visibility = Visibility.Hidden; } else { sessionPerBatchLbl.Visibility = Visibility.Visible; sessionPerBatchTxt.Visibility = Visibility.Visible; } Logger.Clear(); string dbIdentifier = "RLM_planogram_" + Guid.NewGuid().ToString("N"); // instantiate visualizer with this window as its parent reference visualizer = new RLVOutputVisualizer(this); core = new RLVCore(dbIdentifier); // subscribe mainwindow to the comparison event //visualizer.LearningComparisonDisplayResultsEvent += DisplayLearningComparisonResults; // open temporary RLV container panel // todo this must be embeded in this Window instead of the temporary container if (rlvPanel != null) { rlvPanel.Close(); } rlvPanel = new TempRLVContainerPanel(core, visualizer); //this.Top = 20; //tmpPanel.Top = this.Top; //this.Height = tmpPanel.Height; //tmpPanel.Left = 10; //this.Left = tmpPanel.Width + tmpPanel.Left; //tmpPanel.Visibility = Visibility.Hidden; Task.Run(() => { // get items from db as well as the min and max metric scores as we need that for the calculation later on Item[] items; using (PlanogramContext ctx = new PlanogramContext()) { MockData mock = new MockData(ctx); items = itemsCache = mock.GetItemsWithAttr(); simSettings.ItemMetricMin = mock.GetItemMinimumScore(simSettings); simSettings.ItemMetricMax = mock.GetItemMaximumScore(simSettings); } // let's tensorflow (or other listeners) know that it should start training //OnSimulationStart?.Invoke(items, simSettings); //return; // initialize and start RLM training optimizer = new PlanogramOptimizer(items, simSettings, this.UpdateRLMResults, this.UpdateRLMStatus, Logger, dbIdentifier); //optimizer.OnSessionDone += Optimizer_OnSessionDone; optimizer.StartOptimization(tokenSource.Token); }); } }
private void OnSelectedItem(object sender, System.Windows.Input.MouseButtonEventArgs e) { var point = Mouse.GetPosition(planogram); int row = 0; int col = 0; double accumulatedHeight = 0.0; double accumulatedWidth = 0.0; foreach (var rowDefinition in planogram.RowDefinitions) { accumulatedHeight += rowDefinition.ActualHeight; if (accumulatedHeight >= point.Y) { break; } row++; } foreach (var columnDefinition in planogram.ColumnDefinitions) { accumulatedWidth += columnDefinition.ActualWidth; if (accumulatedWidth >= point.X) { break; } col++; } RemoveHighlightedItems(); // row and col now correspond Grid's RowDefinition and ColumnDefinition mouse was // over when double clicked! var rect = planogram.Children .Cast <Rectangle>() .Where(i => Grid.GetRow(i) == row && Grid.GetColumn(i) == col) .FirstOrDefault(); if (rect == null) { row = itemRow; col = itemCol; rect = planogram.Children .Cast <Rectangle>() .Where(i => Grid.GetRow(i) == row && Grid.GetColumn(i) == col) .FirstOrDefault(); } HighlightItem(rect); _row = row; _col = col; selectedSlotIndex = planogram.Children.IndexOf(rect); //MessageBox.Show($"row: {row}, col: {col}, index: {rectIndex}"); var inputValues = new[] { new RLVIOValues() { IOName = "Slot", Value = (selectedSlotIndex + 1).ToString() } }; // TODO remove this. for debugging purposes, we need hardcoded items since the planogram does not have items at startup //int[] preloadedItems = new int[] {61 // ,25 // ,71 // ,64 // ,32 // ,54 // ,67 // ,29 // ,89 // ,31 // ,20 // ,39 // ,76 // ,60 // ,55 // ,52 // ,16 // ,84 // ,76 // ,35 // ,74 // ,62 // ,37 // ,47}; int itemIndex = 0;// preloadedItems[selectedSlotIndex]; if (rect.Tag is ShelfItem) { itemIndex = ((ShelfItem)rect.Tag).Index - 1; } else if (rect.Tag is KeyValuePair <ShelfItem, ShelfItem> ) { itemIndex = ((KeyValuePair <ShelfItem, ShelfItem>)rect.Tag).Key.Index - 1; } var outputValues = new[] { new RLVIOValues() { IOName = "Item", Value = itemIndex.ToString() } }; var itemDisplay = new[] { new RLVItemDisplay() { Name = "Item", Value = "Item #" + (selectedSlotIndex + 1), Visibility = RLVVisibility.Visible } // todo pass in actual item name (see: Value) }; visualizer?.SelectNewItem(inputValues, outputValues, itemDisplay); if (!NoData) { if (noData != null) { noData.Close(); } if (tmpPanel != null) { tmpPanel.Visibility = Visibility.Visible; } else { if (tmpPanel != null) { tmpPanel.Close(); } tmpPanel = new TempRLVContainerPanel(core, visualizer); tmpPanel.Show(); } previousSelectedSlotIndex = selectedSlotIndex; previousSelectedRect = rect; alignPanels(); } else { if (noData != null) { noData.Close(); } noData = new NoDataNotificationWindow(); noData.Show(); noData.Top = this.Top; noData.Left = this.Left + this.Width; selectedSlotIndex = previousSelectedSlotIndex; // Highlight the previous item with data if (rect != null) { rect.StrokeThickness = 1; rect.Stroke = new SolidColorBrush(Colors.Black); } if (previousSelectedRect != null) { HighlightItem(previousSelectedRect); } } //HighlightItem(row, col); //MessageBox.Show($"row: {row}, col: {col}"); }