Пример #1
0
        /// <summary>
        /// Starts optimization based on the array of items and simulation setting that were passed in during instantiation
        /// </summary>
        /// <returns>The final (predicted) output of the optimization</returns>
        public PlanogramOptResults StartOptimization()
        {
            UpdateStatus?.Invoke("Training...");

            var retVal = new PlanogramOptResults();

            // checks what type of simulation we are running
            int    sessions = simSettings.SimType == SimulationType.Sessions ? simSettings.Sessions.Value : DEFAULT_SESSIONS_PER_BATCH;
            double hours    = simSettings.SimType == SimulationType.Time ? simSettings.Hours.Value : 0;

            simSettings.StartedOn = DateTime.Now;
            simSettings.EndsOn    = DateTime.Now.AddHours(hours);

            // simulation scenarios:
            // if we are doing SimulationType.Sessions then the do-while loop will fail, just does the codeblock once, and trains the network with the specific number of sessions
            // if we are doing SimulationType.Time then as default it will train for 100 sessions at a time (per loop) and continues to do so until time runs out
            // if we are doing SimulationType.Score then it will execute just like the Time option except that it will continue to do so until the specified Score is met or surpassed
            do
            {
                // settings
                network.NumSessions = sessions;
                // you can change this and start experimenting which range is best
                // NOTE if you decide to have multiple facings (by changing the NumFacings output Max to greater than 1) and enforce item uniqueness then the EndRandomness must not be 0 (i suggest 5 as the minimum)
                // as the planogram needs a bit of randomness towards the end since we have a condition where we enforce uniqueness of items. In the event that the RLM outputs an item that
                // is already in the planogram then having enough randomness left will allow it to still have a chance to suggest a different item otherwise the RLM will suggest the same item over and over again and cause an infinite loop
                network.StartRandomness = START_RANDOMNESS;
                network.EndRandomness   = END_RANDOMNESS; //(simSettings.SimType == SimulationType.Sessions) ? 0 : network.StartRandomness;
                //network.MaxLinearBracket = MAX_LINEAR;
                //network.MinLinearBracket = MIN_LINEAR;

                // since we might be retraining the network (i.e, SimulationType.Time or Score), we need to call this method to reset the randomization counter of the RLM
                network.ResetRandomizationCounter();

                // training, train 90% per session batch if not Session Type
                var trainingTimes = (simSettings.SimType == SimulationType.Sessions) ? sessions : sessions - PREDICT_SESSIONS;
                retVal = Optimize(trainingTimes, true, simSettings.EnableSimDisplay);

                // for non Sessions type, we predict {PREDICT_SESSIONS}-times per session batch
                if (simSettings.SimType != SimulationType.Sessions)
                {
                    int predictTimes = PREDICT_SESSIONS;
                    if (simSettings.SimType == SimulationType.Score && predictTimes < RPOCSimpleSimSettings.NUM_SCORE_HITS)
                    {
                        predictTimes = RPOCSimpleSimSettings.NUM_SCORE_HITS;
                    }
                    retVal = Optimize(predictTimes, false, simSettings.EnableSimDisplay);
                }
            } while ((simSettings.SimType == SimulationType.Time && simSettings.EndsOn > DateTime.Now) ||
                     (simSettings.SimType == SimulationType.Score && RPOCSimpleSimSettings.NUM_SCORE_HITS > numScoreHits));

            // we do a final prediction and to ensure we update the plangoram display for the final output
            retVal = Optimize(1, false, true);

            network.TrainingDone();
            IsTrainingDone = true;

            UpdateStatus?.Invoke("Processing data...", true);

            return(retVal);
        }
Пример #2
0
        public void UpdateTensorflowResults(PlanogramOptResults results, bool enableSimDisplay = false)
        {
            if (tokenSource.IsCancellationRequested)
            {
                return;
            }
            if (enableSimDisplay)
            {
                Task.Delay(1);
            }

            Dispatcher.Invoke(() =>
            {
                string scoreText         = (simSettings.SimType == SimulationType.Score) ? $"{results.Score.ToString("#,##0.##")} ({results.NumScoreHits})" : results.Score.ToString("#,##0.##");
                scoreTxtTensor.Text      = scoreText;
                sessionRunTxtTensor.Text = results.CurrentSession.ToString();
                timElapseTxtTensor.Text  = results.TimeElapsed.ToString();//string.Format("{0:D2}:{1:D2}:{2:D2}.{3:D3}", results.TimeElapsed.Hours, results.TimeElapsed.Minutes, results.TimeElapsed.Seconds, results.TimeElapsed.Milliseconds);
                minScoreTxtTensor.Text   = results.MinScore.ToString("#,##0.##");
                maxScoreTxtTensor.Text   = results.MaxScore.ToString("#,##0.##");
                //engineTxtTensor.Text = "Tensorflow";
                averageScoreTxtTensor.Text     = results.AvgScore.ToString("#,##0.##");
                averageScoreOf10TxtTensor.Text = results.AvgLastTen.ToString("#,##0.##");

                if (enableSimDisplay)
                {
                    currentResultsTensor = results;
                    FillGrid(planogramTensorflow, results.Shelves, false, ItemAttrbutes_MouseEnter_Tensorflow, ItemAttrbutes_MouseLeave_Tensorflow, isRLM: false);
                }
            });
        }
        private void UpdateRLMResults(PlanogramOptResultsSettings results, bool enableSimDisplay)
        {
            enableSimDisplay = enableSimulation;
            Dispatcher.Invoke(() =>
            {
                if (enableSimDisplay)
                {
                    currentResults = results;
                    FillGrid(planogram, results.Shelves, false, ItemAttributes_MouseEnter, ItemAttributes_MouseLeave);
                }

                if (core.IsComparisonModeOn)
                {
                    DisplayLearningComparisonResults(tmpSelectedData, tmpComparisonData);
                }
                else
                {
                    string scoreText   = (simSettings.SimType == SimulationType.Score) ? $"{results.Score.ToString("#,###.##")} ({results.NumScoreHits})" : results.Score.ToString("#,###.##");
                    scoreTxt.Text      = scoreText;
                    sessionRunTxt.Text = results.CurrentSession.ToString();
                    timElapseTxt.Text  = results.TimeElapsed.ToString();//string.Format("{0:D2}:{1:D2}:{2:D2}.{3:D3}", results.TimeElapsed.Hours, results.TimeElapsed.Minutes, results.TimeElapsed.Seconds, results.TimeElapsed.Milliseconds);
                    minScoretxt.Text   = results.MinScore.ToString("#,###.##");
                    maxScoreTxt.Text   = results.MaxScore.ToString("#,###.##");
                    //engineTxt.Text = "RLM";
                    averageScoreTxt.Text      = results.AvgScore.ToString("#,###.##");
                    averageScoreOf10Txt.Text  = results.AvgLastTen.ToString("#,###.##");
                    currentRandomnessTxt.Text = results.CurrentRandomnessValue.ToString();
                    startRandomnessTxt.Text   = results.StartRandomness.ToString();
                    endRandomnessTxt.Text     = results.EndRandomness.ToString();
                    sessionPerBatchTxt.Text   = results.SessionsPerBatch.ToString();
                    inputTypeTxt.Text         = results.InputType;
                }
            });
        }
        public double CalculateScore(IMLMethod network)
        {
            SessionNumber++;

            DateTime startSession = DateTime.Now;

            PlanogramSimulation pilot = new PlanogramSimulation((BasicNetwork)network, Items, SimSettings);
            var result = LastResult = pilot.ScorePilot();

            result.CurrentSession = SessionNumber;
            metricScoreHistory.Add(result.Score);
            metricAvgLastTen.Enqueue(result.Score);
            if (metricAvgLastTen.Count > 10)
            {
                metricAvgLastTen.Dequeue();
            }
            result.MaxScore   = metricScoreHistory.Max();
            result.MinScore   = metricScoreHistory.Min();
            result.AvgScore   = metricScoreHistory.Average();
            result.AvgLastTen = metricAvgLastTen.Average();

            if (SimSettings.Score.HasValue)
            {
                if (result.Score >= SimSettings.Score.Value)
                {
                    NumScoreHits++;
                }
                else
                {
                    NumScoreHits = 0;
                }
            }

            result.NumScoreHits = NumScoreHits;

            if (Logger != null)
            {
                SimulationData logdata = new SimulationData();

                logdata.Session = result.CurrentSession;
                logdata.Score   = result.Score;
                logdata.Elapse  = DateTime.Now - startSession;

                Logger.Add(logdata, false);
            }

            UpdateUI?.Invoke(result, SimSettings.EnableSimDisplay);

            return(result.Score);
        }
        public PlanogramOptResults ScorePilot()
        {
            PlanogramOptResults retVal = new PlanogramOptResults();

            var    shelves                 = new List <Shelf>();
            double totalMetricScore        = 0;
            int    slotNumber              = 0;
            Dictionary <int, int> itemDict = new Dictionary <int, int>();
            bool hasExceedMax              = false;

            for (int i = 0; i < simSettings.NumShelves; i++)
            {
                Shelf shelfInstance = new Shelf();
                for (int p = 0; p < simSettings.NumSlots; p++)
                {
                    var inputs = new BasicMLData(1);
                    inputs[0] = slotNormalizer.Normalize(slotNumber);

                    IMLData output = network.Compute(inputs);
                    int     index  = Convert.ToInt32(itemNormalizer.DeNormalize(output[0]));

                    Item itemReference = items[index];

                    if (!hasExceedMax)
                    {
                        hasExceedMax = !(CheckDuplicateItem(itemDict, index));
                    }

                    // with the item reference we will also have the Attributes which we need to calculate for the metrics
                    double itemMetricScore = PlanogramOptimizer.GetCalculatedWeightedMetrics(itemReference, simSettings);

                    // we add the item's metric score to totalMetricScore(which is our Session score in this case)
                    // notice that we multplied it with the numFacings since that is how many will also show up on the planogram
                    totalMetricScore += itemMetricScore;

                    shelfInstance.Add(itemReference, itemMetricScore);

                    slotNumber++;
                }

                shelves.Add(shelfInstance);
            }

            retVal.Shelves     = shelves;
            retVal.Score       = (hasExceedMax) ? 0 : totalMetricScore;
            retVal.TimeElapsed = DateTime.Now - simSettings.StartedOn;

            return(retVal);
        }
Пример #6
0
        private void UpdateRLMResults(PlanogramOptResultsSettings results, bool enableSimDisplay)
        {
            if (enableSimDisplay)
            {
                Task.Delay(1).Wait();
            }

            Dispatcher.Invoke(() =>
            {
                currentResults = results;
                if (enableSimDisplay && !core.IsComparisonModeOn)
                {
                    FillGrid(gridIceCreamShelves, results.Shelves, false, ItemAttributes_MouseEnter, ItemAttributes_MouseLeave);
                }

                if (core.IsComparisonModeOn)
                {
                    DisplayLearningComparisonResults(tmpSelectedData, tmpComparisonData);
                }
                else
                {
                    string scoreText     = (simSettings.SimType == SimulationType.Score) ? $"{results.Score.ToString("c")} ({results.NumScoreHits})" : results.Score.ToString("c");
                    txtCurrentScore.Text = scoreText;

                    //sessionRunTxt.Text = results.CurrentSession.ToString();
                    txtTimeElapsed.Text = results.TimeElapsed.ToString();
                    //txtMinScore.Text = results.MinScore.ToString("#,###.##");
                    txtMaxScore.Text = results.MaxScore.ToString("c");
                    //txtAverageScore.Text = results.AvgScore.ToString("#,###.##");
                    //txtAverageOfTenScores.Text = results.AvgLastTen.ToString("#,###.##");
                    //txtCurrentRandomnes.Text = results.CurrentRandomnessValue.ToString();
                    //txtStartRandomnes.Text = results.StartRandomness.ToString();
                    //txtEndRandomnes.Text = results.EndRandomness.ToString();
                    //txtSessionPerBatch.Text = results.SessionsPerBatch.ToString();
                    //txtInputType.Text = results.InputType;
                }
            });
        }