Skip to content

Creating a New Use Case

This guide shows you how to create a new optimization use case by following the standard 6-file pattern.

Directory Structure

Create a new directory for your use case:

src/luna_usecases/my_problem/
├── __init__.py      # Public exports
├── data.py          # Problem data model
├── solution.py      # Solution structure
├── formulation.py   # Optimization logic
├── instance.py      # Combining data and formulation
└── collection.py    # Benchmark collections

File Templates

For complete, ready-to-copy templates for each file, see Your First Use Case.

Implementation Steps

Create the Directory

Create your use case directory under src/luna_usecases/ with your chosen name (lowercase, underscores allowed).

Copy the Templates

Copy each file template from Your First Use Case, replacing the example names with your own.

Implement Your Logic

Edit the generated files to implement your specific problem:

  • data.py: Define problem parameters
  • solution.py: Define result structure
  • formulation.py: Implement formulate() and interpret()

Test Your Implementation

Create test instances and verify the formulation works correctly.

Best Practices

  1. Start Simple: Implement basic version first
  2. Add Validation: Check inputs and outputs
  3. Document: Add docstrings and examples
  4. Test: Verify on small instances
  5. Benchmark: Create test collections

Next Steps