QA4QUBO/matrix.py
def qubo_qap(flow: np.ndarray, distance: np.ndarray, penalty):
    """Quadratic Assignment Problem (QAP)"""
    n = len(flow)
    q = np.einsum("ij,kl->ikjl", flow, distance).astype(np.float)

    i = range(len(q))

    q[i, :, i, :] += penalty
    q[:, i, :, i] += penalty
    q[i, i, i, i] -= 4 * penalty
    return q.reshape(n ** 2, n ** 2)
Quadratic Assignment Problem (QAP)
Quadratic Assignment Problem (QAP)
Quadratic Assignment Problem ( QAP )
def qubo_qap(flow: np.ndarray, distance: np.ndarray, penalty):
    n = len(flow)
    q = np.einsum("ij,kl->ikjl", flow, distance).astype(np.float)
    i = range(len(q))
    q[i, :, i, :] += penalty
    q[:, i, :, i] += penalty
    q[i, i, i, i] -= 4 * penalty
    return q.reshape(n ** 2, n ** 2)
def qubo_qap ( flow : np . ndarray , distance : np . ndarray , penalty ) : n = len ( flow ) q = np . einsum ( "ij,kl->ikjl" , flow , distance ) . astype ( np . float ) i = range ( len ( q ) ) q [ i , : , i , : ] += penalty q [ : , i , : , i ] += penalty q [ i , i , i , i ] -= 4 * penalty return q . reshape ( n ** 2 , n ** 2 )
Quadratic Assignment Problem (QAP)
Quadratic Assignment Problem ( QAP )
"""Quadratic Assignment Problem (QAP)"""
flow
np.ndarray
distance
np.ndarray
penalty