convexengineering / gpkit

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

Model.children and Model.parent #1524

Closed pgkirsch closed 4 years ago

pgkirsch commented 4 years ago

Would it be straightforward to create children and parent attributes for all Model objects? Proposed usage:

Mission.children = ["FlightProfile", "Atmosphere", "AircraftPerformance"]
AircraftPerformance.children = ["Aircraft", "FuselagePerf",.... ]
Aircraft.parent = "AircraftPerformance"

I understand it's possible to re-construct these by iterating over all model varkeys and using lineage, but it seems like it would be more elegant to create during model creation, i.e. execution of Model.__init__?

This would help with visualizing model structures. Related to #1088.

1ozturkbe commented 4 years ago

This is similar to #1451 as well.

bqpd commented 4 years ago

Wouldn't be too hard (probably best to do as another thing the NamedVariable environment catches), but what's the reason you want the stored entries to be a string/list of strings instead of the model instances directly?

pgkirsch commented 4 years ago

Yea model instances probably make more sense. That's how I originally wrote it, I thought strings might be easier for the #1088 use case, but actually probably not.

pgkirsch commented 4 years ago

Not actually sure this is necessary for #1088 anymore though but would perhaps would still be a nice attribute to have.

bqpd commented 4 years ago

It's something I've dallied with adding a few times, but it always turns out to not quite be necessary...happy to add if there's a specific usecase though, like ended up happening with posynomials.

bqpd commented 4 years ago

Closing this until there's a specific usecase...