def solve(self):
        """ Solves AC optimal power flow.
        """
        case = self.om.case
        self._base_mva = case.base_mva
        # TODO: Find an explanation for this value.
        self.opt["cost_mult"] = 1e-4

        # Unpack the OPF model.
        self._bs, self._ln, self._gn, _ = self._unpack_model(self.om)
        # Compute problem dimensions.
        self._ipol, _, self._nb, self._nl, _, self._ny, self._nxyz = \
            self._dimension_data(self._bs, self._ln, self._gn)

        # Compute problem dimensions.
        self._ng = len(self._gn)
#        gpol = [g for g in gn if g.pcost_model == POLYNOMIAL]

        # Linear constraints (l <= A*x <= u).
        A, l, u = self.om.linear_constraints()
#        AA, bb = self._linear_constraints(self.om)

        _, xmin, xmax = self._var_bounds()

        # Select an interior initial point for interior point solver.
        x0 = self._initial_interior_point(self._bs, self._gn, xmin, xmax, self._ny)

        # Build admittance matrices.
        self._Ybus, self._Yf, self._Yt = case.Y

        # Optimisation variables.

        self._Pg = self.om.get_var("Pg")
        self._Qg = self.om.get_var("Qg")
        self._Va = self.om.get_var("Va")
        self._Vm = self.om.get_var("Vm")

        # Adds a constraint on the reference bus angles.
#        xmin, xmax = self._ref_bus_angle_constraint(bs, Va, xmin, xmax)

        # Solve using Python Interior Point Solver (PIPS).
        s = self._solve(x0, A, l, u, xmin, xmax)

        Vang, Vmag, Pgen, Qgen = self._update_solution_data(s)

        self._update_case(self._bs, self._ln, self._gn, self._base_mva,
            self._Yf, self._Yt, Vang, Vmag, Pgen, Qgen, s["lmbda"])

        return s
def solve ( self ) : case = self . om . case self . _base_mva = case . base_mva self . opt [ "cost_mult" ] = 1e-4 self . _bs , self . _ln , self . _gn , _ = self . _unpack_model ( self . om ) self . _ipol , _ , self . _nb , self . _nl , _ , self . _ny , self . _nxyz = self . _dimension_data ( self . _bs , self . _ln , self . _gn ) self . _ng = len ( self . _gn ) A , l , u = self . om . linear_constraints ( ) _ , xmin , xmax = self . _var_bounds ( ) x0 = self . _initial_interior_point ( self . _bs , self . _gn , xmin , xmax , self . _ny ) self . _Ybus , self . _Yf , self . _Yt = case . Y self . _Pg = self . om . get_var ( "Pg" ) self . _Qg = self . om . get_var ( "Qg" ) self . _Va = self . om . get_var ( "Va" ) self . _Vm = self . om . get_var ( "Vm" ) s = self . _solve ( x0 , A , l , u , xmin , xmax ) Vang , Vmag , Pgen , Qgen = self . _update_solution_data ( s ) self . _update_case ( self . _bs , self . _ln , self . _gn , self . _base_mva , self . _Yf , self . _Yt , Vang , Vmag , Pgen , Qgen , s [ "lmbda" ] ) return s
Solves AC optimal power flow.