Пример #1
0
def lemke_optimizer(eco, payoff_matrix=None, dirac_mode=True):
    A = np.zeros((eco.populations.size, eco.populations.size * eco.layers))
    for k in range(eco.populations.size):
        A[k, k * eco.layers:(k + 1) * eco.layers] = -1

    q = np.zeros(eco.populations.size + eco.populations.size * eco.layers)
    q[eco.populations.size * eco.layers:] = -1
    q = q.reshape(-1, 1)
    if payoff_matrix is None:
        payoff_matrix = total_payoff_matrix_builder(eco)

    H = np.block([[-payoff_matrix, A.T],
                  [-A, np.zeros((A.shape[0], eco.populations.size))]])
    lcp = sn.LCP(H, q)
    ztol = 1e-8

    #solvers = [sn.SICONOS_LCP_PGS, sn.SICONOS_LCP_QP,
    #           sn.SICONOS_LCP_LEMKE, sn.SICONOS_LCP_ENUM]

    z = np.zeros((eco.layers * 2 + eco.populations.size, ), np.float64)
    w = np.zeros_like(z)
    options = sn.SolverOptions(sn.SICONOS_LCP_PIVOT)
    #sn.SICONOS_IPARAM_MAX_ITER = 10000000
    #options.iparam[sn.SICONOS_IPARAM_MAX_ITER] = 1000000
    options.dparam[sn.SICONOS_DPARAM_TOL] = 10**(-5)
    info = sn.linearComplementarity_driver(lcp, z, w, options)
    if sn.lcp_compute_error(lcp, z, w, ztol) > 10**(-5):
        print(sn.lcp_compute_error(lcp, z, w, ztol), "Error")
    #print(info, "Info")
    return z
Пример #2
0
def lcp_generic(id, z, w):

    options = sn.SolverOptions(id)
    info = sn.linearComplementarity_driver(lcp, z, w, options)
    print(' iter =', options.iparam[sn.SICONOS_IPARAM_ITER_DONE])
    print(' error=', options.dparam[sn.SICONOS_DPARAM_RESIDU])
    return info