private void Window_Loaded(object sender, RoutedEventArgs e) { string dbIdentifier = "RLV_small"; // instantiate visualizer with this window as its parent reference visualizer = new RLVOutputVisualizer(this); core = new RLVCore(dbIdentifier); this.Top = 20; rlvPanel = new VisualizerWindow(core, visualizer); }
private void startOptimizing() { trainingOverlay.Visibility = Visibility.Visible; selectedSlotIndex = -1; _row = -1; _col = -1; itemRow = -1; itemCol = 1; SimulationPanel simPanel = new SimulationPanel(mock); simPanel.SetSimSettings(simSettings); //bool? result = simPanel.ShowDialog(); simPanel.btnRun_Click(null, null); //if (result.HasValue && result.Value == true) { // resets grid to default FillGrid(gridIceCreamShelves, Colors.LightGray); 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; txtTargetScore.Text = ""; if (simSettings.SimType == SimulationType.Score) { txtTargetScore.Text = simSettings.Score.Value.ToString("n"); } else { txtTargetScore.Visibility = Visibility.Hidden; } //if (simSettings.SimType == SimulationType.Sessions) //{ // lblSessionPerBatch.Visibility = Visibility.Hidden; // txtSessionPerBatch.Visibility = Visibility.Hidden; //} //else //{ // lblSessionPerBatch.Visibility = Visibility.Visible; // txtSessionPerBatch.Visibility = Visibility.Visible; //} string dbIdentifier = "RLM_planogram_" + Guid.NewGuid().ToString("N"); // instantiate visualizer with this window as its parent reference visualizer = new RLVOutputVisualizer(this); rlmDbData = new RlmDbDataSQLServer(dbIdentifier); //rlmDbData = new RlmDbDataPostgreSqlServer(dbIdentifier); core = new RLVCore(rlmDbData); // 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 VisualizerWindow(core, visualizer); 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); } // initialize and start RLM training optimizer = new PlanogramOptimizer(items, simSettings, this.UpdateRLMResults, this.UpdateRLMStatus, Logger, dbIdentifier, OnRLMDataPersistProgress); //optimizer.OnSessionDone += Optimizer_OnSessionDone; optimizer.StartOptimization(); }); } }
private void OnSelectedItem(object sender, System.Windows.Input.MouseButtonEventArgs e) { var point = Mouse.GetPosition(gridIceCreamShelves); int row = 0; int col = 0; double accumulatedHeight = 0.0; double accumulatedWidth = 0.0; foreach (var rowDefinition in gridIceCreamShelves.RowDefinitions) { accumulatedHeight += rowDefinition.ActualHeight; if (accumulatedHeight >= point.Y) { break; } row++; } foreach (var columnDefinition in gridIceCreamShelves.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 = gridIceCreamShelves.Children .Cast <Rectangle>() .Where(i => Grid.GetRow(i) == row && Grid.GetColumn(i) == col) .FirstOrDefault(); if (rect == null) { row = itemRow; col = itemCol; rect = gridIceCreamShelves.Children .Cast <Rectangle>() .Where(i => Grid.GetRow(i) == row && Grid.GetColumn(i) == col) .FirstOrDefault(); } HighlightItem(rect); _row = row; _col = col; selectedSlotIndex = gridIceCreamShelves.Children.IndexOf(rect); //MessageBox.Show($"row: {row}, col: {col}, index: {rectIndex}"); var inputValues = new[] { new RLVIOValues() { IOName = "Slot", Value = (selectedSlotIndex + 1).ToString() } }; int itemIndex = 0; 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 (rlvPanel != null) { rlvPanel.Visibility = Visibility.Visible; } else { if (rlvPanel != null) { rlvPanel.Close(); } rlvPanel = new VisualizerWindow(core, visualizer); rlvPanel.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}"); }