Esempio n. 1
0
    def test_primal_poa(self):
        c, G, h, A, b = CongestionPoA.primal_poa(*self.args1)
        sol = lp('cvxopt', c, G, h, A, b)
        self.assertEqual(round(-1. / sol['min'], 4), .5)

        c, G, h, A, b = CongestionPoA.primal_poa(*self.args2)
        sol2 = lp('cvxopt', c, G, h, A, b)
        self.assertEqual(round(-1. / sol2['min'], 4), .6329)
Esempio n. 2
0
 def test_worst_case(self):
     n = self.args3[0]
     c, G, h, A, b = CongestionPoA.primal_poa(*self.args3)
     theta = lp('cvxopt', c, G, h, A, b)['argmin']
     CongestionPoA.TOL = 4
     actions, values = CongestionPoA.worst_case(theta, n)
     self.assertEqual(actions, [[(0, ), (1, 2)], [(1, ), (0, 3)]])
     self.assertEqual(values, [0.5, 0.5, 0.5, 0.5])
Esempio n. 3
0
    def test_poa(self):
        w = [0., 1, 1, 1]
        f = [0., 1, 0, 0]

        optf = [0., 1., .43, .29]
        c, G, h = ResourcePoA.function_poa(w)
        rpoaf = [0.] + lp('cvxopt', c, G, h)['argmin'][1:]
        rpoaf = [round(e, 2) for e in rpoaf]
        self.assertEqual(rpoaf, optf)

        c, G, h = ResourcePoA.dual_poa(f, w)
        d_poa = 1. / lp('cvxopt', c, G, h)['min']
        self.assertEqual(round(d_poa, 3), .5)

        c, G, h, A, b = ResourcePoA.primal_poa(f, w)
        p_poa = -1. / lp('cvxopt', c, G, h, A, b)['min']
        self.assertEqual(round(p_poa, 3), .5)
Esempio n. 4
0
 def test_worst_case(self):
     w = [0., 1, 1]
     f = [0., 1, 0]
     c, G, h, A, b = ResourcePoA.primal_poa(f, w)
     theta = lp('cvxopt', c, G, h, A, b)['argmin']
     ResourcePoA.TOL = 5
     actions, values = ResourcePoA.worst_case(theta, 2)
     self.assertEqual(actions, [[(2, ), (1, 3)], [(3, ), (0, 2)]])
     self.assertEqual(values, [0.5, 0.5, 0.5, 0.5])
Esempio n. 5
0
def cong_worst_game(n, w, flist, solver):
	theta = lp(solver, CongestionPoA.primal_poa(n, w, flist))['argmin']
	actions, values = CongestionPoA.worst_case(theta, n)
	#### TODO ###
Esempio n. 6
0
def cong_poa(n, w, flist, solver):
	return -1./lp(solver, CongestionPoA.primal_poa(n, w, flist))['min']
Esempio n. 7
0
def worst_game(f, w, solver):
	theta = lp(solver, ResourcePoA.primal_poa(f, w))['argmin']
	N = len(f)
	actions, values = ResourcePoA.worst_case(theta, N)
	return welfare_resource_game(actions, values, w, f)
Esempio n. 8
0
def res_opt_f(w, solver):
	sol = lp(solver, ResourcePoA.function_poa(w))
	f = [0.] + sol['argmin'][1:]
	poa = 1./sol['min']
	return poa, f
Esempio n. 9
0
def res_poa(f, w, solver):
	return 1./lp(solver, ResourcePoA.dual_poa(f, w))['min']