Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raising Variables to Substituted Variables #597

Closed
codykarcher opened this issue Mar 24, 2016 · 5 comments
Closed

Raising Variables to Substituted Variables #597

codykarcher opened this issue Mar 24, 2016 · 5 comments

Comments

@codykarcher
Copy link
Contributor

It would be nice if this worked:

from gpkit import Variable, Model, units
import gpkit

mwx = Variable("mwx", 1, "-", "Maximum Takeoff Weight Weighting Exponent")
MTOW = Variable("W_{MTO}", "-", "Maximum Takeoff Weight")

constraints = [MTOW >= 10]
objective = MTOW**mwx

m = Model(objective, constraints)
sol = m.solve('cvxopt', verbosity=1)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-7-6a678a48de69> in <module>()
      6 
      7 constraints = [MTOW >= 10]
----> 8 objective = MTOW**mwx
      9 
     10 m = Model(objective, constraints)

TypeError: unsupported operand type(s) for ** or pow(): 'Variable' and 'Variable'

So that I could sweep over the exponent in controlpanel...

@bqpd
Copy link
Contributor

bqpd commented Mar 24, 2016

Ooh, interesting example. I don't think that's best done with a Variable,
though? But this is definitely a use case that comes up. @whoburg?
On Mar 24, 2016 13:06, "cjk12" [email protected] wrote:

It would be nice if this worked:

from gpkit import VectorVariable, Variable, Model, unitsimport gpkit

mwx = Variable("mwx", 1, "-", "Maximum Takeoff Weight Weighting Exponent")MTOW = Variable("W_{MTO}", "-", "Maximum Takeoff Weight")

constraints = [MTOW >= 10]
objective = MTOW**mwx

m = Model(objective, constraints)
sol = m.solve('cvxopt', verbosity=1)


TypeError Traceback (most recent call last)
in ()
8 constraints = [MTOW >= 10]
9
---> 10 objective = MTOW**mwx
11
12 m = Model(objective, constraints)

TypeError: unsupported operand type(s) for ** or pow(): 'Variable' and 'Variable'

So that I could sweep over the exponent in controlpanel...


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#597

@whoburg
Copy link
Collaborator

whoburg commented Mar 25, 2016

I'm noticing a lot of cases where users want to play with the objective after model creation (this is one example; another is flipping back and forth between MTOW and 1/endurance).

I don't think we should allow a gpkit.Variable to be used as an exponent. One problem is that it's not clear what to do with units. (note that the units of the objective change every time mwx is changed in the example above -- this is excusable for an objective, but probably not so in constraints).

So, my reaction is that we could handle this in controlpanel by allowing for sliders that aren't Variables in the model. @bqpd, do we already have a related issue with linkedsweeps? Another related issue might be feasibility models with varying exponents on the slack variables.

@bqpd
Copy link
Contributor

bqpd commented Mar 25, 2016

Yeah, hooks for custom controlpanel sliders is probably good. I don't think we have a related issue with linkedsweeps?

In general, changing the cost function is a great thing for a user to be doing and we should definitely encourage it more than we do at present.

@bqpd bqpd added this to the Next release milestone Mar 25, 2016
@whoburg
Copy link
Collaborator

whoburg commented Mar 25, 2016

agree with that.

@bqpd bqpd modified the milestones: Visualization / UI, Next release Apr 6, 2016
@bqpd
Copy link
Contributor

bqpd commented Sep 8, 2016

superseded by #825

@bqpd bqpd closed this as completed Sep 8, 2016
@bqpd bqpd removed this from the Visualization / UI milestone Mar 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants