Closed codykarcher closed 6 years ago
Yeah, as it stands x0
is only freevariables...I'll fix that in the externalsolver
branch
Ok, yea, that's the branch I'm working on. Let me know when you've pushed.
Wait, actually the issue is just that Re is not in any of the constraints, and so is not in the solution. The following works:
from gpkit import VectorVariable, Variable, units, SignomialProgram
import gpkit
from gpkit.constraints.set import ConstraintSet
Re = Variable("Re", 1e7, "-", "Reynolds Number")
CL = Variable("C_L", "-", "Lift Coefficient")
CD = Variable("C_D", "-", "Drag Coefficient")
def xfoil(x0):
return [CD >= 0.01 + .03*CL**2]
class AeroModel(ConstraintSet):
def as_gpconstr(self, x0):
gpconstr = super(AeroModel, self).as_gpconstr(x0)
if x0 and x0["Re"] >= 1e6:
constraints = xfoil(x0)
else:
constraints = [CD >= 1. + CL**2]
return ConstraintSet([gpconstr, constraints])
constraints = AeroModel([CL >= 1.0, Re >= 1e4*CL])
objective = CD
m = SignomialProgram(objective, constraints, require_signomial=False)
m.localsolve('cvxopt', verbosity=1)
Oh, got it, cool. Yea, it will definitely be in in the future, but this is the downside of the toy problem. Thanks.
So this is starting to be really annoying. I want to be able to declare a constant variable and use it in the constraint, like the original post above. Any thoughts on if this is possible? The goal again is to be able to slide it around in real time...
This works:
from gpkit import VectorVariable, Variable, units, SignomialProgram, Model
import gpkit
from gpkit.constraints.set import ConstraintSet
Re = Variable("Re", 1e6, "-", "Reynolds Number")
CL = Variable("C_L", "-", "Lift Coefficient")
CLmax = Variable("C_{L,max}", 1.0, "-", "Lift Coefficient")
CD = Variable("C_D", "-", "Drag Coefficient")
class AeroModel(ConstraintSet):
def as_posyslt1(self):
raise ValueError("AeroModel is not allowed to solve as a GP.")
def as_gpconstr(self, x0):
if x0 and x0["Re"] >= 1e6:
x0["C_{L,max}"] = 2
elif x0:
x0["C_{L,max}"] = 1
gpconstr = super(AeroModel, self).as_gpconstr(x0)
return gpconstr
constraints = AeroModel([CL >= CLmax, Re >= 1e4*CL, CD >= 1. + CL**2])
objective = CD
m = Model(objective, constraints)
# m.localsolve('cvxopt', verbosity=1)
m.controlpanel()
Reopened so that the solution can be documented...
related to #590
I'm running into this again and don't understand the above fix. If I have declared a constant, I really need to pass it in as part of the x0
dict. The constants are in the constraints, so that shouldn't be the issue... Is the core of the fix:
gpconstr = super(AeroModel, self).as_gpconstr(x0)
Because I've moved a ways from the construction in the example in this issue in my code...
The issue for me is that I'm actually calling another external routine (a geometry engine glue code) that requires the number of engines, which is declared as a constant in my code.
@cjk12, what's the current status of this problem?
Again related to #590, I'd like to do this:
But I'm getting:
I'd like to be able to pass in the constants, but apparently they aren't in the
x0
vector? Thoughts?Note, the example as defined in #590 works fine.