Esempio n. 1
0
        public void Step2()
        {
            log.Info("TCPEP optimizer: step2");

            ITPLOptions tplOptions           = configuration.Get <ITPLOptions>();
            uint        linEqSetRunnersCount = tplOptions.LinEqSetRunnersCount;

            Commodity[] commoditiesToCheck = commoditiesSelector.Run(linEqSetRunnersCount);

            if (commoditiesToCheck.Length == 0)
            {
                Finished = true;

                return;
            }

            SortedSet <long>        tConsistPathComms   = new();
            SortedSet <long>        tInconsistPathComms = new();
            List <CommodityChecker> commCheckers        = new();

            ILinEqsAlgorithmProvider linEqsAlgorithmProvider = configuration.Get <ILinEqsAlgorithmProvider>();

            for (long i = 0; i < commoditiesToCheck.Length; i++)
            {
                Commodity commodity = commoditiesToCheck[i];

                commCheckers.Add(
                    linEqsAlgorithmProvider.GetTCPEPCommChecker(
                        meapContext,
                        tapeSegContext,
                        commodity,
                        tConsistPathComms,
                        tInconsistPathComms));
            }

            TPLCollectionRunner <CommodityChecker> commodityCheckerRunner = new
                                                                            (
                commCheckers,
                linEqSetRunnersCount,
                WaitMethod.WaitAll,
                _ => default !
Esempio n. 2
0
        private void RunGaussElimination()
        {
            ITPLOptions tplOptions            = configuration.Get <ITPLOptions>();
            uint        gaussElimRunnersCount = tplOptions.GaussElimRunnersCount;

            long s = 0;

            long[] rowsToSubtract = new long[gaussElimRunnersCount];

            for (long k = 0; k < m; k++)
            {
                long i_max = -1;

                while (true)
                {
                    if (k + s == n)
                    {
                        return;
                    }

                    for (long i = k; i < m; i++)
                    {
                        if (!(A.Get(i, k + s).IsEqualsTo0()))
                        {
                            i_max = i;
                        }
                    }

                    if (i_max == -1)
                    {
                        s++;
                    }
                    else
                    {
                        break;
                    }
                }

                A.SwapRows(k, i_max);

                long p = k + s;

                SortedDictionary <long, RationalNumber> Mk = A.GetRow(k);
                RationalNumber Mkp = SparseMatrix.Get(Mk, p);

                long   rowsToProcessCount = m - (k + 1);
                long[] rowsToProcess      = new long[m];

                for (long w = 0; w < rowsToProcessCount; w++)
                {
                    long d = w + (k + 1);
                    rowsToProcess[d] = d;
                }

                long from = k + 1;

                while (true)
                {
                    SelectRows(
                        rowsToProcess,
                        from,
                        gaussElimRunnersCount,
                        rowsToSubtract,
                        out long rowsToSubtractCount);

                    if (rowsToSubtractCount == 0)
                    {
                        break;
                    }

                    Task[] tasks = new Task[rowsToSubtractCount];
                    List <RowSubtractorSparceMThreads> rowSubtractors = new();

                    for (int i = 0; i < rowsToSubtractCount; i++)
                    {
                        long row = rowsToSubtract[i];
                        RowSubtractorSparceMThreads rowSubtractor = new();

                        rowSubtractor.A        = A;
                        rowSubtractor.rowIndex = row;
                        rowSubtractor.m        = m;
                        rowSubtractor.n        = n;
                        rowSubtractor.p        = p;
                        rowSubtractor.Mk       = Mk;
                        rowSubtractor.Mkp      = Mkp;

                        rowSubtractors.Add(rowSubtractor);
                    }

                    TPLCollectionRunner <RowSubtractorSparceMThreads> rowSubtractorsRunner = new
                                                                                             (
                        rowSubtractors,
                        gaussElimRunnersCount,
                        WaitMethod.WaitAll,
                        _ => default !
Esempio n. 3
0
        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;

            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);
                }
            }
        }
Esempio n. 4
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);
        }