Esempio n. 1
0
 /// <summary>
 /// 探索し、結果を返却します。
 /// </summary>
 /// <param name="context">フィールド状態</param>
 /// <returns>移動方向</returns>
 public Direction Search(FieldContext context)
 {
     StopWatchLogger.StartEventWatch("NegaMaxTemplate.SearchBestValue");
     this.Value = this.SearchBestValue(context.DeepCopy(), 1, DefaultAlpha, DefaultBeta);
     FileHelper.WriteLine("BestScore:" + this.Value);
     StopWatchLogger.StopEventWatch("NegaMaxTemplate.SearchBestValue");
     StopWatchLogger.WriteAllEventTimes("./log/eventtime.txt");
     return(this.key);
 }
Esempio n. 2
0
        /// <summary>
        /// 評価値を取得する
        /// </summary>
        /// <returns></returns>
        protected override double GetEvaluate(FieldContext context)
        {
            StopWatchLogger.StartEventWatch("SearchBestPointer-GetEvaluate");
            var score = this.Evaluator.Evaluate(context);

            StopWatchLogger.StopEventWatch("SearchBestPointer-GetEvaluate");
            FileHelper.WriteLine($"score:{score} direction:{context.OperationDirection}");

            return(score * this.GetParity(context));
        }
Esempio n. 3
0
        public async Task <IActionResult> UpdateAsync(FileIndexItem inputModel, string f, bool append,
                                                      bool collections = true, int rotateClock = 0)
        {
            var stopwatch = StopWatchLogger.StartUpdateReplaceStopWatch();

            var inputFilePaths = PathHelper.SplitInputFilePaths(f);

            var(fileIndexResultsList, changedFileIndexItemName) = await _metaPreflight.Preflight(inputModel,
                                                                                                 inputFilePaths, append, collections, rotateClock);

            var operationId = HttpContext.GetOperationId();

            // Update >
            _bgTaskQueue.QueueBackgroundWorkItem(async _ =>
            {
                var operationHolder = RequestTelemetryHelper.GetOperationHolder(_scopeFactory,
                                                                                nameof(UpdateAsync), operationId);

                var metaUpdateService = _scopeFactory.CreateScope()
                                        .ServiceProvider.GetRequiredService <IMetaUpdateService>();

                var data = await metaUpdateService.UpdateAsync(
                    changedFileIndexItemName, fileIndexResultsList, null,
                    collections, append, rotateClock);
                operationHolder.SetData(_scopeFactory, data);
            });

            // before sending not founds
            new StopWatchLogger(_logger).StopUpdateReplaceStopWatch("update", f, collections, stopwatch);

            // When all items are not found
            if (fileIndexResultsList.All(p => p.Status != FileIndexItem.ExifStatus.Ok &&
                                         p.Status != FileIndexItem.ExifStatus.Deleted))
            {
                return(NotFound(fileIndexResultsList));
            }

            // Clone an new item in the list to display
            var returnNewResultList = fileIndexResultsList.Select(item => item.Clone()).ToList();

            // when switching very fast between images the background task has not run yet
            _metaUpdateService.UpdateReadMetaCache(returnNewResultList);

            // Push direct to socket when update or replace to avoid undo after a second
            _logger.LogInformation($"[UpdateController] send to socket {f}");

            await Task.Run(async() => await TaskRun(fileIndexResultsList));

            return(Json(returnNewResultList));
        }
Esempio n. 4
0
        public async Task <IActionResult> Replace(string f, string fieldName, string search,
                                                  string replace, bool collections = true)
        {
            var stopwatch = StopWatchLogger.StartUpdateReplaceStopWatch();

            var fileIndexResultsList = await _metaReplaceService
                                       .Replace(f, fieldName, search, replace, collections);

            var resultsOkOrDeleteList = fileIndexResultsList.Where(
                p => p.Status == FileIndexItem.ExifStatus.Ok ||
                p.Status == FileIndexItem.ExifStatus.Deleted).ToList();

            var changedFileIndexItemName = resultsOkOrDeleteList.
                                           ToDictionary(item => item.FilePath, item => new List <string> {
                fieldName
            });

            // Update >
            _bgTaskQueue.QueueBackgroundWorkItem(async _ =>
            {
                var metaUpdateService = _scopeFactory.CreateScope()
                                        .ServiceProvider.GetRequiredService <IMetaUpdateService>();
                await metaUpdateService
                .UpdateAsync(changedFileIndexItemName, resultsOkOrDeleteList,
                             null, collections, false, 0);
            });

            // before sending not founds
            new StopWatchLogger(_logger).StopUpdateReplaceStopWatch("update", f, collections, stopwatch);

            // When all items are not found
            if (!resultsOkOrDeleteList.Any())
            {
                return(NotFound(fileIndexResultsList));
            }

            // Push direct to socket when update or replace to avoid undo after a second
            var webSocketResponse =
                new ApiNotificationResponseModel <List <FileIndexItem> >(resultsOkOrDeleteList, ApiNotificationType.Replace);
            await _connectionsService.NotificationToAllAsync(webSocketResponse, CancellationToken.None);

            return(Json(fileIndexResultsList));
        }
Esempio n. 5
0
        /// <summary>
        /// <para>最善手を探索して取得する</para>
        /// </summary>
        /// <returns></returns>
        protected double SearchBestValue(FieldContext context, int depth, double alpha, double beta)
        {
            // 深さ制限に達した
            if (this.IsLimit(depth))
            {
                return(this.GetEvaluate(context));
            }

            // 可能な手をすべて生成
            var leafList = this.GetAllLeaf(context);

            double maxKeyValue = DefaultAlpha;

            if (leafList.Count() > 0)
            {
                // ソート
                StopWatchLogger.StartEventWatch("MoveOrdering");
                if (this.IsOrdering(depth))
                {
                    leafList = this.MoveOrdering(leafList, context);
                }
                StopWatchLogger.StopEventWatch("MoveOrdering");

                var lastContext = context.DeepCopy();
                foreach (Direction leaf in leafList)
                {
                    // 前処理
                    StopWatchLogger.StartEventWatch("SearchSetUp");
                    this.SearchSetUp(context, leaf);
                    StopWatchLogger.StopEventWatch("SearchSetUp");

                    double value = this.SearchBestValue(context, depth + 1, -beta, -alpha) * -1;

                    // 後処理
                    StopWatchLogger.StartEventWatch("SearchTearDown");
                    //context = this.SearchTearDown(lastContext);
                    context = lastContext.DeepCopy();
                    StopWatchLogger.StopEventWatch("SearchTearDown");

                    // ベータ刈り
                    if (value >= beta)
                    {
                        this.SetKey(leaf, depth);
                        return(value);
                    }

                    if (value > maxKeyValue)
                    {
                        // より良い手が見つかった
                        this.SetKey(leaf, depth);
                        maxKeyValue = value;
                        // α値の更新
                        alpha = Math.Max(alpha, maxKeyValue);
                    }
                }
            }
            else
            {
                // ▼パスの場合▼
                // 前処理
                var lastContext = context.DeepCopy();
                this.PassSetUp(context);

                maxKeyValue = this.SearchBestValue(context, depth + 1, -beta, -alpha) * -1;

                // 後処理
                //context = this.PassTearDown(lastContext);
                context = lastContext.DeepCopy();
            }

            Debug.Assert(((maxKeyValue != DefaultAlpha) && (maxKeyValue != DefaultBeta)), "デフォルト値のまま返そうとしています。");
            return(maxKeyValue);
        }