QA4QUBO/matrix.py
def generate_QUBO_problem(S):
    """
        Generate a QUBO problem (The number partitioning problem) from a vector S
    """
    n = len(S)
    c = 0
    for i in range(n):
        c += S[i]
    col_max = 0
    col = 0
    QUBO = np.zeros((n,n))
    #QUBO = [[0 for i in range(n)] for j in range(n)] #Old
    for row in range(n):
        col_max += 1
        while col < col_max:
            if row == col:
                QUBO[row][col] = S[row]*(S[row]-c)
            else:
                QUBO[row][col] = S[row] * S[col]
                QUBO[col][row] = QUBO[row][col]
            col += 1
        col = 0
    return QUBO, c

        Generate a QUBO problem (The number partitioning problem) from a vector S
    
Generate a QUBO problem (The number partitioning problem) from a vector S
Generate a QUBO problem ( The number partitioning problem ) from a vector S
def generate_QUBO_problem(S):
    n = len(S)
    c = 0
    for i in range(n):
        c += S[i]
    col_max = 0
    col = 0
    QUBO = np.zeros((n,n))
    for row in range(n):
        col_max += 1
        while col < col_max:
            if row == col:
                QUBO[row][col] = S[row]*(S[row]-c)
            else:
                QUBO[row][col] = S[row] * S[col]
                QUBO[col][row] = QUBO[row][col]
            col += 1
        col = 0
    return QUBO, c
def generate_QUBO_problem ( S ) : n = len ( S ) c = 0 for i in range ( n ) : c += S [ i ] col_max = 0 col = 0 QUBO = np . zeros ( ( n , n ) ) for row in range ( n ) : col_max += 1 while col < col_max : if row == col : QUBO [ row ] [ col ] = S [ row ] * ( S [ row ] - c ) else : QUBO [ row ] [ col ] = S [ row ] * S [ col ] QUBO [ col ] [ row ] = QUBO [ row ] [ col ] col += 1 col = 0 return QUBO , c
Generate a QUBO problem (The number partitioning problem) from a vector S
Generate a QUBO problem ( The number partitioning problem ) from a vector S
"""
        Generate a QUBO problem (The number partitioning problem) from a vector S
    """ #QUBO = [[0 for i in range(n)] for j in range(n)] #Old
S