예제 #1
0
        public void Dict1_ShouldEnterWith_4_ShouldLeaveWith_3_WithObjective_7_0()
        {
            var linearProgram = _reader.Read(DictionaryFiles + @"dict1");

            _analyze.Analyze(linearProgram);

            _analyze.Entering.ShouldEqual(4);
            _analyze.Leaving.ShouldEqual(3);

            _pivotor.Pivot(_analyze.Entering, _analyze.Leaving, linearProgram);
            linearProgram.ObjectiveValue.ShouldEqual(7.0, Tolerance);
        }
예제 #2
0
        private LinearProgamSolution SolveSingle(LinearProgram linearProgram)
        {
            var pivotCount = 0;

            while (true)
            {
                //do this until no entering, or stop if unbounded
                _analyze.Analyze(linearProgram);

                //no entering, must be solved
                if (_analyze.Entering == 0)
                {
                    break;
                }

                //if unbounded
                if (_analyze.Leaving == 0)
                {
                    return(new LinearProgamSolution(0, 0, LinearProgramSolutionType.Unbounded));
                }

                //if here, we can pivot
                ++pivotCount;

                _pivotor.Pivot(_analyze.Entering, _analyze.Leaving, linearProgram);
            }

            return(new LinearProgamSolution(linearProgram.ObjectiveValue, pivotCount, LinearProgramSolutionType.Solved));
        }