コード例 #1
0
 private void TryToCleanBreak(BreakSchedule tvBreak)
 {
     for (int pos = tvBreak.Count - 1; pos >= 0; --pos)
     {
         if (DeleteOnlyOverfull && tvBreak.UnitFill <= tvBreak.BreakData.SpanUnits)
         {
             break;
         }
         Delete delete = new Delete()
         {
             Solution = Solution,
             TvBreak  = tvBreak.BreakData,
             Position = pos,
         };
         delete.Asses();
         if (delete.OverallDifference.HasScoreImproved() && !delete.OverallDifference.AnyCompatibilityIssuesIncreased())
         {
             delete.Execute();
             Reporter.AddEntry(delete.GenerateReportEntry());
             _numberOfMoves += 1;
             _movePerformed  = true;
         }
         if (CurrentTime.Elapsed >= TimeLimit)
         {
             break;
         }
     }
 }
コード例 #2
0
        private bool InsertInRandomNonFilledBreak(TaskScore taskData)
        {
            List <BreakSchedule> breaksWithEnoughSpace = Solution.AdvertisementsScheduledOnBreaks.Values.Where
                                                         (
                b => b.BreakData.SpanUnits >= b.UnitFill + taskData.AdConstraints.AdSpanUnits
                                                         ).ToList();

            if (breaksWithEnoughSpace.Count == 0)
            {
                return(false);
            }
            int           breakNum = Random.Next(breaksWithEnoughSpace.Count);
            BreakSchedule schedule = breaksWithEnoughSpace[breakNum];
            int           position = Random.Next(schedule.Count + 1);
            Insert        insert   = new Insert()
            {
                TvBreak            = schedule.BreakData,
                AdvertisementOrder = taskData.AdConstraints,
                Position           = position,
                Instance           = Instance,
                Solution           = Solution,
            };

            insert.Asses();
            insert.Execute();
            Reporter.AddEntry(insert.GenerateReportEntry());
            return(true);
        }
コード例 #3
0
 private void ChooseMoveToPerform(List<int> positions, TaskScore taskScore, BreakSchedule breakSchedule)
 {
     foreach(var position in positions)
     {
         Insert move = new Insert()
         {
             Solution = Solution,
             Position = position,
             TvBreak = breakSchedule.BreakData,
             AdvertisementOrder = taskScore.AdConstraints,
         };
         move.Asses();
         if(move.OverallDifference.HasScoreImproved() && !move.OverallDifference.AnyCompatibilityIssuesIncreased())
         {
             move.Execute();
             Reporter.AddEntry(move.GenerateReportEntry());
             _numberOfMoves += 1;
             _movePerformed = true;
         }
         else
         {
             break;
         }
         if (CurrentTime.Elapsed >= TimeLimit) break;
     }
 }
コード例 #4
0
 private void GenerateReportEntry()
 {
     Reporter.AddEntry(new ReportEntry()
     {
         Time               = DateTime.Now,
         Action             = "Added break",
         AttainedAcceptable = Solution.IntegrityLossScore <= 0,
         WeightedLoss       = Solution.WeightedLoss,
         IntegrityLoss      = Solution.IntegrityLossScore,
     });
 }
コード例 #5
0
        private void ChooseMoveToPerform(List <ITransformation> moves)
        {
            foreach (var move in moves)
            {
                move.Asses();
            }
            var candidate = moves.OrderBy(m => m.OverallDifference.IntegrityLossScore).FirstOrDefault();

            if (candidate.OverallDifference.IntegrityLossScore < 0)
            {
                candidate.Execute();
                Reporter.AddEntry(candidate.GenerateReportEntry());
                _movePerformed = true;
            }
        }
コード例 #6
0
        protected override async Task RunInternal()
        {
            await Container.CreateIfNotExistsAsync();

            byte[] buffer = new byte[BlobSizeBytes];
            new Random().NextBytes(buffer);

            SemaphoreSlim sem   = new SemaphoreSlim(5, 5);
            List <Task>   tasks = new List <Task>();

            for (ulong i = 0; i < NBlobsToUpload; ++i)
            {
                string         blobName = BlobPrefix + i;
                CloudBlockBlob blob     = Container.GetBlockBlobReference(blobName);
                Reporter.AddEntry(await UploadBlobAsync(buffer, blob));
            }
        }
コード例 #7
0
        private void PerformIfTransformationImprovesScore(TaskScore taskScore, BreakSchedule breakSchedule)
        {
            Insert move = new Insert()
            {
                Solution           = Solution,
                Position           = breakSchedule.Count,
                TvBreak            = breakSchedule.BreakData,
                AdvertisementOrder = taskScore.AdConstraints,
            };

            move.Asses();
            if (move.OverallDifference.HasScoreImproved() && !move.OverallDifference.AnyCompatibilityIssuesIncreased())
            {
                move.Execute();
                Reporter.AddEntry(move.GenerateReportEntry());
                _numberOfMoves += 1;
                _movePerformed  = true;
            }
        }
コード例 #8
0
        private void InsertInRandomBreak(TaskScore taskData)
        {
            int           breakNum = Random.Next(Instance.Breaks.Count);
            TvBreak       tvBreak  = Instance.Breaks.Values.ToList()[breakNum];
            BreakSchedule schedule = Solution.AdvertisementsScheduledOnBreaks[tvBreak.ID];
            int           position = Random.Next(schedule.Count + 1);
            Insert        insert   = new Insert()
            {
                TvBreak            = schedule.BreakData,
                AdvertisementOrder = taskData.AdConstraints,
                Position           = position,
                Instance           = Instance,
                Solution           = Solution,
            };

            insert.Asses();
            insert.Execute();
            Reporter.AddEntry(insert.GenerateReportEntry());
        }
コード例 #9
0
        protected override async Task RunInternal()
        {
            // Initialize a buffer large enough to contain the contents of a single blob.
            byte[] buffer = new byte[NBytesPerBlob];

            // Choose the name of the first blob to retrieve.
            string nextBlobName = GetRandomBlobName();

            for (uint i = 1; i <= NBlobsToDownload; ++i)
            {
                MemoryStream readStream = new MemoryStream(buffer);

                var cbb = Container.GetBlockBlobReference(nextBlobName);

                Reporter.AddEntry(await DownloadBlobAsync(readStream, cbb));

                nextBlobName = GetRandomBlobName();
            }
        }
コード例 #10
0
 private void ChooseToPerform()
 {
     if (_bestMove == null || !_bestMove.OverallDifference.HasScoreImproved())
     {
         WidenNeighberhood();
         _numberOfLoopsWithoutImprovement += 1;
     }
     else
     {
         _numberOfLoopsWithoutImprovement = 0;
         RewardBestFactory();
         NarrowNeighberhood();
         NumberOfMoves += 1;
     }
     if (_bestMove == null || _bestMove.OverallDifference.HasScoreWorsened())
     {
         if (Solution.IsBetterThan(_previousBest))
         {
             _previousBest = Solution.TakeSnapshot();
         }
         if (ActionWhenScoreWorsens == Action.Stop)
         {
             _timeToStop = true;
             return;
         }
         else if (ActionWhenScoreWorsens == Action.Ignore)
         {
             return;
         }
         ;
     }
     if (_bestMove == null)
     {
         return;
     }
     _bestMove.Execute();
     Reporter.AddEntry(_bestMove.GenerateReportEntry());
 }
コード例 #11
0
        protected override async Task RunInternal()
        {
            if (NBlocksToUpload == 0)
            {
                Console.WriteLine("Nothing to do.  NBlocksToUpload = 0.");
                return;
            }

            await Container.CreateIfNotExistsAsync();

            byte[] buffer = new byte[BlockSizeBytes];
            new Random().NextBytes(buffer);

            SemaphoreSlim sem   = new SemaphoreSlim(5, 5);
            List <Task>   tasks = new List <Task>();

            // Only use 100 blocks per blob.
            const ulong MAX_BLOCK_COUNT = 100;

            ulong nBlobsToUpload = NBlocksToUpload / MAX_BLOCK_COUNT + 1;

            for (ulong blobIndex = 0; blobIndex < nBlobsToUpload; ++blobIndex)
            {
                string         blobName = BlobPrefix + blobIndex;
                CloudBlockBlob blob     = Container.GetBlockBlobReference(blobName);

                ulong nBlocksToUpload = MAX_BLOCK_COUNT;
                if (blobIndex + 1 == nBlobsToUpload)
                {
                    nBlocksToUpload = NBlocksToUpload % MAX_BLOCK_COUNT;
                }
                for (ulong blockIndex = 0; blockIndex < nBlocksToUpload; ++blockIndex)
                {
                    string blockIdStr = Convert.ToBase64String(BitConverter.GetBytes(blockIndex));
                    Reporter.AddEntry(await UploadBlockAsync(buffer, blob, blockIdStr));
                }
            }
        }
コード例 #12
0
        protected override async Task RunInternal()
        {
            BlobContinuationToken continuationToken = null;
            Stopwatch             stopwatch         = new Stopwatch();

            do
            {
                stopwatch.Start();
                BlobResultSegment resultSegment = await Container.ListBlobsSegmentedAsync(BlobPrefix, continuationToken);

                stopwatch.Stop();

                // Count the number of items from the results.
                ulong nResults = 0;
                foreach (IListBlobItem item in resultSegment.Results)
                {
                    ++nResults;
                }

                continuationToken = resultSegment.ContinuationToken;
                Reporter.AddEntry(new ListBlobTestDataEntry(stopwatch.Elapsed, nResults));
                stopwatch.Reset();
            } while (continuationToken != null);
        }