示例#1
0
    def mean_cooperation(self):
        expr = self.__get_replicator_rhs()
        if expr == 0:
            return 0.0
        p = Poly(expr, domain='RR')
        roots = sorted([float(r) for r in p.nroots(n=15, maxsteps=300) if r.is_real and r >= 0.00 and r <= 1.00])
        roots = [0.0] + roots + [1.0]

        coop = 0
        p = Poly(x * (1 - x) * expr, domain='RR')
        for i in range(1, len(roots)):
            difference = roots[i] - roots[i - 1]
            poly_val = p.subs(x, roots[i - i] + difference / 2)
            coop += roots[i - 1] * difference if poly_val < 0 else roots[i] * difference
        return coop