コード例 #1
0
ファイル: test_ahp.py プロジェクト: leliel12/scikit-criteria
    def test_ahp(self):
        rank = [1, 3, 2]
        points = [0.4177, 0.2660, 0.3164]

        crit_vs_crit = ahp.t([
            [1.], [1./3., 1.], [1./3., 1./2., 1.]
        ])
        alt_vs_alt_by_crit = [
            ahp.t([[1.], [1./5., 1.], [1./3., 3., 1.]]),
            ahp.t([[1.], [9., 1.], [3., 1./5., 1.]]),
            ahp.t([[1.], [1/2., 1.], [5., 7., 1.]]),
        ]

        result = ahp.ahp(crit_vs_crit, alt_vs_alt_by_crit)
        rank_result, points_result = result[:2]

        self.assertAllClose(points_result, points, atol=1.e-3)
        self.assertAllClose(rank_result, rank)

        rx = (
            "The number 'alt_vs_alt_by_crit' must be "
            "the number of criteria '{}'. Found"
        ).format(3, len(alt_vs_alt_by_crit))
        rx = rx.replace("(", r"\(").replace(")", r"\)").replace(".", r"\.")
        with self.assertRaisesRegexp(ValueError, rx):
            ahp.ahp(crit_vs_crit, alt_vs_alt_by_crit[1:])
コード例 #2
0
 def test_cr(self):
     ic = 0.02695218060897031
     cr = 0.051829169847109106
     crit_vs_crit = ahp.t([[1.], [1. / 3., 1.], [1. / 3., 1. / 2., 1.]])
     ic_result, cr_result = ahp.saaty_cr(crit_vs_crit)[:2]
     import ipdb
     ipdb.set_trace()
     self.assertAllClose(ic, ic_result, atol=1.e-3)
     self.assertAllClose(cr, cr_result, atol=1.e-3)
コード例 #3
0
    def test_t(self):
        tmtx = [[1], [1, 2, 3]]
        rx = ("The low triangular matrix for AHP must "
              "have the same number of columns and rows")
        with self.assertRaisesRegexp(ValueError, rx):
            ahp.t(tmtx)

        tmtx = [[1], [1., 1], [1 / 3.0, 1 / 6.0, 1]]
        mtx = ahp.t(tmtx)

        for ridx, row in enumerate(tmtx):
            for cidx, value in enumerate(row):
                if not np.isclose(mtx[ridx][cidx], value, atol=1.e-10):
                    self.fail("Incorect triangular matrix construct")

        mtxtype = random.choice(
            [ahp.MTX_TYPE_CRITERIA, ahp.MTX_TYPE_ALTERNATIVES])
        ahp.validate_ahp_matrix(3, mtx, mtxtype)
コード例 #4
0
ファイル: test_ahp.py プロジェクト: leliel12/scikit-criteria
 def test_cr(self):
     ic = 0.02695218060897031
     cr = 0.051829169847109106
     crit_vs_crit = ahp.t([
         [1.], [1./3., 1.], [1./3., 1./2., 1.]
     ])
     ic_result, cr_result = ahp.saaty_cr(crit_vs_crit)[:2]
     import ipdb; ipdb.set_trace()
     self.assertAllClose(ic, ic_result, atol=1.e-3)
     self.assertAllClose(cr, cr_result, atol=1.e-3)
コード例 #5
0
ファイル: test_ahp.py プロジェクト: leliel12/scikit-criteria
    def test_t(self):
        tmtx = [[1], [1, 2, 3]]
        rx = ("The low triangular matrix for AHP must "
              "have the same number of columns and rows")
        with self.assertRaisesRegexp(ValueError, rx):
            ahp.t(tmtx)

        tmtx = [[1],
                [1., 1],
                [1/3.0, 1/6.0, 1]]
        mtx = ahp.t(tmtx)

        for ridx, row in enumerate(tmtx):
            for cidx, value in enumerate(row):
                if not np.isclose(mtx[ridx][cidx], value, atol=1.e-10):
                    self.fail("Incorect triangular matrix construct")

        mtxtype = random.choice([ahp.MTX_TYPE_CRITERIA,
                                 ahp.MTX_TYPE_ALTERNATIVES])
        ahp.validate_ahp_matrix(3, mtx, mtxtype)
コード例 #6
0
    def test_ahp(self):
        rank = [1, 3, 2]
        points = [0.4177, 0.2660, 0.3164]

        crit_vs_crit = ahp.t([[1.], [1. / 3., 1.], [1. / 3., 1. / 2., 1.]])
        alt_vs_alt_by_crit = [
            ahp.t([[1.], [1. / 5., 1.], [1. / 3., 3., 1.]]),
            ahp.t([[1.], [9., 1.], [3., 1. / 5., 1.]]),
            ahp.t([[1.], [1 / 2., 1.], [5., 7., 1.]]),
        ]

        result = ahp.ahp(crit_vs_crit, alt_vs_alt_by_crit)
        rank_result, points_result = result[:2]

        self.assertAllClose(points_result, points, atol=1.e-3)
        self.assertAllClose(rank_result, rank)

        rx = ("The number 'alt_vs_alt_by_crit' must be "
              "the number of criteria '{}'. Found").format(
                  3, len(alt_vs_alt_by_crit))
        rx = rx.replace("(", r"\(").replace(")", r"\)").replace(".", r"\.")
        with self.assertRaisesRegexp(ValueError, rx):
            ahp.ahp(crit_vs_crit, alt_vs_alt_by_crit[1:])