Skip to content

[feature] Refactor C3Options for Improved Structure and Maintainability #8

@Meow404

Description

@Meow404

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.

  1. 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 };
  2. Encapsulate Cost Matrix Parameters:

    • Move cost matrix parameters (Q, R, G, U, and their scaling factors) into a dedicated sub-struct for better modularity.
  3. Improve Serialization Logic:

    • Simplify the Serialize method by delegating serialization to sub-structs, reducing redundancy and improving readability.

Advantages of the Refactor

  1. Improved Readability:

    • Grouping related parameters makes the code easier to navigate and understand.
    • Enumerations provide clear, self-documenting code.
  2. Enhanced Maintainability:

    • Changes to specific parameter groups (e.g., cost matrices) can be made in isolation without affecting unrelated parts of the struct.
  3. Type Safety:

    • Enumerations prevent invalid values (e.g., typos in strings like "stewart_and_trinkle") and ensure only valid options are used.
  4. Scalability:

    • Adding new parameters or features becomes easier without bloating the main struct.
  5. Cleaner Serialization:

    • Delegating serialization to sub-structs reduces duplication and makes the logic more modular.

Generated by: GitHub Copilot

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions