How to use the nashpy.integer_pivoting.pivot_tableau function in nashpy

To help you get started, we’ve selected a few nashpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github drvinceknight / Nashpy / src / nashpy / algorithms / lemke_howson.py View on Github external
if np.min(B) <= 0:
        B = B + abs(np.min(B)) + 1

    # build tableaux
    col_tableau = make_tableau(A)
    col_tableau = shift_tableau(col_tableau, A.shape)
    row_tableau = make_tableau(B.transpose())
    full_labels = set(range(sum(A.shape)))

    if initial_dropped_label in non_basic_variables(row_tableau):
        tableux = cycle((row_tableau, col_tableau))
    else:
        tableux = cycle((col_tableau, row_tableau))

    # First pivot (to drop a label)
    entering_label = pivot_tableau(next(tableux), initial_dropped_label)
    while non_basic_variables(row_tableau).union(non_basic_variables(col_tableau)) != full_labels:
        entering_label = pivot_tableau(next(tableux), next(iter(entering_label)))

    row_strategy = tableau_to_strategy(row_tableau, non_basic_variables(col_tableau),
                                       range(A.shape[0]))
    col_strategy = tableau_to_strategy(col_tableau, non_basic_variables(row_tableau),
                                       range(A.shape[0], sum(A.shape)))

    if row_strategy.shape != (A.shape[0],) and col_strategy.shape != (A.shape[0],):
        msg = """The Lemke Howson algorithm has returned probability vectors of 
incorrect shapes. This indicates an error. Your game could be degenerate."""

        warnings.warn(msg, RuntimeWarning)
    return row_strategy, col_strategy
github drvinceknight / Nashpy / src / nashpy / algorithms / lemke_howson.py View on Github external
# build tableaux
    col_tableau = make_tableau(A)
    col_tableau = shift_tableau(col_tableau, A.shape)
    row_tableau = make_tableau(B.transpose())
    full_labels = set(range(sum(A.shape)))

    if initial_dropped_label in non_basic_variables(row_tableau):
        tableux = cycle((row_tableau, col_tableau))
    else:
        tableux = cycle((col_tableau, row_tableau))

    # First pivot (to drop a label)
    entering_label = pivot_tableau(next(tableux), initial_dropped_label)
    while non_basic_variables(row_tableau).union(non_basic_variables(col_tableau)) != full_labels:
        entering_label = pivot_tableau(next(tableux), next(iter(entering_label)))

    row_strategy = tableau_to_strategy(row_tableau, non_basic_variables(col_tableau),
                                       range(A.shape[0]))
    col_strategy = tableau_to_strategy(col_tableau, non_basic_variables(row_tableau),
                                       range(A.shape[0], sum(A.shape)))

    if row_strategy.shape != (A.shape[0],) and col_strategy.shape != (A.shape[0],):
        msg = """The Lemke Howson algorithm has returned probability vectors of 
incorrect shapes. This indicates an error. Your game could be degenerate."""

        warnings.warn(msg, RuntimeWarning)
    return row_strategy, col_strategy