convexengineering / gpkit

Geometric programming for engineers
http://gpkit.readthedocs.org
MIT License
206 stars 40 forks source link

Returning Multiple Constraints #659

Closed codykarcher closed 8 years ago

codykarcher commented 8 years ago

I have something that looks like this:

class CDp_CL(ConstraintSet):
    def __init__(self, CDp, CL):
        super(CDp_CL,self).__init__([])
        self.CDp = CDp
        self.CL = CL

    def as_posyslt1(self):
        raise ValueError("This CD model is not allowed to solve as a GP.")

    def as_gpconstr(self, x0):

        if not x0:
            return (self.CDp >= 0.01)
        else:
            xfoilcd, xfoilcl, xfoilalpha, xfoilcm = XFOIL.single_cl(x0[self.CL.key])
        return (self.CDp >= xfoilcd)

But what if I want to return multiple constraints? I tried this, but it doesn't seem to want to converge... Note that if I put my GP compatible (no x0 case) constraints explicitly in to the GP, it solves fine:

class CDp_CL(ConstraintSet):
    def __init__(self, CDp, CDp0, M, CL):
        super(CDp_CL,self).__init__([])
        self.CDp = CDp
        self.CDp0 = CDp0
        self.CL = CL
        self.M = M

    def as_posyslt1(self):
        raise ValueError("This CD model is not allowed to solve as a GP.")

    def as_gpconstr(self, x0):

        if not x0:
            return (self.CDp >= 0.01)
        else:
            xfoilcd, xfoilcl, xfoilalpha, xfoilcm = XFOIL.single_cl(x0[self.CL.key])
            constraints = [
                           self.CDp0 >= xfoilcd,
                           self.CDp**2 >= self.CDp**2 * self.M**2 + self.CDp0**2
                          ]

            return ConstraintSet(constraints)
bqpd commented 8 years ago

Hmm! This seems like it should work...if it solves with the single constraint self.CDp**2 >= self.CDp**2 * self.M**2 + xfoilcd**2 then this sounds like a bug.

codykarcher commented 8 years ago

Yea, let me put together a better example on this... I'm not entirely sure it's a gpkit issue if you think that should work. Thanks.

codykarcher commented 8 years ago

This seems to have resolved. I suspect I was actually doing something incorrectly, causing the error.