Skip to content

pymoo/n-constr-keyword

Rule n-constr-keyword
Pack pymoo
Severity info
Fix safe, with xpd check --fix
Library versions pymoo 0.6 and later

Since pymoo 0.6.0, Problem has no n_constr parameter and reads it as the number of inequality constraints. Write n_ieq_constr or n_eq_constr.

class Welded(Problem):
def __init__(self):
super().__init__(n_var=4, n_obj=2, n_constr=4, xl=xl, xu=xu)
super().__init__(n_var=4, n_obj=2, n_ieq_constr=4, xl=xl, xu=xu)

The rule reports n_constr= given to super().__init__ in a problem class, or to Problem and ElementwiseProblem called by name. Problem has no such parameter since pymoo 0.6.0 and reads it from **kwargs as n_ieq_constr. A problem built with either keyword had the same n_ieq_constr, and GA with seed=1 returned the same X, F and G for both, bit for bit. A call that passes both keywords is left alone.

xpd check --fix applies the fix of this rule.

The safe fix writes n_ieq_constr=.

xpd prints this message with the issue. A name that starts with $ stands for code from your file.

n_constr is no longer a parameter of Problem since pymoo 0.6.0, which reads it from **kwargs as n_ieq_constr. Write n_ieq_constr for the constraints in out["G"], and n_eq_constr for those in out["H"].

Browse the other rules of the pymoo pack.