Пример #1
0
 def test_rank_mtopsis_w_vector(self):
     """Test the rank function with the mTOPSIS, w, Vector methods."""
     x_matrix = [
         [0.9, 30.0, 500.0, 4.0],
         [0.1, 50.0, 5.0, 6.0],
         [0.5, 80.0, 8.0, 6.0],
         [0.8, 40.0, 100.0, 4.0],
         [0.7, 60.0, 20.0, 5.0],
         [0.6, 60.0, 10.0, 5.0],
     ]
     obtained_ranking = mcdm.rank(x_matrix,
                                  is_benefit_x=[True, False, False, True],
                                  n_method="Vector",
                                  w_vector=[0.3, 0.2, 0.4, 0.1],
                                  s_method="mTOPSIS")
     expected_ranking = [
         ("a5", 0.836287),
         ("a6", 0.814430),
         ("a4", 0.805387),
         ("a3", 0.745801),
         ("a2", 0.688769),
         ("a1", 0.341532),
     ]
     self.assertEqual(len(obtained_ranking), len(expected_ranking))
     for i, tmp in enumerate(obtained_ranking):
         self.assertEqual(tmp[0], expected_ranking[i][0])
         self.assertAlmostEqual(tmp[1], expected_ranking[i][1], places=6)
Пример #2
0
 def test_rank_saw_critic_dc_linear2(self):
     """Test the rank function with the SAW, CRITIC.DC, Linear2 methods."""
     x_matrix = [
         [0.9, 30.0, 500.0, 4.0],
         [0.1, 50.0, 5.0, 6.0],
         [0.5, 80.0, 8.0, 6.0],
         [0.8, 40.0, 100.0, 4.0],
         [0.7, 60.0, 20.0, 5.0],
         [0.6, 60.0, 10.0, 5.0],
     ]
     obtained_ranking = mcdm.rank(x_matrix,
                                  is_benefit_x=[True, False, False, True],
                                  n_method="Linear2",
                                  c_method="dCor",
                                  w_method="CRITIC",
                                  s_method="SAW")
     expected_ranking = [
         ("a2", 0.677366),
         ("a5", 0.675493),
         ("a3", 0.658395),
         ("a6", 0.652317),
         ("a4", 0.622630),
         ("a1", 0.456501),
     ]
     self.assertEqual(len(obtained_ranking), len(expected_ranking))
     for i, tmp in enumerate(obtained_ranking):
         self.assertEqual(tmp[0], expected_ranking[i][0])
         self.assertAlmostEqual(tmp[1], expected_ranking[i][1], places=6)
Пример #3
0
 def test_rank_saw_mw_linear1(self):
     """Test the rank function with the SAW, MW, Linear1 methods."""
     x_matrix = [
         [0.9, 30.0, 500.0, 4.0],
         [0.1, 50.0, 5.0, 6.0],
         [0.5, 80.0, 8.0, 6.0],
         [0.8, 40.0, 100.0, 4.0],
         [0.7, 60.0, 20.0, 5.0],
         [0.6, 60.0, 10.0, 5.0],
     ]
     obtained_ranking = mcdm.rank(x_matrix,
                                  is_benefit_x=[True, False, False, True],
                                  n_method="Linear1",
                                  w_method="MW",
                                  s_method="SAW")
     expected_ranking = [
         ("a2", 0.677778),
         ("a1", 0.669167),
         ("a3", 0.638889),
         ("a6", 0.625000),
         ("a5", 0.590278),
         ("a4", 0.588889),
     ]
     self.assertEqual(len(obtained_ranking), len(expected_ranking))
     for i, tmp in enumerate(obtained_ranking):
         self.assertEqual(tmp[0], expected_ranking[i][0])
         self.assertAlmostEqual(tmp[1], expected_ranking[i][1], places=6)
Пример #4
0
 def test_rank_saw_sd_linear1(self):
     """Test the rank function with the SAW, SD, Linear1 methods."""
     x_matrix = [
         [0.9, 30.0, 500.0, 4.0],
         [0.1, 50.0, 5.0, 6.0],
         [0.5, 80.0, 8.0, 6.0],
         [0.8, 40.0, 100.0, 4.0],
         [0.7, 60.0, 20.0, 5.0],
         [0.6, 60.0, 10.0, 5.0],
     ]
     obtained_ranking = mcdm.rank(x_matrix,
                                  is_benefit_x=[True, False, False, True],
                                  n_method="Linear1",
                                  w_method="SD",
                                  s_method="SAW")
     expected_ranking = [
         ("a2", 0.653952),
         ("a3", 0.604472),
         ("a1", 0.601574),
         ("a6", 0.595749),
         ("a5", 0.539665),
         ("a4", 0.530537),
     ]
     self.assertEqual(len(obtained_ranking), len(expected_ranking))
     for i, tmp in enumerate(obtained_ranking):
         self.assertEqual(tmp[0], expected_ranking[i][0])
         self.assertAlmostEqual(tmp[1], expected_ranking[i][1], places=6)
Пример #5
0
 def test_rank_saw_vic_ap_linear1(self):
     """Test the rank function with the SAW, VIC.AP, Linear1 methods."""
     x_matrix = [
         [0.9, 30.0, 500.0, 4.0],
         [0.1, 50.0, 5.0, 6.0],
         [0.5, 80.0, 8.0, 6.0],
         [0.8, 40.0, 100.0, 4.0],
         [0.7, 60.0, 20.0, 5.0],
         [0.6, 60.0, 10.0, 5.0],
     ]
     obtained_ranking = mcdm.rank(x_matrix,
                                  is_benefit_x=[True, False, False, True],
                                  n_method="Linear1",
                                  c_method="AbsPearson",
                                  w_method="VIC",
                                  s_method="SAW")
     expected_ranking = [
         ("a2", 0.644440),
         ("a1", 0.623018),
         ("a3", 0.593228),
         ("a6", 0.591963),
         ("a4", 0.543750),
         ("a5", 0.540097),
     ]
     self.assertEqual(len(obtained_ranking), len(expected_ranking))
     for i, tmp in enumerate(obtained_ranking):
         self.assertEqual(tmp[0], expected_ranking[i][0])
         self.assertAlmostEqual(tmp[1], expected_ranking[i][1], places=6)
Пример #6
0
 def test_rank_mtopsis_em_linear3(self):
     """Test the rank function with the mTOPSIS, EM, Linear3 methods."""
     x_matrix = [
         [0.9, 30.0, 500.0, 4.0],
         [0.1, 50.0, 5.0, 6.0],
         [0.5, 80.0, 8.0, 6.0],
         [0.8, 40.0, 100.0, 4.0],
         [0.7, 60.0, 20.0, 5.0],
         [0.6, 60.0, 10.0, 5.0],
     ]
     obtained_ranking = mcdm.rank(x_matrix,
                                  is_benefit_x=[True, False, False, True],
                                  n_method="Linear3",
                                  w_method="EM",
                                  s_method="mTOPSIS")
     expected_ranking = [
         ("a6", 0.955577),
         ("a5", 0.954078),
         ("a3", 0.938579),
         ("a2", 0.909531),
         ("a4", 0.808416),
         ("a1", 0.096521),
     ]
     self.assertEqual(len(obtained_ranking), len(expected_ranking))
     for i, tmp in enumerate(obtained_ranking):
         self.assertEqual(tmp[0], expected_ranking[i][0])
         self.assertAlmostEqual(tmp[1], expected_ranking[i][1], places=6)
Пример #7
0
 def test_rank_mew_vic_linear1(self):
     """Test the rank function with the MEW, VIC, Linear1 methods."""
     x_matrix = [
         [0.9, 30.0, 500.0, 4.0],
         [0.1, 50.0, 5.0, 6.0],
         [0.5, 80.0, 8.0, 6.0],
         [0.8, 40.0, 100.0, 4.0],
         [0.7, 60.0, 20.0, 5.0],
         [0.6, 60.0, 10.0, 5.0],
     ]
     obtained_ranking = mcdm.rank(x_matrix,
                                  is_benefit_x=[True, False, False, True],
                                  n_method="Linear1",
                                  w_method="VIC",
                                  s_method="MEW")
     expected_ranking = [
         ("a6", 0.583347),
         ("a3", 0.574199),
         ("a5", 0.480220),
         ("a2", 0.469420),
         ("a4", 0.304194),
         ("a1", 0.192606),
     ]
     self.assertEqual(len(obtained_ranking), len(expected_ranking))
     for i, tmp in enumerate(obtained_ranking):
         self.assertEqual(tmp[0], expected_ranking[i][0])
         self.assertAlmostEqual(tmp[1], expected_ranking[i][1], places=6)
Пример #8
0
 def test_default(self):
     """
     Test the integration with the default selections.
     """
     x_matrix, _alt_names = mcdm.load(
         os.path.join(DIR_PATH, "data", "example03.tsv"),
         delimiter="\t",
     )
     self.assertAlmostEqualRankings(mcdm.rank(x_matrix), get_ranking01())
Пример #9
0
 def test_default_float32(self):
     """
     Test the ranking of alternatives with the default selections and a
     float32 NumPy array.
     """
     self.assertAlmostEqualRankings(
         rank(np.array(get_matrix03(), dtype=np.float32)),
         get_ranking01(),
     )
Пример #10
0
 def test_mew(self):
     """
     Test the integration with the MEW scoring method.
     """
     x_matrix, _alt_names = mcdm.load(
         os.path.join(DIR_PATH, "data", "example03.tsv"),
         delimiter="\t",
     )
     self.assertAlmostEqualRankings(
         mcdm.rank(x_matrix, s_method="MEW"),
         get_ranking17(),
     )
 def weights(df):
     x_matrix = []
     alt_names = []
     for i in list(df.iloc[:, 3:].columns.unique()):
         alt_names.append(i)
         x_matrix.append(list(df.loc[:, i]))
         d = dict(
             mcdm.rank(x_matrix,
                       alt_names=alt_names,
                       w_method="CRITIC",
                       s_method="SAW"))
     return d
Пример #12
0
 def test_topsis_w(self):
     """
     Test the integration with the TOPSIS scoring method and predefined
     weights.
     """
     x_matrix, _alt_names = mcdm.load(
         os.path.join(DIR_PATH, "data", "example03.tsv"),
         delimiter="\t",
     )
     self.assertAlmostEqualRankings(
         mcdm.rank(x_matrix, w_vector=get_vector01(), s_method="TOPSIS"),
         get_ranking18(),
     )
Пример #13
0
 def test_default_w_asc_order(self):
     """
     Test the ranking of alternatives with the default selections,
     predefined weights, and cost criteria.
     """
     self.assertAlmostEqualRankings(
         rank(
             get_matrix03(),
             is_benefit_x=[False, False],
             w_vector=get_vector01(),
         ),
         get_ranking03(),
     )
Пример #14
0
 def test_integration_mew_vic(self):
     """Test integration with the MEW and VIC methods."""
     filepath = os.path.join(DIR_PATH, "data", "example09.tsv")
     x_matrix, alt_names = mcdm.load(
         filepath, delimiter="\t", skiprows=1, labeled_rows=True)
     obtained_ranking = mcdm.rank(
         x_matrix, alt_names=alt_names, w_method="VIC", s_method="MEW")
     expected_ranking = [
         ("COORD.PRoPHET", 0.475401),
         ("DF.PRoPHET",    0.472054),
         ("CnR.LTS",       0.380770),
         ("SimBetTS.L8",   0.380006),
         ("SimBetTS.L16",  0.379992),
         ("CnR.DestEnc",   0.379448),
         ("LSF-SnW.L16",   0.377400),
         ("DF.DestEnc",    0.373788),
         ("COORD.DestEnc", 0.373536),
         ("SimBetTS.L4",   0.372440),
         ("LSF-SnW.L8",    0.368945),
         ("DF.LTS",        0.366043),
         ("COORD.LTS",     0.365320),
         ("LSF-SnW.L4",    0.344986),
         ("CnF.PRoPHET",   0.344899),
         ("CnF.DestEnc",   0.340809),
         ("CnF.LTS",       0.336824),
         ("SnF.L8",        0.333813),
         ("SnF.L4",        0.331080),
         ("CnR.PRoPHET",   0.328371),
         ("SnF.L2",        0.328271),
         ("SnF.L16",       0.325965),
         ("SimBetTS.L2",   0.319820),
         ("LSF-SnW.L2",    0.283363),
         ("CnR.Enc",       0.253889),
         ("DF.Enc",        0.196428),
         ("COORD.Enc",     0.185271),
         ("Epidemic",      0.176182),
         ("Direct",        0.144637),
         ("EBR.L16",       0.144275),
         ("SnW.L16",       0.144196),
         ("EBR.L2",        0.139577),
         ("SnW.L2",        0.139347),
         ("SnW.L8",        0.137288),
         ("EBR.L8",        0.137283),
         ("EBR.L4",        0.136547),
         ("SnW.L4",        0.136425),
         ("CnF.Enc",       0.117134),
     ]
     self.assertEqual(len(obtained_ranking), len(expected_ranking))
     for i, tmp in enumerate(obtained_ranking):
         self.assertEqual(tmp[0], expected_ranking[i][0])
         self.assertAlmostEqual(tmp[1], expected_ranking[i][1], places=6)
Пример #15
0
 def test_mew_vic(self):
     """
     Test the ranking of alternatives with the MEW scoring method and the
     VIC weighting method.
     """
     self.assertAlmostEqualRankings(
         rank(
             get_matrix09(),
             alt_names=get_labels04(),
             is_benefit_x=[True, True, True],
             w_method="VIC",
             s_method="MEW",
         ),
         get_ranking16(),
     )
Пример #16
0
 def test_saw_critic(self):
     """
     Test the ranking of alternatives with the SAW scoring method and the
     CRITIC weighting method.
     """
     self.assertAlmostEqualRankings(
         rank(
             get_matrix09(),
             alt_names=get_labels04(),
             is_benefit_x=[True, True, True],
             w_method="CRITIC",
             s_method="SAW",
         ),
         get_ranking15(),
     )
Пример #17
0
 def test_mtopsis_w_vector(self):
     """
     Test the ranking of alternatives with the mTOPSIS scoring method,
     predefined weights, and the Vector normalization method.
     """
     self.assertAlmostEqualRankings(
         rank(
             get_matrix07(),
             is_benefit_x=[True, False, False, True],
             n_method="Vector",
             w_vector=get_vector02(),
             s_method="mTOPSIS",
         ),
         get_ranking14(),
     )
Пример #18
0
 def test_saw_critic_linear2(self):
     """
     Test the ranking of alternatives with the SAW scoring method, the
     CRITIC weighting method, and the Linear2 normalization method.
     """
     self.assertAlmostEqualRankings(
         rank(
             get_matrix07(),
             is_benefit_x=[True, False, False, True],
             n_method="Linear2",
             w_method="CRITIC",
             s_method="SAW",
         ),
         get_ranking09(),
     )
Пример #19
0
 def test_mew_vic_linear1(self):
     """
     Test the ranking of alternatives with the MEW scoring method, the VIC
     weighting method, and the Linear1 normalization method.
     """
     self.assertAlmostEqualRankings(
         rank(
             get_matrix07(),
             is_benefit_x=[True, False, False, True],
             n_method="Linear1",
             w_method="VIC",
             s_method="MEW",
         ),
         get_ranking08(),
     )
Пример #20
0
 def test_mtopsis_em_linear3(self):
     """
     Test the ranking of alternatives with the mTOPSIS scoring method, the
     EM weighting method, and the Linear3 normalization method.
     """
     self.assertAlmostEqualRankings(
         rank(
             get_matrix07(),
             is_benefit_x=[True, False, False, True],
             n_method="Linear3",
             w_method="EM",
             s_method="mTOPSIS",
         ),
         get_ranking12(),
     )
Пример #21
0
def getResults(excludeStudents=[]):

    list = []
    for student in GlobalData.students:

        if student['id'] in excludeStudents: continue

        list.append(
            mcdm.rank(x_matrix=Pointer.getCriteriaValues(),
                      alt_names=Pointer.getReferenceNameList(),
                      is_benefit_x=GlobalData.benefits,
                      n_method="Linear1",
                      w_vector=MCDM.normalizeWeightage(
                          student['preferences'])))

    return list
Пример #22
0
 def test_integration_mew(self):
     """Test integration with the MEW method."""
     filepath = os.path.join(DIR_PATH, "data", "example03.tsv")
     x_matrix, alt_names = mcdm.load(filepath, delimiter="\t")
     obtained_ranking = mcdm.rank(x_matrix, s_method="MEW")
     expected_ranking = [
         ("a3", 0.500000),
         ("a2", 0.433013),
         ("a4", 0.433013),
         ("a1", 0.000000),
         ("a5", 0.000000),
     ]
     self.assertEqual(len(obtained_ranking), len(expected_ranking))
     for i, tmp in enumerate(obtained_ranking):
         self.assertEqual(tmp[0], expected_ranking[i][0])
         self.assertAlmostEqual(tmp[1], expected_ranking[i][1], places=6)
Пример #23
0
 def test_saw_vic_abspearson_linear1(self):
     """
     Test the ranking of alternatives with the SAW scoring method, the
     VIC.AbsPearson weighting method, and the Linear1 normalization method.
     """
     self.assertAlmostEqualRankings(
         rank(
             get_matrix07(),
             is_benefit_x=[True, False, False, True],
             n_method="Linear1",
             c_method="AbsPearson",
             w_method="VIC",
             s_method="SAW",
         ),
         get_ranking07(),
     )
Пример #24
0
 def test_topsis_w_vector_float32(self):
     """
     Test the ranking of alternatives with the TOPSIS scoring method,
     predefined weights, the Vector normalization method, and float32 NumPy
     arrays.
     """
     self.assertAlmostEqualRankings(
         rank(
             np.array(get_matrix07(), dtype=np.float32),
             is_benefit_x=[True, False, False, True],
             n_method="Vector",
             w_vector=np.array(get_vector02(), dtype=np.float32),
             s_method="TOPSIS",
         ),
         get_ranking13(),
     )
Пример #25
0
 def test_topsis_is_benefit_x(self):
     """
     Test the integration with the TOPSIS scoring method and a mixture of
     benefit and cost criteria.
     """
     x_matrix, _alt_names = mcdm.load(
         os.path.join(DIR_PATH, "data", "example03.tsv"),
         delimiter="\t",
     )
     self.assertAlmostEqualRankings(
         mcdm.rank(
             x_matrix,
             is_benefit_x=[True, False],
             s_method="TOPSIS",
         ),
         get_ranking19(),
     )
Пример #26
0
 def test_rank_default_float32(self):
     """Test the rank function with a float32 NumPy array."""
     x_matrix = np.array([[0.00, 1.00], [0.25, 0.75], [0.50, 0.50],
                          [0.75, 0.25], [1.00, 0.00]],
                         dtype=np.float32)
     obtained_ranking = mcdm.rank(x_matrix)
     expected_ranking = [
         ("a1", 0.500000),
         ("a2", 0.500000),
         ("a3", 0.500000),
         ("a4", 0.500000),
         ("a5", 0.500000),
     ]
     self.assertEqual(len(obtained_ranking), len(expected_ranking))
     for i, tmp in enumerate(obtained_ranking):
         self.assertEqual(tmp[0], expected_ranking[i][0])
         self.assertAlmostEqual(tmp[1], expected_ranking[i][1], places=6)
Пример #27
0
 def test_integration_topsis_w(self):
     """Test integration with the TOPSIS and w_vector methods."""
     filepath = os.path.join(DIR_PATH, "data", "example03.tsv")
     x_matrix, alt_names = mcdm.load(filepath, delimiter="\t")
     obtained_ranking = mcdm.rank(
         x_matrix, w_vector=[0.7, 0.3], s_method="TOPSIS")
     expected_ranking = [
         ("a5", 0.700000),
         ("a4", 0.650413),
         ("a3", 0.500000),
         ("a2", 0.349587),
         ("a1", 0.300000),
     ]
     self.assertEqual(len(obtained_ranking), len(expected_ranking))
     for i, tmp in enumerate(obtained_ranking):
         self.assertEqual(tmp[0], expected_ranking[i][0])
         self.assertAlmostEqual(tmp[1], expected_ranking[i][1], places=6)
Пример #28
0
 def test_integration_topsis_is_benefit_x(self):
     """Test integration with the TOPSIS method and mixed criteria."""
     filepath = os.path.join(DIR_PATH, "data", "example03.tsv")
     x_matrix, alt_names = mcdm.load(filepath, delimiter="\t")
     obtained_ranking = mcdm.rank(
         x_matrix, is_benefit_x=[True, False], s_method="TOPSIS")
     expected_ranking = [
         ("a5", 1.000000),
         ("a4", 0.750000),
         ("a3", 0.500000),
         ("a2", 0.250000),
         ("a1", 0.000000),
     ]
     self.assertEqual(len(obtained_ranking), len(expected_ranking))
     for i, tmp in enumerate(obtained_ranking):
         self.assertEqual(tmp[0], expected_ranking[i][0])
         self.assertAlmostEqual(tmp[1], expected_ranking[i][1], places=6)
Пример #29
0
 def test_integration_mtopsis_em_linear3(self):
     """Test integration with the mTOPSIS, EM, Linear3 methods."""
     filepath = os.path.join(DIR_PATH, "data", "example08.tsv")
     x_matrix, alt_names = mcdm.load(
         filepath, delimiter="\t", labeled_rows=True)
     obtained_ranking = mcdm.rank(
         x_matrix, alt_names=alt_names, n_method="Linear3",
         w_method="EM", s_method="mTOPSIS")
     expected_ranking = [
         ("A", 0.567198),
         ("D", 0.473771),
         ("B", 0.440236),
         ("C", 0.439791),
     ]
     self.assertEqual(len(obtained_ranking), len(expected_ranking))
     for i, tmp in enumerate(obtained_ranking):
         self.assertEqual(tmp[0], expected_ranking[i][0])
         self.assertAlmostEqual(tmp[1], expected_ranking[i][1], places=6)
Пример #30
0
 def test_integration_mew_vic_linear1(self):
     """Test integration with the MEW, VIC, Linear1 methods."""
     filepath = os.path.join(DIR_PATH, "data", "example08.tsv")
     x_matrix, alt_names = mcdm.load(
         filepath, delimiter="\t", labeled_rows=True)
     obtained_ranking = mcdm.rank(
         x_matrix, alt_names=alt_names, n_method="Linear1",
         w_method="VIC", s_method="MEW")
     expected_ranking = [
         ("A", 0.596199),
         ("B", 0.592651),
         ("D", 0.581653),
         ("C", 0.507066),
     ]
     self.assertEqual(len(obtained_ranking), len(expected_ranking))
     for i, tmp in enumerate(obtained_ranking):
         self.assertEqual(tmp[0], expected_ranking[i][0])
         self.assertAlmostEqual(tmp[1], expected_ranking[i][1], places=6)