Пример #1
0
    def equi(self):
        #random.seed(datetime.datetime.now())
        sys = SOE(g = self.g, a = self.a, t = self.t, c_k = self.c_k, c_l = self.c_l,\
                  a_k = self.a_k, a_l = self.a_l, PE = self.PE)
        a = Agent(g = self.g, a = self.a, t = self.t, c_k = self.c_k, c_l = self.c_l,\
                  a_k = self.a_k, a_l = self.a_l, PE = self.PE)
        x = fsolve(sys.KL_PE, ((random.uniform(1, 5), ) * 2), xtol=1.49012e-10)
        while x[0] <= 1e-2 or x[1] <= 1e-2:
            x = fsolve(sys.KL_PE, ((random.uniform(1, 5), ) * 2),
                       xtol=1.49012e-10)
        y = np.array([])
        for b in range(2):
            y = np.append(y, x[b]**2)
        ans = [0, 0, 0]
        ans[1] = y[0]
        ans[2] = y[1]
        ans[0] = a.Prod(ans)

        for i in range(100):
            random.seed(datetime.datetime.now())
            x = fsolve(sys.KL_PE, ((random.uniform(1, 5), ) * 2),
                       xtol=1.49012e-10)
            while x[0] < 1e-2 or x[1] < 1e-2:
                random.seed(datetime.datetime.now())
                x = fsolve(sys.KL_PE, ((random.uniform(1, 5), ) * 2),
                           xtol=1.49012e-10)
            y = np.array([])
            for b in range(2):
                y = np.append(y, x[b]**2)
            comp = [0, 0, 0]
            comp[1] = y[0]
            comp[2] = y[1]
            comp[0] = a.Prod(comp)
            print comp
            if a.Util(ans) < a.Util(comp):
                ans = comp
        print ans
        print a.Util(ans)
Пример #2
0
    def Comp(self):
        random.seed(datetime.datetime.now())
        sys = SOE(g = self.g, a = self.a, t = self.t, c_k = self.c_k, c_l = self.c_l,\
                  a_k = self.a_k, a_l = self.a_l, PE = self.PE)
        a = Agent(g = self.g, a = self.a, t = self.t, c_k = self.c_k, c_l = self.c_l,\
                  a_k = self.a_k, a_l = self.a_l, PE = self.PE)
        #fin the solution for the social planner

        x = fsolve(sys.KL, ((random.uniform(1, 5), ) * 2),
                   xtol=1.49012e-10,
                   maxfev=10000)
        while x[0] <= 1e-2 or x[1] <= 1e-2:
            x = fsolve(sys.KL, ((random.uniform(1, 5), ) * 2),
                       xtol=1.49012e-10,
                       maxfev=10000)
        y = np.array([])
        for b in range(2):
            y = np.append(y, x[b]**2)
        ans = [0, 0, 0]
        ans[1] = y[0]
        ans[2] = y[1]
        ans[0] = a.Prod(ans)

        for i in range(1000):
            random.seed(datetime.datetime.now())
            x = fsolve(sys.KL, ((random.uniform(1, 5), ) * 2),
                       xtol=1.49012e-10,
                       maxfev=10000)
            while x[0] <= 1e-2 or x[1] <= 1e-2:
                random.seed(datetime.datetime.now())
                x = fsolve(sys.KL, ((random.uniform(1, 5), ) * 2),
                           xtol=1.49012e-10,
                           maxfev=10000)
            y = np.array([])
            for b in range(2):
                y = np.append(y, x[b]**2)
            comp = [0, 0, 0]
            comp[1] = y[0]
            comp[2] = y[1]
            comp[0] = a.Prod(comp)
            #print a.Util(comp)
            if a.Util(ans) < a.Util(comp):
                ans = comp
        ans1 = ans
        u1 = a.Util(ans1)
        x = fsolve(sys.KL_PE, ((random.uniform(1, 5), ) * 2), xtol=1.49012e-10)
        while x[0] <= 1e-2 or x[1] <= 1e-2:
            x = fsolve(sys.KL_PE, ((random.uniform(1, 5), ) * 2),
                       xtol=1.49012e-10)
        y = np.array([])
        for b in range(2):
            y = np.append(y, x[b]**2)
        ans = [0, 0, 0]
        ans[1] = y[0]
        ans[2] = y[1]
        ans[0] = a.Prod(ans)

        for i in range(1000):
            random.seed(datetime.datetime.now())
            x = fsolve(sys.KL_PE, ((random.uniform(1, 5), ) * 2),
                       xtol=1.49012e-10)
            while x[0] < 1e-2 or x[1] < 1e-2:
                random.seed(datetime.datetime.now())
                x = fsolve(sys.KL_PE, ((random.uniform(1, 5), ) * 2),
                           xtol=1.49012e-10)
            y = np.array([])
            for b in range(2):
                y = np.append(y, x[b]**2)
            comp = [0, 0, 0]
            comp[1] = y[0]
            comp[2] = y[1]
            comp[0] = a.Prod(comp)
            #print a.Util(comp)
            if a.Util(ans) < a.Util(comp):
                ans = comp
        ans2 = ans
        u2 = a.Util(ans2)
        d = u2 - u1
        k1 = ans1[1]
        k2 = ans2[1]
        kd = k2 - k1
        print "Individual utility level: %6.4f" % u1
        print "Optimal utility level: %6.4f" % u2
        print "There is a %6.4f difference" % d
        print "Capital is underinvested by %6.4f" % kd