예제 #1
0
        public static void Main(string[] args)
        {
            ILPTask task = null;

            task = new ILPTask () {
                C = DenseVector.OfEnumerable (new [] {
                    7.0, -2, 6, 0, 5, 2,
                }),
                B = DenseVector.OfEnumerable (new [] {
                    -8.0, 22, 30
                }),
                M = 3,
                N = 6,
                A = DenseMatrix.OfArray (new [,] {
                    { 1.0, -5, 3, 1, 0, 0 },
                    { 4.0, -1, 1, 0, 1, 0, },
                    { 2.0, 4, 2, 0, 0, 1 },
                }),
                DL = DenseVector.OfEnumerable (new [] {
                    0.0, 0, 0, 0, 0, 0
                }),
                DR = DenseVector.OfEnumerable (new [] {
                    1e100, 1e100, 1e100, 1e100, 1e100, 1e100
                }),
            };

            var result = task.SolveILPByCutoff ();
            Console.WriteLine ("=========== FINAL SOLUTION");
            Console.WriteLine (result);
            Console.WriteLine ("VALUE");
            Console.WriteLine (task.C * result);
        }
예제 #2
0
        public Dictionary<string, ILPTask> ReadTasks()
        {
            var doc = new XmlDocument ();
            doc.Load (fileName);

            var tasks = new Dictionary<string, ILPTask> ();

            foreach (XmlNode node in doc.GetElementsByTagName("Task").Cast<XmlNode>()) {
                string name = readAttribute (node, "Name");

                var A = (DenseMatrix)(readMatrixChild (node, "A"));
                var b = (DenseVector)readMatrixChild (node, "b").Row (0);
                var c = (DenseVector)readMatrixChild (node, "c").Row (0);

                DenseMatrix dLeftMatrix = readMatrixChild (node, "dLeft");
                DenseVector dLeft = dLeftMatrix == null ? null : (DenseVector)dLeftMatrix.Row (0);

                DenseMatrix dRightMatrix = readMatrixChild (node, "dRight");
                DenseVector dRight = dRightMatrix == null ? null : (DenseVector)dRightMatrix.Row (0);

                var task = new ILPTask { A = A, B = b, C = c, DL = dLeft, DR = dRight };

                tasks [name] = task;
            }

            return tasks;
        }
예제 #3
0
        public static void Main(string[] args)
        {
            ILPTask task = null;

            task = new ILPTask()
            {
                C = DenseVector.OfEnumerable(new [] {
                    7.0, -2, 6, 0, 5, 2,
                }),
                B = DenseVector.OfEnumerable(new [] {
                    -8.0, 22, 30
                }),
                M = 3,
                N = 6,
                A = DenseMatrix.OfArray(new [, ] {
                    { 1.0, -5, 3, 1, 0, 0 },
                    { 4.0, -1, 1, 0, 1, 0, },
                    { 2.0, 4, 2, 0, 0, 1 },
                }),
                DL = DenseVector.OfEnumerable(new [] {
                    0.0, 0, 0, 0, 0, 0
                }),
                DR = DenseVector.OfEnumerable(new [] {
                    1e100, 1e100, 1e100, 1e100, 1e100, 1e100
                }),
            };

            var result = task.SolveILPByCutoff();

            Console.WriteLine("=========== FINAL SOLUTION");
            Console.WriteLine(result);
            Console.WriteLine("VALUE");
            Console.WriteLine(task.C * result);
        }
예제 #4
0
파일: Main.cs 프로젝트: RandomStuffs22/Labs
        public static void Main(string[] args)
        {
            ILPTask task = null;

            task = new ILPTask()
            {
                C = DenseVector.OfEnumerable(new [] {
                    -2.0, 1, -2, -1, 8, -5, 3, 5, 1, 2,
                }),
                B = DenseVector.OfEnumerable(new [] {
                    27.0, 6, 18
                }),
                M = 3,
                N = 10,
                A = DenseMatrix.OfArray(new [, ] {
                    { 1.0, 0, 0, 1, 1, -3, 4, -1, 3, 3 },
                    { 0.0, 1, 0, -2, 1, 1, 7, 3, 4, 5 },
                    { 0.0, 0, 1, 1, 0, 2, -2, 1, -4, 7 },
                }),
                DL = DenseVector.OfEnumerable(new [] {
                    0.0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                }),
                DR = DenseVector.OfEnumerable(new [] {
                    8.0, 7, 6, 7, 8, 5, 6, 7, 8, 5,
                }),
            };

            /*
             * task = new ILPTask () {
             *      C = DenseVector.OfEnumerable (new [] {
             *              1.0, 2, 3, -1, 4, -5, 6
             *      }),
             *      B = DenseVector.OfEnumerable (new [] {
             *              26, 185, 32.5
             *      }),
             *      M = 3,
             *      N = 7,
             *      A = DenseMatrix.OfArray (new [,] {
             *              { 1.0, 0, 1, 0, 4, 3, 4 },
             *              { 0.0, 1, 2, 0, 55, 3.5, 5 },
             *              { 0.0, 0, 3, 1, 6, 2, -2.5 },
             *      }),
             *      DL = DenseVector.OfEnumerable (new [] {
             *              0.0, 1, 0, 0, 0, 0, 0,
             *      }),
             *      DR = DenseVector.OfEnumerable (new [] {
             *              1.0, 2, 5, 7, 8, 4, 2,
             *      }),
             * };*/

            var result = task.SolveILByBranching();

            Console.WriteLine("=========== FINAL SOLUTION");
            Console.WriteLine(result);
            Console.WriteLine("VALUE");
            Console.WriteLine(task.C * result);
        }
예제 #5
0
파일: Main.cs 프로젝트: RandomStuffs22/Labs
        public static void Main(string[] args)
        {
            ILPTask task = null;

            task = new ILPTask () {
                C = DenseVector.OfEnumerable (new [] {
                    -2.0, 1, -2, -1, 8, -5, 3, 5, 1, 2,
                }),
                B = DenseVector.OfEnumerable (new [] {
                    27.0, 6, 18
                }),
                M = 3,
                N = 10,
                A = DenseMatrix.OfArray (new [,] {
                    { 1.0, 0, 0, 1, 1, -3, 4, -1, 3, 3 },
                    { 0.0, 1, 0, -2, 1, 1, 7, 3, 4, 5 },
                    { 0.0, 0, 1, 1, 0, 2, -2, 1, -4, 7 },
                }),
                DL = DenseVector.OfEnumerable (new [] {
                    0.0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                }),
                DR = DenseVector.OfEnumerable (new [] {
                    8.0, 7, 6, 7, 8, 5, 6, 7, 8, 5,
                }),
            };

            /*
            task = new ILPTask () {
                C = DenseVector.OfEnumerable (new [] {
                    1.0, 2, 3, -1, 4, -5, 6
                }),
                B = DenseVector.OfEnumerable (new [] {
                    26, 185, 32.5
                }),
                M = 3,
                N = 7,
                A = DenseMatrix.OfArray (new [,] {
                    { 1.0, 0, 1, 0, 4, 3, 4 },
                    { 0.0, 1, 2, 0, 55, 3.5, 5 },
                    { 0.0, 0, 3, 1, 6, 2, -2.5 },
                }),
                DL = DenseVector.OfEnumerable (new [] {
                    0.0, 1, 0, 0, 0, 0, 0,
                }),
                DR = DenseVector.OfEnumerable (new [] {
                    1.0, 2, 5, 7, 8, 4, 2,
                }),
            };*/

            var result = task.SolveILByBranching ();
            Console.WriteLine ("=========== FINAL SOLUTION");
            Console.WriteLine (result);
            Console.WriteLine ("VALUE");
            Console.WriteLine (task.C * result);
        }
예제 #6
0
파일: Program.cs 프로젝트: rettour/Labs
        public static void Main(string[] args)
        {
            var tasks = new List<ILPTask> (new TasksXmlReader ("tasks2.xml").ReadTasks ().Values);
            ILPTask task = null;

            task = new ILPTask () {
                C = DenseVector.OfEnumerable (new [] {
                    -3.5, 1, 0, 0, 0,
                }),
                B = DenseVector.OfEnumerable (new [] {
                    15.0, 6, 0
                }),
                M = 3,
                N = 5,
                A = DenseMatrix.OfArray (new [,] {
                    { 5.0, -1, 1, 0, 0 },
                    { -1.0, 2, 0, 1, 0 },
                    { -7.0, 2, 0, 0, 1 },
                }),
                DL = DenseVector.OfEnumerable (new [] {
                    0.0, 0, 0, 0, 0,
                }),
                DR = DenseVector.OfEnumerable (new [] {
                    1e100, 1e100, 1e100, 1e100, 1e100,
                }),
            };

            task = new ILPTask () {
                C = DenseVector.OfEnumerable (new [] {
                    2.0, -5, 0, 0, 0
                }),
                B = DenseVector.OfEnumerable (new [] {
                    -1.0, 10, 3,
                }),
                M = 3,
                N = 5,
                A = DenseMatrix.OfArray (new [,] {
                    { -2.0, -1, 1, 0, 0 },
                    { 3.0, 1, 0, 1, 0 },
                    { -1.0, 1, 0, 0, 1 },
                }),
                DL = DenseVector.OfEnumerable (new [] {
                    0.0, 0, 0, 0, 0,
                }),
                DR = DenseVector.OfEnumerable (new [] {
                    1e100, 1e100, 1e100, 1e100, 1e100,
                }),
            };

            task = new ILPTask () {
                C = DenseVector.OfEnumerable (new [] {
                    21.0, 11, 0
                }),
                B = DenseVector.OfEnumerable (new [] {
                    13.0,
                }),
                M = 1,
                N = 3,
                A = DenseMatrix.OfArray (new [,] {
                    { 7.0, 4, 1 },
                }),
                DL = DenseVector.OfEnumerable (new [] {
                    0.0, 0, 0,
                }),
                DR = DenseVector.OfEnumerable (new [] {
                    1e100, 1e100, 1e100,
                }),
            };

            task = new ILPTask () {
                C = DenseVector.OfEnumerable (new [] {
                    2.0, 1
                }),
                B = DenseVector.OfEnumerable (new [] {
                    3.0,
                }),
                M = 1,
                N = 2,
                A = DenseMatrix.OfArray (new [,] {
                    { 2.0, 1 },
                }),
                DL = DenseVector.OfEnumerable (new [] {
                    0.0, 0,
                }),
                DR = DenseVector.OfEnumerable (new [] {
                    1e100, 1e100,
                }),
            };

            task = new ILPTask () {
                C = DenseVector.OfEnumerable (new [] {
                    //2.0, -3, 1, 12, -14, 0, 5,
                    -2.0, 3, -1, -12, 14, 0, -5,
                }),
                B = DenseVector.OfEnumerable (new [] {
                    20.0, 4, 14
                }),
                M = 3,
                N = 7,
                A = DenseMatrix.OfArray (new [,] {
                    { 2.0, -3, 4, 5, 6, -8, 4 },
                    { -3.0, 4, -5, 1, 0, 12, -7 },
                    { 1.0, 1, 1, 1, 1, 1, 1 },
                }),
                DL = DenseVector.OfEnumerable (new [] {
                    0.0, 0, 0, 0, 0, 0, 0, 0,
                    //-1.0, -2, 0, -3, -2, -1, -4, -4
                }),
                DR = DenseVector.OfEnumerable (new [] {
                    1e100, 1e100, 1e100,
                    1e100, 1e100, 1e100,
                    1e100, 1e100,
                    //3.0, 4, 5, 3, 4, 5, 3, 4
                }),
            };

            //task = tasks[2];
            var result = task.SolveILPByCutoff ();
            //var result = task.SolveILByBranching ();
            //var result = task.SolveILPByCutoff ();
            Console.WriteLine ("=========== FINAL SOLUTION");
            Console.WriteLine (result);
            Console.WriteLine ("VALUE");
            Console.WriteLine (task.C * result);
        }
예제 #7
0
파일: Program.cs 프로젝트: vledyaev/Labs
        public static void Main(string[] args)
        {
            var     tasks = new List <ILPTask> (new TasksXmlReader("tasks2.xml").ReadTasks().Values);
            ILPTask task  = null;

            task = new ILPTask()
            {
                C = DenseVector.OfEnumerable(new [] {
                    -3.5, 1, 0, 0, 0,
                }),
                B = DenseVector.OfEnumerable(new [] {
                    15.0, 6, 0
                }),
                M = 3,
                N = 5,
                A = DenseMatrix.OfArray(new [, ] {
                    { 5.0, -1, 1, 0, 0 },
                    { -1.0, 2, 0, 1, 0 },
                    { -7.0, 2, 0, 0, 1 },
                }),
                DL = DenseVector.OfEnumerable(new [] {
                    0.0, 0, 0, 0, 0,
                }),
                DR = DenseVector.OfEnumerable(new [] {
                    1e100, 1e100, 1e100, 1e100, 1e100,
                }),
            };


            task = new ILPTask()
            {
                C = DenseVector.OfEnumerable(new [] {
                    2.0, -5, 0, 0, 0
                }),
                B = DenseVector.OfEnumerable(new [] {
                    -1.0, 10, 3,
                }),
                M = 3,
                N = 5,
                A = DenseMatrix.OfArray(new [, ] {
                    { -2.0, -1, 1, 0, 0 },
                    { 3.0, 1, 0, 1, 0 },
                    { -1.0, 1, 0, 0, 1 },
                }),
                DL = DenseVector.OfEnumerable(new [] {
                    0.0, 0, 0, 0, 0,
                }),
                DR = DenseVector.OfEnumerable(new [] {
                    1e100, 1e100, 1e100, 1e100, 1e100,
                }),
            };


            task = new ILPTask()
            {
                C = DenseVector.OfEnumerable(new [] {
                    21.0, 11, 0
                }),
                B = DenseVector.OfEnumerable(new [] {
                    13.0,
                }),
                M = 1,
                N = 3,
                A = DenseMatrix.OfArray(new [, ] {
                    { 7.0, 4, 1 },
                }),
                DL = DenseVector.OfEnumerable(new [] {
                    0.0, 0, 0,
                }),
                DR = DenseVector.OfEnumerable(new [] {
                    1e100, 1e100, 1e100,
                }),
            };



            task = new ILPTask()
            {
                C = DenseVector.OfEnumerable(new [] {
                    2.0, 1
                }),
                B = DenseVector.OfEnumerable(new [] {
                    3.0,
                }),
                M = 1,
                N = 2,
                A = DenseMatrix.OfArray(new [, ] {
                    { 2.0, 1 },
                }),
                DL = DenseVector.OfEnumerable(new [] {
                    0.0, 0,
                }),
                DR = DenseVector.OfEnumerable(new [] {
                    1e100, 1e100,
                }),
            };


            task = new ILPTask()
            {
                C = DenseVector.OfEnumerable(new [] {
                    //2.0, -3, 1, 12, -14, 0, 5,
                    -2.0, 3, -1, -12, 14, 0, -5,
                }),
                B = DenseVector.OfEnumerable(new [] {
                    20.0, 4, 14
                }),
                M = 3,
                N = 7,
                A = DenseMatrix.OfArray(new [, ] {
                    { 2.0, -3, 4, 5, 6, -8, 4 },
                    { -3.0, 4, -5, 1, 0, 12, -7 },
                    { 1.0, 1, 1, 1, 1, 1, 1 },
                }),
                DL = DenseVector.OfEnumerable(new [] {
                    0.0, 0, 0, 0, 0, 0, 0, 0,
                    //-1.0, -2, 0, -3, -2, -1, -4, -4
                }),
                DR = DenseVector.OfEnumerable(new [] {
                    1e100, 1e100, 1e100,
                    1e100, 1e100, 1e100,
                    1e100, 1e100,
                    //3.0, 4, 5, 3, 4, 5, 3, 4
                }),
            };


            //task = tasks[2];
            var result = task.SolveILPByCutoff();

            //var result = task.SolveILByBranching ();
            //var result = task.SolveILPByCutoff ();
            Console.WriteLine("=========== FINAL SOLUTION");
            Console.WriteLine(result);
            Console.WriteLine("VALUE");
            Console.WriteLine(task.C * result);
        }
예제 #8
0
        static void Main(string[] args)
        {
            string[] defaults = { "op", "myData.txt", "myDataout.txt" };

            do
            {
                var command = new string[3];
                defaults.CopyTo(command, 0);
                Console.WriteLine("Enter the command:");
                string[] userCommand = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < userCommand.Length; i++)
                {
                    command[i] = userCommand[i].Trim();
                }

                ITask task = null;
                switch (command[0].ToLower())
                {
                case "lp":
                {
                    task = new LPTask();
                    break;
                }

                case "ilp":
                {
                    task = new ILPTask();
                    break;
                }

                case "ja":
                {
                    task = new JohnsonTask();
                    break;
                }

                case "op":
                {
                    task = new OPTask();
                    break;
                }

                default:
                {
                    Console.WriteLine("Uncorrect command");
                    break;
                }
                }

                try
                {
                    task.ReadDataFromTxt(command[1]);
                }
                catch (Exception e)
                {
                    task = null;
                    Console.WriteLine("Some errors occurred, please check your input and try again.");
                }

                if (task != null)
                {
                    task.Resolve();
                    task.WriteResultToTxt(command[2]);
                    Console.WriteLine("Work has been finished successfully!");
                }

                Console.WriteLine("Press any key to continue or Esc to exit...\n");
                if (Console.ReadKey(true).Key == ConsoleKey.Escape)
                {
                    break;
                }
            } while (true);
        }