Exemplo n.º 1
0
        public static int FindPercentOfChange(SearchParameters parameters, Solver solver, Random rand)
        {
            if (!(parameters is ParametersForDefined))
            {
                throw new ArgumentException("Wrong parameters type in method PercentFinder.ParametersForDefined. Need to be ParametersForDefined.");
            }
            var  param   = (ParametersForDefined)parameters;
            int  percent = 0;
            bool change  = false;
            int  cNumber = param.Cs.Length;

            double[]   newX           = new double[param.OldX.Length];
            double[]   result         = new double[param.OldX.Length];
            double[]   oldX           = param.OldX;
            double[]   selectedValues = null;
            double[]   solutions;
            double[][] changedCs = new double[cNumber][];
            param.OldX.CopyTo(newX, 0);
            param.OldX.CopyTo(result, 0);

            switch (parameters.CChangeParameters)
            {
            case CChangeParameters.Default:
                selectedValues = GetAll(oldX);
                break;

            case CChangeParameters.Basic:
                selectedValues = GetBasic(oldX);
                break;

            case CChangeParameters.NonBasic:
                selectedValues = GetNonBasic(oldX);
                break;
            }

            while (!change)
            {
                if (newX.SequenceEqual(oldX))
                {
                    CopyMultidimensional(param.Cs, ref changedCs);
                    percent++;
                    ChangeMatrixs(ref changedCs, percent, selectedValues, rand);
                    (_, solutions) = solver.GetSolutions(changedCs, param.A, param.B);
                    (newX, _)      = solver.SolveSeveral(changedCs, param.A, param.B, param.L, param.Alpha, solutions);
                    result         = newX;
                    newX           = solver.DivideX(solver.RoundVector(newX), cNumber);
                }
                else
                {
                    change = true;
                    changedCs.CopyTo(param.Cs, 0);
                }
            }
            param.DefineXs(result);
            return(percent);
        }
        private int GetPercentOfChange(SearchParameters parameters, Solver solver, Random random)
        {
            if (!(parameters is ParametersForRandom))
            {
                throw new ArgumentException("Wrong parameters type in method Experiment.GetPercentOfChange. Need to be ParametersForRandom.");
            }
            var param = (ParametersForRandom)parameters;
            int percent;

            double[]   x     = new double[param.Size * param.Size];
            double[][] cs    = new double[param.MatrixQuantity][];
            double[]   a     = new double[param.Size];
            double[]   b     = new double[param.Size];
            double[]   l     = new double[param.MatrixQuantity];
            double[]   alpha = new double[param.MatrixQuantity];
            double[]   solutions;

            bool success = false;

            while (!success)
            {
                (a, b) = _generator.GenerateAB(param.Size, random);
                l      = _generator.GenerateL(param.MatrixQuantity, random);
                alpha  = _generator.GenerateAlpha(param.MatrixQuantity);
                for (int i = 0; i < param.MatrixQuantity; i++)
                {
                    cs[i] = _generator.GenerateMatrix(param.Size, random);
                }
                (_, solutions) = solver.GetSolutions(cs, a, b);
                (x, _)         = solver.SolveSeveral(cs, a, b, l, alpha, solutions);
                x = solver.DivideX(solver.RoundVector(x), param.MatrixQuantity);
                if (!solver.CheckABConstraints(x, a, b))
                {
                    continue;
                }
                success = true;
            }
            var parametersForDefined = new ParametersForDefined(x, cs, a, b, l, alpha, _cChangeParameters);

            percent = PercentFinder.FindPercentOfChange(parametersForDefined, solver, random);
            return(percent);
        }