Ejemplo n.º 1
0
        public override void Steps()
        {
            /// <summary>
            /// Reduction:
            /// </summary>
            // source set has non-cyclic core
            Log.Information($"Reduction");
            Reduce();

            if (!source.Any())
            {
                // source set was completely reduced
                Result = currentSolution;
                return;
            }

            var lowerBound = LowerBound();

            if (lowerBound >= UpperBound)
            {
                // there is currently no better solution
                Result = boundarySolution;
                return;
            }

            /// <summary>
            /// Fork: choose column against whick will occur the fork
            /// </summary>
            // source set has cyclic core
            var chosen = new WeightsCalculator(source).ChooseColumn();

            Log.Information($"Is occur the fork against column {chosen}");

            /// <summary>
            /// Option 1: chosen column is added to the solution; chosen = 1
            /// </summary>
            Log.Information($"Option 1: column {chosen} is added to the solution");

            var source1 = source.ToDictionary();

            source1.RemoveAssociatedRows(chosen);
            Log.Information($"Select Chosen Column: {{{chosen}}} {source1.Print()}");

            var solution1 = currentSolution.ToList();

            solution1.Add(chosen);
            Log.Information($"Current Solution: {solution1.Print()}");

            var result1 = new UnateCovering(source1, solution1, boundarySolution).Result;

            if (result1.Count < UpperBound)
            {
                boundarySolution = result1;
                if (UpperBound == lowerBound)
                {
                    Result = boundarySolution;
                    return;
                }
            }

            /// <summary>
            /// Option 0: chosen column is removed from the source set; chosen = 0
            /// </summary>
            Log.Information($"Option 0: column {chosen} is removed from the source set");

            var source0 = source.ToDictionary();

            source0.RemoveColumn(chosen);
            Log.Information($"Remove Chosen Column: {{{chosen}}} {source0.Print()}");

            var result0 = new UnateCovering(source0, currentSolution, boundarySolution).Result;

            if (result0.Count < UpperBound)
            {
                boundarySolution = result0;
            }

            Result = boundarySolution;
            return;
        }
Ejemplo n.º 2
0
        public List <List <Complex> > GetPreparedModes(CalculatedModesInfo modesInfo, int MaxM, List <double> receiverDepths, int Nrd, string Comp, List <string> warnings)
        {
            var PhiR = new List <List <Complex> >(MaxM + 1);

            for (var i = 0; i <= MaxM; i++)
            {
                PhiR.Add(Enumerable.Repeat(new Complex(), Nrd + 1).ToList());
            }

            var weightsCalculator = new WeightsCalculator();

            var(w, ird) = weightsCalculator.CalculateWeightsAndIndices(modesInfo.Z, modesInfo.NTot, receiverDepths, Nrd);

            if (modesInfo.ModesCount > MaxM)
            {
                modesInfo.ModesCount = MaxM;
            }

            if (modesInfo.BCTop == "A")
            {
                kTop2 = Complex.Pow((2 * Math.PI * modesInfo.Frequency / modesInfo.CPTop), 2);
            }

            if (modesInfo.BCBottom == "A")
            {
                kBot2 = Complex.Pow((2 * Math.PI * modesInfo.Frequency / modesInfo.CPBottom), 2);
            }

            var tolerance = 1500 / modesInfo.Frequency;

            for (var ir = 1; ir <= Nrd; ir++)
            {
                var iz = ird[ir];
                var wt = Math.Abs(Math.Min(w[ir], 1 - w[ir]));

                if (receiverDepths[ir] < modesInfo.DepthTop)
                {
                    if (modesInfo.CSTop != 0 || modesInfo.BCTop != "A")
                    {
                        warnings.Add($"Receiver depth: {receiverDepths[ir]}. Highest valid depth: {modesInfo.DepthTop}. Rcvr above depth of top.");
                    }
                }
                else if (receiverDepths[ir] > modesInfo.DepthBottom)
                {
                    if (modesInfo.CSBottom != 0 || modesInfo.BCBottom != "A")
                    {
                        warnings.Add($"Receiver depth: {receiverDepths[ir]}. Lowest valid depth: {modesInfo.DepthBottom}. Rcvr below depth of top.");
                    }
                }
                else if (modesInfo.NTot > 1)
                {
                    if (wt * (modesInfo.Z[iz + 1] - modesInfo.Z[iz]) > tolerance)
                    {
                        warnings.Add($"Receiver depth: {receiverDepths[ir]}. Nearest depths: {modesInfo.Z[iz]}, {modesInfo.Z[iz+1]}. Modes not tabulated near requested pt.");
                    }
                }
                else
                {
                    if (Math.Abs(receiverDepths[iz] - modesInfo.Z[iz]) > tolerance)
                    {
                        warnings.Add($"Rd, Tabulation depth {receiverDepths[ir]}, {modesInfo.Z[iz]}. tolerance: {tolerance}. Modes not tabulated near requested pt.");
                    }
                }
            }

            for (var mode = 1; mode <= modesInfo.ModesCount; mode++)
            {
                PhiR[mode] = PrepareOneMode(modesInfo, w, ird, receiverDepths, Nrd, mode, Comp);
            }

            return(PhiR);
        }