'Optimization and objective function using Scipy

I am trying to optimize an objective function using scipy. I simplified what I would like to do to focus on the problem more. There is an array called operating, which is an independent variable to optimize the output( indeed it is the array makes the objective function optimized). operating could be 0 , 1, or 0.5, and each of these values can affect another variable called TI, so TI = f(operating) , and this TI also changes the objective function.

objective = function - penalty 
penalty= f(TI)

So changing the operating leads to changing the TI and, consequently, the objective function. I have also used the following lines to optimize using scipy :

x0 = np.full((wt),0.6)
bounds=np.full((wt,2),(0,1)).reshape(-1, 2)             
res= minimize(wt_simulation, x0=x0, bounds=bounds,method='powell',options={'maxiter': 1e4, 'disp': True})

The problem is that x0 (=operating) must be a mix of 0.5,1 and 0 in the defined range to consider all three values in operating, and then these values will be changed in each optimization to get the best deal for the objective. I tried different methods, and I think the only option to use in such optimization is the Powell method, but the fact is that the final result is incorrect, and I got the wrong values. So I think there is a mistake by me in the optimization's options or something like this. If I have only two values in operating, optimization works correctly. so how can solve his problem to optimize the function by considering those three values in operation? for instance, even in x0 I change 0,6 to another value again I could get different results, so which value should be correct?

x0 = np.full((wt),0.6)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source