Exemple #1
0
        private static void WriteAssignment2Solution(string fileName)
        {
            var reader        = new LinearProgramDictionaryReader();
            var linearProgram = reader.Read(fileName);

            var analyze    = new SimpleAnalyzeEnteringLeavingVariables();
            var calculator = new HackyPivot2();
            var solver     = new LinearProgramSolverWeek2(analyze, calculator);
            var solution   = solver.Solve(linearProgram);

            if (solution.SolutionType == LinearProgramSolutionType.Unbounded)
            {
                const string output = "UNBOUNDED";
                File.WriteAllText(fileName + ".output", output);
            }
            else
            {
                var output = String.Format("{1}{0}{2}",
                                           Environment.NewLine,
                                           solution.ObjectiveValue,
                                           solution.PivotCount);

                File.WriteAllText(fileName + ".output", output);
            }
        }
Exemple #2
0
        private static void WriteAssignment3Solution(string fileName)
        {
            var reader        = new LinearProgramDictionaryReader();
            var linearProgram = reader.Read(fileName);

            var analyze      = new SimpleAnalyzeEnteringLeavingVariables();
            var calculator   = new HackyPivot2();
            var primalToDual = new HackyMapPrimalToDual();
            var dualToPrimal = new HackyMapDualToPrimal();
            var restore      = new SimpleRestoreObjective();

            var solver = new LinearProgramSolverWeek3(analyze, calculator, primalToDual, dualToPrimal, restore);

            var solution = solver.Solve(linearProgram);

            if (solution.SolutionType == LinearProgramSolutionType.Unbounded)
            {
                const string output = "UNBOUNDED";
                File.WriteAllText(fileName + ".output", output);
            }
            else if (solution.SolutionType == LinearProgramSolutionType.Infeasible)
            {
                const string output = "INFEASIBLE";
                File.WriteAllText(fileName + ".output", output);
            }
            else
            {
                var output = String.Format("{0}", solution.ObjectiveValue);
                File.WriteAllText(fileName + ".output", output);
            }
        }
Exemple #3
0
        private static void WriteAssignment1Solution(string fileName)
        {
            var reader        = new LinearProgramDictionaryReader();
            var linearProgram = reader.Read(fileName);

            var analyze = new SimpleAnalyzeEnteringLeavingVariables();

            analyze.Analyze(linearProgram);

            var calculator = new HackyPivot();

            calculator.Pivot(analyze.Entering, analyze.Leaving, linearProgram);
            var obj = linearProgram.ObjectiveValue;

            if (analyze.Entering != 0 && analyze.Leaving != 0)
            {
                var output = String.Format("{1}{0}{2}{0}{3}",
                                           Environment.NewLine,
                                           analyze.Entering,
                                           analyze.Leaving,
                                           obj);

                File.WriteAllText(fileName + ".output", output);
            }
        }