'Methods of Optimization in scipy

I am trying to optimize a function using Scipy in the following way:

    def wt_simulation(x,wt,wd,ws,l,k):

    if x<=0.3:
       condition 1

    if x>0.3 & x<0.7:
       condition 2
    else:
      condition 3

        x0 = np.full((wt),0.5)
        bounds=np.full((wt,2),(0,1)).reshape(-1, 2)             
        res= minimize(wt_simulation, x0=x0, bounds=bounds,method='powell',args=(wt,wd,ws,wd[l],ws[k]))

as you can see I have defined a bound for x in which it must be in range( 0,1); depending on the x values, there are three conditions in the objective function (wt_simulation). so in each iteration x values must be a mix of different values in the range (0,1) to optimize the function with respect to these 3 conditions. I tried to do this with different methods in Scipy, but none of them can handle it; it means, x starts from 0.5 but after optimization, I only got optimized values for x around 0.5 ( I have also tried different values like 0.4,.. and nothing changed), while there must be some values, for instance, lower than <=0.3 (condition 1) so it optimized the function regardless of 3 conditions. and I wanna know that how can I handle the problem? the only method that I think can handle this problem is Powell method but I do not know how can I use it since it needs direction.



Sources

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

Source: Stack Overflow

Solution Source