def _f(self, x, user_data=None):
        """ Evaluates the objective function.
        """
        p_gen = x[self._Pg.i1:self._Pg.iN + 1] # Active generation in p.u.
        q_gen = x[self._Qg.i1:self._Qg.iN + 1] # Reactive generation in p.u.

        # Polynomial cost of P and Q.
        xx = r_[p_gen, q_gen] * self._base_mva
        if len(self._ipol) > 0:
            f = sum([g.total_cost(xx[i]) for i,g in enumerate(self._gn)])
        else:
            f = 0

        # Piecewise linear cost of P and Q.
        if self._ny:
            y = self.om.get_var("y")
            self._ccost = csr_matrix((ones(self._ny),
                (range(y.i1, y.iN + 1), zeros(self._ny))),
                shape=(self._nxyz, 1)).T
            f = f + self._ccost * x
        else:
            self._ccost = zeros((1, self._nxyz))
        # TODO: Generalised cost term.

        return f
def _f ( self , x , user_data = None ) : p_gen = x [ self . _Pg . i1 : self . _Pg . iN + 1 ] q_gen = x [ self . _Qg . i1 : self . _Qg . iN + 1 ] xx = r_ [ p_gen , q_gen ] * self . _base_mva if len ( self . _ipol ) > 0 : f = sum ( [ g . total_cost ( xx [ i ] ) for i , g in enumerate ( self . _gn ) ] ) else : f = 0 if self . _ny : y = self . om . get_var ( "y" ) self . _ccost = csr_matrix ( ( ones ( self . _ny ) , ( range ( y . i1 , y . iN + 1 ) , zeros ( self . _ny ) ) ) , shape = ( self . _nxyz , 1 ) ) . T f = f + self . _ccost * x else : self . _ccost = zeros ( ( 1 , self . _nxyz ) ) return f
Evaluates the objective function.