Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.Write("Enter file path: ");
            FileReader fr = new FileReader(Console.ReadLine());
            Equation   e  = fr.GetEquation();

            //e.SetRow(0, new double[] {1, -3 }, true, 1);
            //e.SetRow(1, new double[] {1, 1 }, true,5);
            //e.SetRow(2, new double[] {0, 1 }, false,10);
            //e.SetRow(3, new double[] {2, 1 }, false,15);
            //e.SetFunc(new double[] { 4, 1 }, true);
            e.Print();
            e.PrintRevers();
            e.Canonize();
            Console.WriteLine("Canonize:");
            e.Print();
            e.FindDbr();
            e.PrintDBR();
            e.Simplex();
            e.PrintAnswer();
        }
Ejemplo n.º 2
0
        public Equation GetEquation()
        {
            var      content = File.ReadAllLines(path, Encoding.UTF8);
            Equation e       = new Equation(content.Count() - 1);
            var      f       = content[0].Split("->".ToCharArray());

            f[0] = f[0].Substring(f[0].IndexOf('=') + 1);
            var           f1    = f[0].Split(' ');
            List <double> fList = new List <double>();

            foreach (var s in f1)
            {
                double t = 0;
                if (double.TryParse(s, out t))
                {
                    fList.Add(t);
                }
            }

            e.SetFunc(fList, f[2].Trim() == "max");
            for (int i = 1; i < content.Count(); i++)
            {
                bool   gt = false;
                double r  = 0;
                var    eq = content[i].Split(' ');
                fList.Clear();
                foreach (var s in eq)
                {
                    if (s == ">=")
                    {
                        gt = true;
                        r  = double.MaxValue;
                    }
                    else if (s == "<=")
                    {
                        gt = false;
                        r  = double.MaxValue;
                    }
                    else if (r == double.MaxValue)
                    {
                        double t = 0;
                        if (double.TryParse(s, out t))
                        {
                            r = t;
                        }
                    }
                    else
                    {
                        double t = 0;
                        if (double.TryParse(s, out t))
                        {
                            fList.Add(t);
                        }
                    }
                }
                e.SetRow(i - 1, fList, gt, r);
            }



            return(e);
        }