-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
Description
The C3Options struct in c3_options.h is functional but can benefit from a structural refactor to improve readability, maintainability, and scalability. Currently, the struct contains a large number of parameters, some of which are loosely related, making it harder to navigate and understand. By introducing sub-structs, enumerations, and grouping related parameters, we can simplify the organization and enhance the usability of the code.
-
Use Enumerations for Fixed Options:
- Replace string-based parameters like contact_model and projection_type with enumerations for type safety and clarity:
enum class ContactModel { StewartAndTrinkle, Anitescu }; enum class ProjectionType { QP, MIQP };
- Replace string-based parameters like contact_model and projection_type with enumerations for type safety and clarity:
-
Encapsulate Cost Matrix Parameters:
- Move cost matrix parameters (
Q,R,G,U, and their scaling factors) into a dedicated sub-struct for better modularity.
- Move cost matrix parameters (
-
Improve Serialization Logic:
- Simplify the Serialize method by delegating serialization to sub-structs, reducing redundancy and improving readability.
Advantages of the Refactor
-
Improved Readability:
- Grouping related parameters makes the code easier to navigate and understand.
- Enumerations provide clear, self-documenting code.
-
Enhanced Maintainability:
- Changes to specific parameter groups (e.g., cost matrices) can be made in isolation without affecting unrelated parts of the struct.
-
Type Safety:
- Enumerations prevent invalid values (e.g., typos in strings like
"stewart_and_trinkle") and ensure only valid options are used.
- Enumerations prevent invalid values (e.g., typos in strings like
-
Scalability:
- Adding new parameters or features becomes easier without bloating the main struct.
-
Cleaner Serialization:
- Delegating serialization to sub-structs reduces duplication and makes the logic more modular.
Generated by: GitHub Copilot