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

change functional constraint functions #116

Merged
merged 1 commit into from
Oct 20, 2023

Conversation

BaptisteCbl
Copy link
Collaborator

Hi,
This is the pr related to the issue #113 (constraint revise).
I'll do an other pr or commits in this one for the time function revise #115.

@jbcaillau
Copy link
Member

@BaptisteCbl hi there, is this PR ready to merge? the case being I'll have a look.

@BaptisteCbl
Copy link
Collaborator Author

Hello, this PR only addresses the constraint revise, but is ready to merge in this matter per se.

julia> constraint!(ocp, :state, rg=2:3, lb=[ 0, 0 ], ub=[ 1, 2 ])
julia> constraint!(ocp, :initial, rg=1:2:5, lb=[ 0, 0, 0 ], ub=[ 1, 2, 1 ])
julia> constraint!(ocp, :variable, rg=1:2, lb=[ 0, 0 ], ub=[ 1, 2 ])
```
"""
function constraint!(ocp::OptimalControlModel{<: TimeDependence, <: VariableDependence}, type::Symbol;
rg::Union{RangeConstraint,Nothing}=nothing, f::Union{Function,Nothing}=nothing,
val::Union{ctVector,Nothing}=nothing, lb::Union{ctVector,Nothing}=nothing, ub::Union{ctVector,Nothing}=nothing,
rg::Union{OrdinalRange{<:Integer},Integer,Nothing}=nothing, f::Union{Function,Nothing}=nothing, lb::Union{ctVector,Nothing}=nothing, ub::Union{ctVector,Nothing}=nothing,
Copy link
Member

@jbcaillau jbcaillau Aug 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BaptisteCbl 👍🏽 thanks, that was the point

(typeof(rg) <: Int) && (rg = Index(rg))

@match (rg,f,lb,ub) begin
(::Nothing,::Nothing,::ctVector,::ctVector) => return constraint!(ocp, type, lb, ub, label) #
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BaptisteCbl at this point, I see that you reduce the computation of the new constraint! functions with updated named arguments to three cases/subfunctions:

  • linear, full range (no range give implies full range)
  • linear, given range
  • nonlinear (function)

Wouldn't it be more robust, particularly with less code duplication (e.g., check on arguments), to do the converse:

  • fully code the new version with named args
  • implement the other calls of constraint! (namely the three cases mentioned above) by calling this unique new function?

@@ -4,29 +4,30 @@
using BenchmarkTools
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BaptisteCbl just for the record: can you please recall me what these bench folder and bench_nlp_constraints are for? (did not remember this stuff.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bench folder contains programs to generate a markdown file with the performance of the Julia file. Apart from the examples that use CTBase, it is independent of CTBase. I don't think it was meant to stay here. But it was actually developed by @ocots, he may have a better answer.

Copy link
Member

@jbcaillau jbcaillau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @BaptisteCbl, many thanks for the work 🙏🏽 Main comment here. Please tell me what think.

@jbcaillau jbcaillau changed the base branch from main to constraint_revise August 25, 2023 05:51
@jbcaillau
Copy link
Member

jbcaillau commented Oct 5, 2023

@BaptisteCbl hi again, please tell me if you have touched the request below (main comment on the constraint! function revision). I need to know before merging 🤞🏾

Hi @BaptisteCbl, many thanks for the work 🙏🏽 Main comment here. Please tell me what think.

image

@BaptisteCbl
Copy link
Collaborator Author

Hi, I haven't touched this request either but I indeed think that it would be better with your suggestion.

@jbcaillau
Copy link
Member

Hi, I haven't touched this request either but I indeed think that it would be better with your suggestion.

@BaptisteCbl Thanks for the confirmation. Please tell me if you want to do it (I'll do it otherwise 🥹)

@BaptisteCbl
Copy link
Collaborator Author

I won't be able to do it today or this weekend, but if you want I can do it on Monday.

@jbcaillau
Copy link
Member

jbcaillau commented Oct 6, 2023

I won't be able to do it today or this weekend, but if you want I can do it on Monday.

No hurry, next week is fine 👍🏽. Keep in touch.

@jbcaillau
Copy link
Member

@BaptisteCbl having some time this Friday to work on this with you. keep me informed.

@BaptisteCbl
Copy link
Collaborator Author

BaptisteCbl commented Oct 13, 2023

Hi, I looked at the constraints! functions and tried to do as you said but I have difficulty having functions that do not overwrite themselves when we keep the same options. In fact, since we can have declaration with named arguments constraint!(ocp,type,lb=lb,ub=ub) and constraint!(ocp,type,lb,ub) without lb or ub possibly that makes Julia overwrite the first version written. I don't really know how it's possible to overcome this properly.
Otherwise, I'm sorry but I will not be available after 15h30.

@jbcaillau
Copy link
Member

Hi @BaptisteCbl ; available for a quick catch up this Friday (Oct. 20)?

@BaptisteCbl
Copy link
Collaborator Author

Hello, yes I am available in the morning before 12h.

@jbcaillau
Copy link
Member

Hello, yes I am available in the morning before 12h.

👍🏽 I’ll be on zoom at 10:30 if you can
https://univ-cotedazur.zoom.us/my/caillau

@jbcaillau jbcaillau merged commit 05048dc into control-toolbox:constraint_revise Oct 20, 2023
@jbcaillau jbcaillau mentioned this pull request Oct 20, 2023
@jbcaillau
Copy link
Member

Followed by [#123]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants