public (bool, int[]) Determine(int[] input)
        {
            MEAPSharedContext MEAPSharedContext = new();

            MEAPSharedContext.MNP   = tMachine;
            MEAPSharedContext.Input = input;

            MEAPSharedContext.InitInstance = new TMInstance(
                MEAPSharedContext.MNP,
                MEAPSharedContext.Input);

            MEAPSharedContext.MNP.PrepareTapeFwd(
                MEAPSharedContext.Input,
                MEAPSharedContext.InitInstance);

            MEAPSharedContext.CancellationTokenSource = new CancellationTokenSource();
            MEAPSharedContext.CancellationToken       = MEAPSharedContext.CancellationTokenSource.Token;

            ITPLOptions tplOptions = configuration.Get <ITPLOptions>();
            uint        determinePathRunnersCount = tplOptions.DeterminePathRunnersCount;

            IDebugOptions debugOptions = configuration.Get <IDebugOptions>();
            ulong         currentMu    = debugOptions.muStart;

            ITASGBuilder tasgBuilder = configuration.Get <ITASGBuilder>();

            MEAPSharedContext.TASGBuilder = tasgBuilder;
            tasgBuilder.MEAPSharedContext = MEAPSharedContext;

            tasgBuilder.Init();

            while (true)
            {
                List <DeterminePathRunner> determinePathRunners = new();
                ulong baseMu = currentMu;

                for (long i = 0; i < determinePathRunnersCount; i++)
                {
                    DeterminePathRunnerCtorArgs determinePathRunnerCtorArgs = new()
                    {
                        tMachine          = tMachine,
                        input             = input,
                        currentMu         = currentMu++,
                        MEAPSharedContext = MEAPSharedContext
                    };

                    DeterminePathRunner determinePathRunner = configuration.Get <DeterminePathRunner>(
                        new Ninject.Parameters.ConstructorArgument(
                            nameof(determinePathRunnerCtorArgs),
                            determinePathRunnerCtorArgs));

                    determinePathRunners.Add(determinePathRunner);
                }

                TPLCollectionRunner <DeterminePathRunner> determinePathRunnerSet = new
                                                                                   (
                    determinePathRunners,
                    determinePathRunnersCount,
                    WaitMethod.WaitAll,
                    itemsArray => Array.Find(itemsArray, s => s.Done) !
                                                                                   );
                determinePathRunnerSet.Run();

                if (determinePathRunnerSet.Done)
                {
                    bool  result = determinePathRunnerSet.CurrentItem.Result;
                    int[] output = determinePathRunnerSet.CurrentItem.Output;

                    return(result, output);
                }
            }
        }
Ejemplo n.º 2
0
        public (bool, int[]) Determine(int[] input)
        {
            int inputLength = input.Length;

            ICPLTMInfo cpltmInfo = configuration.Get <ICPLTMInfo>(
                new Ninject.Parameters.ConstructorArgument(
                    nameof(inputLength),
                    input.Length));
            IDebugOptions debugOptions = configuration.Get <IDebugOptions>();

            cpltmInfo.ComputeSequences();

            uint  maxMu     = cpltmInfo.PathLength;
            ulong currentMu = debugOptions.muStart;

            log.InfoFormat($"path length: {cpltmInfo.PathLength}");

            MEAPSharedContext MEAPSharedContext = new()
            {
                MNP       = tMachine,
                Input     = input,
                CPLTMInfo = cpltmInfo
            };

            MEAPSharedContext.InitInstance = new TMInstance(
                MEAPSharedContext.MNP,
                MEAPSharedContext.Input);

            MEAPSharedContext.MNP.PrepareTapeFwd(
                MEAPSharedContext.Input,
                MEAPSharedContext.InitInstance);

            MEAPSharedContext.CancellationTokenSource = new CancellationTokenSource();
            MEAPSharedContext.CancellationToken       = MEAPSharedContext.CancellationTokenSource.Token;

            MEAPSharedContext.NodeLevelInfo = new NodeLevelInfo();

            ITASGBuilder tasgBuilder = configuration.Get <ITASGBuilder>();

            MEAPSharedContext.TASGBuilder = tasgBuilder;
            tasgBuilder.MEAPSharedContext = MEAPSharedContext;

            tasgBuilder.Init();

            ITPLOptions tplOptions = configuration.Get <ITPLOptions>();
            uint        determinePathRunnersCount = tplOptions.DeterminePathRunnersCount;

            bool result;

            int[] output;

            while (currentMu <= maxMu)
            {
                List <DeterminePathRunner> determinePathRunners = new();

                for (long i = 0; i < determinePathRunnersCount; i++)
                {
                    DeterminePathRunnerCtorArgs determinePathRunnerCtorArgs = new()
                    {
                        tMachine          = tMachine,
                        input             = input,
                        currentMu         = currentMu,
                        MEAPSharedContext = MEAPSharedContext
                    };

                    currentMu++;

                    DeterminePathRunner determinePathRunner =
                        configuration.Get <DeterminePathRunner>(
                            new Ninject.Parameters.ConstructorArgument(
                                nameof(determinePathRunnerCtorArgs),
                                determinePathRunnerCtorArgs));

                    determinePathRunners.Add(determinePathRunner);
                }

                TPLCollectionRunner <DeterminePathRunner> determinePathRunnerSet = new
                                                                                   (
                    determinePathRunners,
                    determinePathRunnersCount,
                    WaitMethod.WaitAll,
                    itemsArray => Array.Find(itemsArray, s => s.Done) !
                                                                                   );

                determinePathRunnerSet.Run();

                if (determinePathRunnerSet.Done)
                {
                    result = determinePathRunnerSet.CurrentItem.Result;
                    output = determinePathRunnerSet.CurrentItem.Output;

                    break;
                }
            }

            result = true;
            output = Array.Empty <int>();

            return(result, output);
        }
        public override void Run(uint[] states)
        {
            log.InfoFormat("mu: {0}", meapContext.mu);

            ITASGBuilder tasgBuilder = configuration.Get <ITASGBuilder>();

            meapContext.TASGBuilder = tasgBuilder;
            tasgBuilder.meapContext = meapContext;

            tasgBuilder.Init();
            tasgBuilder.CreateTArbitrarySeqGraph();
            tasgBuilder.CreateTArbSeqCFG(states);
            meapContext.TArbSeqCFG.Trace();

            if (meapContext.TArbSeqCFG.IsTrivial())
            {
                return;
            }

            ComputeNodeVLevels(meapContext.TArbSeqCFG);

            ICommonOptions       commonOptions       = configuration.Get <ICommonOptions>();
            ICheckDataStructures checkDataStructures = configuration.Get <ICheckDataStructures>();

            if (commonOptions.CheckDataStructures)
            {
                checkDataStructures.CheckTASGHasNoBackAndCrossEdges(meapContext.TArbSeqCFG);
            }

            meapContext.DUPairCount       = 0;
            meapContext.TConsistPairCount = 0;

            TConsistPairSetBuilderOrd tConsistPairSetBuilder = new(meapContext);

            tConsistPairSetBuilder.Run();

            log.InfoFormat("defUsePairSet: {0}", meapContext.DUPairCount);
            log.InfoFormat("TConsistPairSet: {0}", meapContext.TConsistPairCount);

            meapContext.CommoditiesBuilder = new CommoditiesBuilderOrd(meapContext);
            meapContext.CommoditiesBuilder.EnumeratePairs();

            IDebugOptions debugOptions = configuration.Get <IDebugOptions>();

            if (debugOptions.ComputeCommoditiesExplicitely)
            {
                meapContext.Commodities = meapContext.CommoditiesBuilder.CreateCommodities();
                meapContext.CommoditiesBuilder.CreateCommodityGraphs();
            }
            else
            {
                meapContext.Commodities = new SortedDictionary <long, Commodity>();
            }

            log.DebugFormat("states = {0}", AppHelper.ArrayToString(states));

            DetermineIfExistsTCPath determineIfExistsTCSeq = new(meapContext);

            determineIfExistsTCSeq.RunForMultipleTapeSegs();

            CopyResultFromTapeSegContext();
        }