-
Notifications
You must be signed in to change notification settings - Fork 20
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
Implements support for variable duration solutions #150
Conversation
@tjstienstra, if you're interested in reviewing this, it is much appreciated. I've only tried it out on the example pendulum problem here, nothing more complicated yet. |
If you have any comments on the API for the instance constraints, I'd be interested. The basic idea is that if you have fixed duration problems you give something like |
I would have a preference not to use round brackets substituting t for indices. That may not just be confusing at first, especially since we normally find the index for the supplied time value, but it will also cause problems for possible future features. The closest solution would be to use a multiple of |
One of my main curiosities is also what would the API look like if variable time steps were supported? |
|
||
|
||
# Specify the objective function and it's gradient. | ||
def obj(free): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use the create_objective_function
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to write it out to see how the new variable affected the equations and did not know if create_objective_function()
supported h
as a symbol.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not yet but we can easily make it support it (will have to check ones more). But I think that the only difference is that we should change the default keyword argument to an integer (bit nicer if someone doesn't specify it) and we have to multiply the objective with the node_time_interval and remove it from the functions where it manually multiplies the solution with the node time interval.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll let you update it after I merge this. Or I could merge in changes onto this branch if you want.
I suspect I could support something like
I originally wrote it like this and then realized it was much simpler to ask the node number from the user, so switched to it. |
I guess the API wouldn't really change other than |
Yeah, that was the other thing I thought of.
I would prefer the additional difficulty, because it is clearer and mathematically correct. t=4h for the fifth node. Another solution is to create a boolean keyword argument to interpret supplied time values as indices. |
I was more thinking toward supplying an iterable as node_time_interval, which may include multiples of |
I'm not sure why you'd want to do that. What is the reason that you'd want to specify unequal proportional spacing? Wouldn't it mean you are trying to guess where the solution is stiff (smaller spacing in stiff areas) without knowing the solution? |
If a problem is partially reusable then we could start iterating to improve the solution. A bit like what pycollo does only then way simpler. In several problems you know where you want a bit higher resolution and where you do not need that many points. |
I see, yes, if you have a sense of the solution you could proportional time to reflect that. |
I switched to integer multiples of the time interval symbol. |
Fixes #19
This PR allows a user to pass in a symbol as the node interval value instead of a float and then specify instance constraints in terms of node index instead of time. This adds the node interval value as a free optimization variable (as the last element) and the resulting constraint equations and Jacobian takes into account the variable interval. I demonstrate it on the pendulum swing up problem.
parse_free
to deal with having h as the last term.