@@ -387,33 +387,29 @@ def _constraint_function(self, coeffs):
387387 # Evaluate the constraint function along the trajectory
388388 value = []
389389 for i , t in enumerate (self .timepts ):
390- for type , fun , lb , ub in self .trajectory_constraints :
390+ for ctype , fun , lb , ub in self .trajectory_constraints :
391391 if np .all (lb == ub ):
392392 # Skip equality constraints
393393 continue
394- elif type == opt .LinearConstraint :
394+ elif ctype == opt .LinearConstraint :
395395 # `fun` is the A matrix associated with the polytope...
396- value .append (
397- np .dot (fun , np .hstack ([states [:, i ], inputs [:, i ]])))
398- elif type == opt .NonlinearConstraint :
396+ value .append (fun @ np .hstack ([states [:, i ], inputs [:, i ]]))
397+ elif ctype == opt .NonlinearConstraint :
399398 value .append (fun (states [:, i ], inputs [:, i ]))
400399 else :
401- raise TypeError ("unknown constraint type %s" %
402- constraint [0 ])
400+ raise TypeError (f"unknown constraint type { ctype } " )
403401
404402 # Evaluate the terminal constraint functions
405- for type , fun , lb , ub in self .terminal_constraints :
403+ for ctype , fun , lb , ub in self .terminal_constraints :
406404 if np .all (lb == ub ):
407405 # Skip equality constraints
408406 continue
409- elif type == opt .LinearConstraint :
410- value .append (
411- np .dot (fun , np .hstack ([states [:, i ], inputs [:, i ]])))
412- elif type == opt .NonlinearConstraint :
407+ elif ctype == opt .LinearConstraint :
408+ value .append (fun @ np .hstack ([states [:, i ], inputs [:, i ]]))
409+ elif ctype == opt .NonlinearConstraint :
413410 value .append (fun (states [:, i ], inputs [:, i ]))
414411 else :
415- raise TypeError ("unknown constraint type %s" %
416- constraint [0 ])
412+ raise TypeError (f"unknown constraint type { ctype } " )
417413
418414 # Update statistics
419415 self .constraint_evaluations += 1
@@ -475,33 +471,29 @@ def _eqconst_function(self, coeffs):
475471 # Evaluate the constraint function along the trajectory
476472 value = []
477473 for i , t in enumerate (self .timepts ):
478- for type , fun , lb , ub in self .trajectory_constraints :
474+ for ctype , fun , lb , ub in self .trajectory_constraints :
479475 if np .any (lb != ub ):
480476 # Skip inequality constraints
481477 continue
482- elif type == opt .LinearConstraint :
478+ elif ctype == opt .LinearConstraint :
483479 # `fun` is the A matrix associated with the polytope...
484- value .append (
485- np .dot (fun , np .hstack ([states [:, i ], inputs [:, i ]])))
486- elif type == opt .NonlinearConstraint :
480+ value .append (fun @ np .hstack ([states [:, i ], inputs [:, i ]]))
481+ elif ctype == opt .NonlinearConstraint :
487482 value .append (fun (states [:, i ], inputs [:, i ]))
488483 else :
489- raise TypeError ("unknown constraint type %s" %
490- constraint [0 ])
484+ raise TypeError (f"unknown constraint type { ctype } " )
491485
492486 # Evaluate the terminal constraint functions
493- for type , fun , lb , ub in self .terminal_constraints :
487+ for ctype , fun , lb , ub in self .terminal_constraints :
494488 if np .any (lb != ub ):
495489 # Skip inequality constraints
496490 continue
497- elif type == opt .LinearConstraint :
498- value .append (
499- np .dot (fun , np .hstack ([states [:, i ], inputs [:, i ]])))
500- elif type == opt .NonlinearConstraint :
491+ elif ctype == opt .LinearConstraint :
492+ value .append (fun @ np .hstack ([states [:, i ], inputs [:, i ]]))
493+ elif ctype == opt .NonlinearConstraint :
501494 value .append (fun (states [:, i ], inputs [:, i ]))
502495 else :
503- raise TypeError ("unknown constraint type %s" %
504- constraint [0 ])
496+ raise TypeError ("unknown constraint type {ctype}" )
505497
506498 # Update statistics
507499 self .eqconst_evaluations += 1
0 commit comments