예제 #1
0
        /// <summary>
        /// Variant of 4th step of normalizing(should be used if constraint system has more than(>=) and equal(=) constraints, 
        /// except less than constraints, which were changed on previous step)
        /// </summary>
        /// <param name="problem">Initial problem</param>
        /// <returns>Changed problem(new object)</returns>
        public LppForSimplexMethod ChangeBothTypesOfConstraints(LppForSimplexMethod problem)
        {
            var problemCopy = new LppForSimplexMethod(problem);

            //1.
            var maxIndex = EqualConstraintWithBiggestFreeCoefficient(problemCopy);
            //2.
            for (var i = 0; i < problemCopy.ConstraintCount; i++)
            {
                var currConstraint = problemCopy.GetConstraint(i);
                if (problemCopy.LessThanConstraintsIndexes.Contains(i) || currConstraint.Sign != ">=")
                    continue;

                var constraintWithMaxCoef = problemCopy.GetConstraint(maxIndex);

                while (currConstraint.RightSide >= constraintWithMaxCoef.RightSide)
                    currConstraint.Divide(2);

                currConstraint.Multiply(-1);
                problemCopy.AddAdditionalVariable(i);

                currConstraint.Add(constraintWithMaxCoef);
            }
            //3.
            for (var i = 0; i < problemCopy.ConstraintCount; i++)
                if (problemCopy.GetBasisVariableLabel(i) == null)
                    problemCopy.AddArtificialVariable(i);

            return problemCopy;
        }
예제 #2
0
        /// <summary>
        /// Variant of 4th step of normalizing(should be used if constraint system has only more than constraints, 
        /// except less than constraints, which were changed on previous step)
        /// </summary>
        /// <param name="problem">Initial problem</param>
        /// <returns>Changed problem(new object)</returns>
        public LppForSimplexMethod ChangeMoreThanConstraints(LppForSimplexMethod problem)
        {
            var problemCopy = new LppForSimplexMethod(problem);
            //1.
            for (var i = 0; i < problemCopy.ConstraintCount; i++)
                if (!problemCopy.LessThanConstraintsIndexes.Contains(i))
                    problemCopy.AddAdditionalVariable(i);
            //2.
            var maxIndex = EqualConstraintWithBiggestFreeCoefficient(problemCopy);
            //3.
            for (var i = 0; i < problemCopy.ConstraintCount; i++)
            {
                if (problemCopy.LessThanConstraintsIndexes.Contains(i) || i == maxIndex) continue;

                var first = problemCopy.GetConstraint(maxIndex);
                var second = problemCopy.GetConstraint(i);
                second.Multiply(-1);
                second.Add(first);
            }
            //4.
            if (problemCopy.GetBasisVariableLabel(maxIndex) == null)
                problemCopy.AddArtificialVariable(maxIndex);

            return problemCopy;
        }
예제 #3
0
        /// <summary>
        /// 3rd step of normalizing
        /// </summary>
        /// <param name="problem">Initial problem</param>
        /// <returns>Changed problem(new object)</returns>
        public LppForSimplexMethod ChangeLessThanConstraints(LppForSimplexMethod problem)
        {
            var problemCopy = new LppForSimplexMethod(problem);

            for (var i = 0; i < problemCopy.ConstraintCount; i++)
                if (problemCopy.GetConstraint(i).Sign == "<=")
                {
                    problemCopy.AddAdditionalVariable(i);
                    problemCopy.LessThanConstraintsIndexes.Add(i);
                }

            return problemCopy;
        }