Skip to content
Advertisement

Problem in linear constraints of scipy. All the elements of population is getting rejected

I am using scipy differential evolution. I have to set the following linear constraints. 0<x1+x2+x3+x4<=1. x2+x3=1. I have set the following matrix A=[0 1 1 0] B=[1]. linear_constraint = LinearConstraint(A,B,B,True). i have also set lower and upper bound to 0 and1. However, during each iteration, the output of the objective function is InF, whereas the differential evolution is not calling the objective function

Can anyone suggest what is wrong? My Scipy version is 1.5.4 and python 3.7.

Thanks in advances..

Advertisement

Answer

You need to set up the constraints as:

from scipy.optimize import LinearConstraint

A = np.array([[1.0, 1.0, 1.0, 1.0],
              [0.0, 1.0, 1.0, 0.0]])

lc = LinearConstraint(A, [0, 1], [1, 1])

The keep_feasible keyword will be ignored. For the constraints to be feasible the bounds on each of the parameters have to encompass a feasible region. For example if x2 and x3 are positive then one of x1 or x4 has to be able to access negative values.

In a constrained minimization the objective function is only evaluated if the trial solution is not feasible.

A trial solution is accepted if:

    Trial is accepted if:
    * it satisfies all constraints and provides a lower or equal objective
      function value, while both the compared solutions are feasible
    - or -
    * it is feasible while the original solution is infeasible,
    - or -
    * it is infeasible, but provides a lower or equal constraint violation
      for all constraint functions.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement