feat: support optimal control problems with zero-dimensional control#246
Open
feat: support optimal control problems with zero-dimensional control#246
Conversation
- Remove mandatory control declaration requirement in parser
- Fix replace_call method signature for Vector{Union{Nothing, Symbol}} compatibility
- Add comprehensive test suite for zero control dimension cases
- Update test runner configuration for better module isolation
This enables definition of autonomous optimal control problems without control
variables, which was previously blocked by parser validation logic.
- Add check to avoid unnecessary has/subs calls on Nothing symbols - Use eachindex(x) instead of 1:length(x) for better performance - Skip processing of Nothing symbols in variable replacement loop This optimization improves performance when handling control variables that may be Nothing in autonomous optimal control problems.
- Add validation in p_control! to ensure control is declared before dynamics and cost - Control cannot be declared after dynamics (is_global_dyn or is_coord_dyn) - Control cannot be declared after cost criterion (criterion is set) - Maintains consistency while allowing autonomous problems (dynamics without control) This prevents mixed declaration patterns while preserving flexibility for zero-control problems.
- Remove duplicate test for initial_control with nothing - The functionality is already covered in the 'initial_guess without control' test - Streamline test suite by eliminating redundant test cases
- Add declaration order validation tests - Add coordinate dynamics without control tests - Add advanced cost criteria tests (Lagrange, Bolza) - Add constraints without control tests - All 24 tests now pass successfully This provides comprehensive coverage for autonomous optimal control problems and validates the new flexible declaration order logic.
- Add test for state initialization without control - Add test for variable initialization with zero control - Update get_model function to support variable parameter - All 27 tests now pass successfully Enhances test coverage for initialization scenarios in autonomous optimal control problems.
Member
Author
|
@jbcaillau Please review and merge. |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📖 Summary
This PR introduces support for non-controlled optimal control problems (zero-dimensional control) by removing the artificial requirement that control variables must be declared before dynamics and cost criteria. The change enables mathematically valid problems without control variables while maintaining logical declaration order consistency.
🎯 Key Changes
Parser Flexibility
p_dynamics!,p_dynamics_coord!,p_lagrange!, andp_bolza!functionsp_control!to prevent declaring control after dynamics/cost are definedTechnical Improvements
replace_callfunction to handleVector{Union{Nothing, Symbol}}efficientlyNothingsymbols in replacement loops for better performanceComprehensive Testing
🔄 Behavior Changes
✅ Now Supported
❌ Still Prevented
🧪 Testing
📈 Impact
This change expands CTParser.jl's capability to handle the full spectrum of optimal control problems, from fully controlled to completely autonomous systems, while preserving the logical structure that prevents confusing mixed declaration patterns.