public Route[] FindPath(Field field, Vector2Int start, Vector2Int[] goals)
    {
        // ゴールの数だけジョブを回す
        JobHandle[] job_handles = new JobHandle[goals.Length];
        NativeArray <Vector2Int>[] result_paths = new NativeArray <Vector2Int> [goals.Length];
        NativeArray <int>[]        result_walks = new NativeArray <int> [goals.Length];

        // フィールドのコストをNativeArrayに
        NativeArray <int> field_cost = new NativeArray <int>(field.size.x * field.size.y, Allocator.Temp);

        for (int i = 0; i < field.size.x * field.size.y; i++)
        {
            field_cost[i] = field.GetCell(Utility.ToPosition(i, field.size.x));
        }

        for (int i = 0; i < goals.Length; i++)
        {
            result_paths[i] = new NativeArray <Vector2Int>(JobRouter.MAX_WALKS, Allocator.Temp);
            result_walks[i] = new NativeArray <int>(1, Allocator.Temp);

            // ジョブを作成
            var job_router = new JobRouter()
            {                   // コンストラクタで各種情報を設定
                costs       = field_cost,
                fieldSize   = field.size,
                goal        = goals[i],
                start       = start,
                resultPath  = result_paths[i],
                resultWalks = result_walks[i],
            };

            // ジョブをスケジュール
            job_handles[i] = job_router.Schedule();
        }
        // ジョブを開始
        JobHandle.ScheduleBatchedJobs();
        // 順番に経路探索ジョブを待って、結果を作成
        Route[] results = new Route[goals.Length];
        for (int i = 0; i < goals.Length; i++)
        {
            // ジョブ待ち
            job_handles[i].Complete();

            // 結果をルートに変換
            var route = new Route();
            route.path = new Vector2Int[result_walks[i][0]];
            for (int j = 0; j < route.path.Length; j++)
            {
                route.path[j] = result_paths[i][j];
            }
            results[i] = route;

            result_paths[i].Dispose();
            result_walks[i].Dispose();
        }

        field_cost.Dispose();

        return(results);
    }
Beispiel #2
0
        private void button4_Click(object sender, EventArgs e)
        {
            String serviceUrl = "http://www.datacount.com.br/Datacount/JobRoutingService.aspx";
            int    tenantId   = 10;

            JobRouter jobRouter = new JobRouter(serviceUrl, tenantId, this);

            // Envia os logs de cópia
            //notifications.Clear();
            String baseDir    = @"C:\temp\Datacount";
            String copyLogDir = Path.Combine(baseDir, "CopyLogs");

            if (!jobRouter.SendCopyJobs(copyLogDir))
            {
                // São gravados logs detalhados para que se possa determinar a causa da falha
                //ProcessNotifications();
                return;
            }
        }
Beispiel #3
0
        public IScheduler CreateScheduler()
        {
            Func <DateTime> now = () => DateTime.Now;

            var eventStream                = new EventStream(_eventSinks, _exceptionLogger, now);
            var recoverableAction          = new RecoverableAction(this, eventStream);
            var delegatingPersistenceStore = new DelegatingPersistenceStore(_persistenceProvider);
            var jobMutation                = new JobMutator(eventStream, delegatingPersistenceStore);

            var queueConfiguration = new JobQueueFactory(
                delegatingPersistenceStore, this, eventStream, recoverableAction, jobMutation).Create();

            var router       = new JobRouter(queueConfiguration);
            var methodBinder = new MethodBinder();

            var continuationDispatcher = new ContinuationDispatcher(router, jobMutation,
                                                                    delegatingPersistenceStore, recoverableAction);
            var activityToContinuationConverter = new ActivityToContinuationConverter(now);

            var runningTransition = new RunningTransition(jobMutation);
            var failedTransition  = new FailedTransition(this, jobMutation, now);
            var endTransition     = new EndTransition(delegatingPersistenceStore, jobMutation,
                                                      continuationDispatcher);

            var continuationLiveness = new ContinuationLiveness(delegatingPersistenceStore, continuationDispatcher);

            var coordinator = new JobCoordinator(eventStream, recoverableAction);

            var waitingForChildrenTransition = new WaitingForChildrenTransition(
                delegatingPersistenceStore,
                continuationDispatcher,
                activityToContinuationConverter,
                recoverableAction,
                jobMutation);

            var changeState = new StatusChanger(eventStream, runningTransition, failedTransition,
                                                endTransition, waitingForChildrenTransition, jobMutation);

            var failedJobQueue = new FailedJobQueue(this, delegatingPersistenceStore, now, eventStream, router);

            var errorHandlingPolicy = new ErrorHandlingPolicy(this, coordinator, changeState,
                                                              failedJobQueue, recoverableAction);

            var exceptionFilterDispatcher = new ExceptionFilterDispatcher(eventStream);

            var jobDispatcher = new Dispatcher.Dispatcher(_dependencyResolver,
                                                          coordinator,
                                                          errorHandlingPolicy,
                                                          methodBinder,
                                                          eventStream,
                                                          recoverableAction,
                                                          changeState,
                                                          continuationLiveness,
                                                          exceptionFilterDispatcher);

            var jobPumps =
                queueConfiguration
                .ActivitySpecificQueues
                .Values
                .Select(q => new JobPump(jobDispatcher, eventStream, q))
                .ToList();

            jobPumps.Add(new JobPump(jobDispatcher, eventStream, queueConfiguration.Default));

            return(new Scheduler(
                       queueConfiguration,
                       this,
                       delegatingPersistenceStore,
                       now,
                       failedJobQueue,
                       recoverableAction,
                       router,
                       activityToContinuationConverter,
                       jobPumps,
                       jobMutation));
        }