rwl / PYPOWER

Port of MATPOWER to Python
http://rwl.github.io/PYPOWER/api/
Other
329 stars 110 forks source link

Update polycost.py to prevent failure for purely piecewise linear cases #60

Closed SNPerkin closed 2 years ago

SNPerkin commented 3 years ago

This function is called by multiple sub-functions of runopf(). When a case is defined with only piecewise linear gencost functions (i.e. no polynomial cost functions) the 'polycost' function fails. The gencost usually passed into this function is often "polycost(gencost[ipol, :], xx[ipol], 1)" as in opf_costfcn.py:105, which in this edge case means gencost is an empty array. The empty gencost array doesn't trigger the if statement on line 35, and then causes line 35 to fail, as taking the max of an empty array throws an error.

The proposed change causes this function to return an empty array immediately if gencost is empty (i.e. if all cost functions are peicewise linear) to ensure that the OPF can continue without error. The change has been tested locally and produces the expected result (runopf() solves for a case of only piecewise linear costcurves).