Fonnie
Fonnie

Reputation: 133

How do I convert a GEKKO returned integer back to a python recognizable integer?

The function intpolatn receives the integer variable u_hub_next from a GEKKO maximized objective function. intpolatn is just meant to check if the integer falls between windvel[0] and windvel[1] and succeeding elif statements, and then return the appropriate list, depending on which elif condition satisfies the value of u_hub_next. However, GEKKO keeps throwing the error TypeError: object of type 'int' has no len() at the if conditional, and hence the code cannot proceed to the remainder of the python code. A snippet of the code is given below without succeeding elif statements and without the gekko section: I'd appreciate any guidance.

def intpolatn(u_hub_next):
    windvel = np.array([0, 3, 4, 6, 7, 14])
    thrust_coeff = np.array([0, 0.9, 0.9, 0.7, 0.83, 0.39])
    # print(u_hub_next)
    if windvel[0] <= u_hub_next < windvel[1]:
        m = 0
        c_t = 0
        axial = 0
        p_u = check_p_u(u_hub_next) 
        u_hub_next = 0
        return [u_hub_next, c_t, axial, p_u]

Upvotes: 3

Views: 559

Answers (1)

John Hedengren
John Hedengren

Reputation: 14346

Extract the value of u_hub_next with:

uhn = u_hub_next.value[0]

The value is a float type so use int(uhn) to convert it to an integer type or one of the Numpy integer types for even more control.

Upvotes: 1

Related Questions