So, I tried using scipy.optimize.minimize to find the optimal parameter (stiffness and damping: kx1, cx1, kz1, cz1, kx23, cx23, kz23, cz23) that could equate to a certain value (max tension: T_max_1 & T_max_23).

Generally, the problem could be written like this:

stiffness & damping on moor 1

T1x = kx1 * (x + x2_1) + cx1 * (dx + dx2_1)   
T1z = kz1 * (z - z2_1) + cz1 * (dz + dz2_1)
T_check1  = np.sqrt(T1x**2 + T1z**2)

T_diff1 = T_check1 - T_max_1    # Difference between T_check and T_max_1

where:

x2_1 = r*(1 - np.cos(np.radians(rty)))
z2_1 = r*np.sin(np.radians(rty))
    
dx2_1 = r*np.sin(np.radians(rty))*np.radians(drty)
dz2_1 = r*np.cos(np.radians(rty))*np.radians(drty)*(-1)

similiarly, this part is for stiffness and damping on moor 2 (in which the value is equal to the one that would be applied to moor 3)

stiffness & damping on moor 2 & 3

T23x = kx23 * (x - x2_23) + cx23 * (dx + dx2_23)
T23z = kz23 * (z + z2_23) + cz23 * (dz + dz2_23)
T_check23  = np.sqrt(T23x**2 + T23z**2)

T_diff23 = T_check23 - T_max_23    # Difference between T_check and T_max_23

where:

x2_23 = r23*(1 - np.cos(np.radians(rty)))
z2_23 = r23*np.sin(np.radians(rty))
    
dx2_23 = r23*np.sin(np.radians(rty))*np.radians(drty)
dz2_23 = r23*np.cos(np.radians(rty))*np.radians(drty)*(-1)

Then, the value that I want to optimize.minimize is

T_diff1**2 + T_diff23**2

and I expect that the scipy.optimize.minimize().x would be kx1, cx1, kz1, cz1, kx23, cx23, kz23, cz23.

The value of T_max_1, T_max_23, r, and r23 are defined earlier in the code. But, the value of x, z, rty, dx, dz, and drty are the maximum values of certain parameters of a differential equation solution which uses kx1, cx1, kz1, cz1, kx23, cx23, kz23, cz23 as a part of the equation.

The bounds for kx1, cx1, kz1, cz1, kx23, cx23, kz23, cz23 are

bound_moor  = (0.0, np.inf)
bnds = (bound_moor, bound_moor, bound_moor, bound_moor, \
        bound_moor, bound_moor, bound_moor, bound_moor)

and I want to put a constraint that states -6 < x < 6 , but x is dependent on kx1, cx1, kz1, cz1, kx23, cx23, kz23, cz23.

I tried putting the differential equation and the optimization problem in one function but only return the T_diff1**2 + T_diff23**2 , then defining the constraint for x like this:

def constraint1(variables):
    x, _, _, _, _, _, _, _ = variables  # Extract x from variables

    return x + 6  # Ensure x is greater than -6

def constraint2(variables):
    x, _, _, _, _, _, _, _ = variables  # Extract x from variables

    return 6 - x  # Ensure x is less than 6

and i also put constraints that state kx1 > kx23, cx1 > cx23, kz1 > kz23, and cz1 > cz23. I need to do this for a set of different cases so I tried putting the optimization inside the for loop and it does not finish running.

Another time I tried to return x from the function alongside T_diff1**2 + T_diff23**2 and set the objective function to:

def objective_function(params):
    return differential_equation(params)[0]

and the x constraint is:

constr_xup   = {'type': 'ineq', 'fun': lambda params: 6 - differential_equation(params)[1]}
constr_xdown = {'type': 'ineq', 'fun': lambda params: differential_equation(params)[1] + 6}

but, it also does not end.

Some searches lead me to terms like 'constraints on intermediate variables' and 'dynamic optimization'. But, is it possible to do this with scipy.optimize.minimize or do I need something else?

0

There are 0 best solutions below