Beispiel #1
0
        public void JobAssignment()
        {
            // J = Job | W = Worker
            //     J1  J2  J3  J4
            // W1  82  83  69  92
            // W2  77  37  49  92
            // W3  11  69  5   86
            // W4  8   9   98  23

            int[,] matrix =
            {
                { 82, 83, 69, 92 },
                { 77, 37, 49, 92 },
                { 11, 69,  5, 86 },
                {  8,  9, 98, 23 }
            };
            var algorithm = new HungarianAlgorithm(matrix);

            algorithm.Compute();

            Assert.IsNotNull(algorithm.AgentsTasks);
            int[] tasks = algorithm.AgentsTasks;
            Assert.AreEqual(2, tasks[0]); // J1 to be done by W3
            Assert.AreEqual(1, tasks[1]); // J2 to be done by W2
            Assert.AreEqual(0, tasks[2]); // J3 to be done by W1
            Assert.AreEqual(3, tasks[3]); // J4 to be done by W4
        }
        public void Compute()
        {
            int[,] matrix = { { 1, 2, 3 }, { 3, 3, 3 }, { 3, 3, 2 } };
            var algorithm = new HungarianAlgorithm(matrix);

            int[] res = algorithm.Compute();
            Assert.AreEqual(res[0], 0);
            Assert.AreEqual(res[1], 1);
            Assert.AreEqual(res[2], 2);
        }
Beispiel #3
0
        public void SimpleAssignment()
        {
            int[,] matrix =
            {
                { 1, 2, 3 },
                { 3, 3, 3 },
                { 3, 3, 2 }
            };
            var algorithm = new HungarianAlgorithm(matrix);

            int[] tasks = algorithm.Compute();

            Assert.AreEqual(0, tasks[0]);
            Assert.AreEqual(1, tasks[1]);
            Assert.AreEqual(2, tasks[2]);
        }