#!/usr/bin/env python # coding: utf-8 # # Using LHS Value to Debug An Infeasible Problem # # This notebook aims to show how to use the left-hand side (LHS) value (`Constraint.e`) to debug an infeasible problem. # # The LHS value is the value of the left-hand side of the equation. It is useful to check which constraints are violated. # In[1]: import ams # In[2]: ams.config_logger(stream_level=20) # First, let's solve a DCOPF. # In[3]: sp = ams.load(ams.get_case('matpower/case14.m'), no_output=True) # In[4]: sp.DCOPF.run(solver='CLARABEL') # In[5]: sp.DCOPF.pg.v.round(2) # Then, we can lower down the generator maximum output to create an infeasible problem. # In[6]: sp.StaticGen.set(src='pmax', attr='v', idx=[1, 2, 3, 4, 5], value=0.5) # Remember to update the corresponding parameters in the routine. # In[7]: sp.DCOPF.update('pmax') # Now, we can see that the problem is infeasible. # In[8]: sp.DCOPF.run(solver='CLARABEL') # Then, we can turn off some constraints and sovle it again. # In[9]: sp.DCOPF.disable(['pglb', 'pgub']) # Note that since there are some constraints touched, the OModel will be updated automatically. # In[10]: sp.DCOPF.run(solver='CLARABEL') # In[11]: sp.DCOPF.pg.v # Since all the inequality constraints are written in the form of $Ax -b \leq 0$, we can check the violated constraints by finding the those with positive `Constraint.e`. # In[12]: sp.DCOPF.pgub.e # In[13]: sp.DCOPF.pglb.e