public void Run_InfiniteCost_ThrowsException()
 {
     Assert.Throws <ArgumentException>(() => HungarianAlgorithm.Run(new[, ] {
         { float.PositiveInfinity }
     }));
     Assert.Throws <ArgumentException>(() => HungarianAlgorithm.Run(new[, ] {
         { float.NegativeInfinity }
     }));
 }
 public void Run_MoreTargetsThanSources_AssignsSourcesToCheapest()
 {
     Assert.Throws <ArgumentException>(() => HungarianAlgorithm.Run(
                                           new float[, ]
     {
         { 1, 9, 3 },
         { 3, 9, 1 }
     }
                                           ));
 }
 public void Run_MoreSourcesThanTargets_ThrowsException()
 {
     Assert.Throws <ArgumentException>(() => HungarianAlgorithm.Run(
                                           new float[, ]
     {
         { 1, 3 },
         { 9, 9 },
         { 3, 1 }
     }
                                           ));
 }
Exemplo n.º 4
0
        public void RunCheck()
        {
            var matrix = new[, ] {
                { 1, 2, 3 }, { 3, 3, 3 }, { 3, 3, 2 }
            };
            var algorithm = new HungarianAlgorithm(matrix);
            var res       = algorithm.Run();

            Assert.AreEqual(res[0], 0);
            Assert.AreEqual(res[1], 1);
            Assert.AreEqual(res[2], 2);
        }
Exemplo n.º 5
0
        public JsonResult CalculateMatrix()
        {
            const int SIZE = 5000;

            var matrix = generateMatrix(SIZE);

            var algorithm = new HungarianAlgorithm(matrix);

            Thread.Sleep(1000);

            var result = algorithm.Run();

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public void Run_TwoSources_AssignsLowestCostTarget(float f, short s1, short s2, short s3, short s4)
        {
            // The behaviour for equal matching is not defined.
            if (Abs(s1 + s4 - s3 - s2) == 0 || Abs(f) < 1e-10 || Abs(f) > 1e10)
            {
                return;
            }
            var(f1, f2, f3, f4) = (f * s1, f *s2, f *s3, f *s4);

            var result = HungarianAlgorithm.Run(new[, ] {
                { f1, f2 }, { f3, f4 }
            });

            Assert.Equal(f1 + f4 < f3 + f2 ? new[] { 0, 1 } : new[] { 1, 0 }, result);
        }
Exemplo n.º 7
0
        public void ngramset_edit_distance(List <string> mnemonics1, List <string> mnemonics2, int n)
        {
            Ngram ngram1 = new Ngram(mnemonics1, n);
            Ngram ngram2 = new Ngram(mnemonics2, n);

            int set_size = ngram1.ngramSet.Count;
            //int reduced_set_size = set_size  - Math.Max(mnemonics1.FindIndex(delegate (string data) { return data == ""; }), mnemonics2.FindIndex(delegate (string data) { return data == ""; }));
            int ngram_size = n;

            int[,] matrix = ngram_matrix(ngram1.ngramSet, ngram2.ngramSet);
            var hungarian = new HungarianAlgorithm(matrix);

            int[] hungarian_indexes = hungarian.Run();

            double ngram_edit_distance = getTotal(matrix, hungarian_indexes) / set_size / ngram_size;
            double edit_distance       = calc_edit_distance(mnemonics1, mnemonics2);
            double slope1_ratio        = calculate_slope1_ratio(hungarian_indexes);
            double index_similarity2   = calculate_continuous_equal_slope(hungarian_indexes, 2);
            double index_similarity3   = calculate_continuous_equal_slope(hungarian_indexes, 3);

            this.similarity = new ngram_similarity(ngram_edit_distance, edit_distance, slope1_ratio, index_similarity2, index_similarity3);
        }
 public void Run_Metric_MatchClosest()
 {
     Assert.Equal(new[] { 1, 2, 0 },
                  HungarianAlgorithm.Run(new[] { -100, 0, 100 }, new[] { 111, -111, 42 }, (i1, i2) => Abs(i2 - i1)));
 }
 public void Run_NaNCost_ThrowsException()
 {
     Assert.Throws <ArgumentException>(() => HungarianAlgorithm.Run(new[, ] {
         { float.NaN }
     }));
 }
Exemplo n.º 10
0
 public void Run_OneSource_AssignsTarget(float cost)
 {
     Assert.Equal(new[] { 0 }, HungarianAlgorithm.Run(new[, ] {
         { cost }
     }));
 }
Exemplo n.º 11
0
 public void Run_EmptyCostMatrix_ReturnsEmptyResult()
 {
     Assert.Empty(HungarianAlgorithm.Run(new float[0, 0]));
 }
Exemplo n.º 12
0
 public void Run_EmptyCostMatrix_DoesNotFail()
 {
     HungarianAlgorithm.Run(new float[0, 0]);
 }
Exemplo n.º 13
0
 public void Run_Vector3s_MathClosest()
 {
     Assert.Equal(new[] { 1, 0 },
                  HungarianAlgorithm.Run(new[] { Vector3.Zero, Vector3.UnitY }, new[] { Vector3.One, Vector3.Zero }));
 }