Esempio n. 1
0
        /// <summary>
        /// Creates files for producing a formal proof for the given linear program
        /// </summary>
        static bool ProcessLP(string fname, LpNumber upperBound, int precision, ListHyp hypermap, bool infeasible, bool holTerms)
        {
            if (precision > 7)
            {
                throw new Exception("Cannot solve the problem: " + fname);
            }

            LP         lp;
            LPSolution sol;

            // Load an LP
            FileStream fs = new FileStream(fname + ".lp", FileMode.Open);

            using (fs)
            {
                StreamReader r       = new StreamReader(fs);
                Scanner      scanner = new Scanner(r, fname + ".lp");

                lp = LP.ParseLP(scanner);
            }

            // Load solutions
            fs = new FileStream(fname + ".txt", FileMode.Open);
            using (fs)
            {
                sol = LPSolution.LoadSolution(new StreamReader(fs), precision, upperBound, infeasible);
            }

            if (!infeasible && sol.Optimal.value > upperBound.value)
            {
                throw new Exception("Optimal value is greater than " + upperBound.value + ": " + fname);
            }

            if (!lp.SetSolution(sol, precision, infeasible))
            {
                return(false);
            }

            // Create a test file containing all inequalities explicitly
//            FileStream test = new FileStream(fname + "_test.hl", FileMode.Create);
//            lp.ConvertToHOL(new StreamWriter(test), precision);
//            test.Close();

            // Create a certificate file
            FileStream main     = new FileStream(fname + "_out.hl", FileMode.Create);
            FileStream main_bin = new FileStream(fname + "_out.bin", FileMode.Create);

            lp.PrintCertificate(new StreamWriter(main), new BinaryWriter(main_bin), precision, hypermap, log, infeasible, holTerms);
            main_bin.Close();
            main.Close();

            // Debug file with text inequalities
//            FileStream text = new FileStream(fname + "_text.hl", FileMode.Create);
//            lp.PrintAllText(new StreamWriter(text), precision, hypermap);
//            text.Close();

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates files for a formal proof for a general linear program
        /// </summary>
        static bool processLPGeneral(string fname, int precision, LpNumber upperBound)
        {
            if (precision > 10)
            {
                throw new Exception("Cannot solve the problem (precision > 10): " + fname);
            }

            LP         lp;
            LPSolution sol;

            // Load an LP
            FileStream fs = new FileStream(fname + ".lp", FileMode.Open);

            using (fs)
            {
                StreamReader r       = new StreamReader(fs);
                Scanner      scanner = new Scanner(r, fname + ".lp");

                lp = LP.ParseLP(scanner);
            }

            // Load solutions
            fs = new FileStream(fname + ".txt", FileMode.Open);
            using (fs)
            {
                sol = LPSolution.LoadSolution(new StreamReader(fs), precision, upperBound, false);
            }

            if (!lp.SetSolution(sol, precision, false))
            {
                return(false);
            }

            // Create a test file containing all inequalities explicitly
            FileStream test = new FileStream(fname + "_test.hl", FileMode.Create);

            lp.ConvertToHOL(new StreamWriter(test), precision);
            test.Close();

            return(true);
        }