This repository demonstrates how to evolve a basic OR-Tools optimization model into a cloud-ready application using Nextmv. The examples show a small, local model (the Stigler diet problem), how to prepare it for Nextmv, and how to add lightweight experimentation and statistics.
A small OR-Tools implementation of the Stigler diet problem that runs locally.
Run locally:
cd starting-state/
pip install -r requirements.txt
python main.pyWhat the example includes:
- β
OR-Tools solver model (
starting-state/main.py) - β
Externalized input file:
starting-state/inputs/diet_data.json - β
Produces
solution.txt(human-readable) andstatistics.json(Nextmv-style statistics)
Changes made (example):
- An
app.yamlmanifest that tells Nextmv how to run the model and handle inputs/outputs.
Example Nextmv commands (replace example app name and run ID as needed):
cd run_in_nextmv_state/
tar czf - diet.dat | nextmv app run -a ortools-example
nextmv app output -a ortools-example -r <runID>What you unlock:
- β Observability (logs, metrics)
- β Collaboration and instance management
- β Cloud execution and scaling
Additional changes shown in final_state/ include:
- Statistics output compatible with Nextmv experimentation (JSON)
- Configurable options in
app.yamlso you can run parameter sweeps
Example:
cd final_state/
tar czf - diet.dat | nextmv app run -a ortools-example -o "limit_dairy=true"
nextmv app output -a ortools-example -r <runID>What you unlock:
- β Configuration testing and parameter sweeps
- β Performance analytics and custom statistics
- β Easy comparison between runs
This is the Stigler diet problem β a classic optimization that minimizes the cost of a diet while meeting nutritional requirements.
- Objective: Minimize total cost
- Constraints: Meet minimum nutrition requirements (calories, protein, vitamins, etc.)
- The example can be extended with optional constraints (e.g. limit dairy) for experimentation
- Input data (nutrients and food items) are stored in
starting-state/inputs/diet_data.json. - Running the example writes a human-readable summary to
solution.txt(appended) and a JSON statistics filestatistics.json(used by Nextmv) when available.
Prerequisites
- Python 3.8+ (examples use Python 3.11 in Nextmv runtimes)
- Install dependencies in the folder you want to run:
Local execution (starting-state):
cd starting-state/
pip install -r requirements.txt
python main.pyNotes:
- The example reads inputs from
starting-state/inputs/diet_data.json. - It appends a human-readable summary to
solution.txtand writesstatistics.jsonwith Nextmv-style statistics whennextmvis available. - If you don't have OR-Tools installed, install it with
pip install ortoolsor use the providedrequirements.txt.
python push.pySmall, well-placed changes (an app manifest and lightweight statistics) let you move from a local script to a cloud-native optimization application with observability, experiment tracking, and team-ready deployment.
For details on the implementation, see starting-state/main.py and final_state/main.py.
This repository demonstrates how to evolve a basic gurobipy optimization model into a fully-featured, cloud-native application using Nextmv. We'll take you through three stages of development, showing how minimal changes unlock powerful capabilities like observability, collaboration, instance management, version control, and experimentation.
A standard gurobipy diet optimization model that runs locally:
cd starting-state/
python main.pyWhat you get:
- β Working optimization model
- β Local execution
- β No version control
- β No collaboration features
- β No observability
- β No experimentation
Changes made:
- Added
app.yamlmanifest - Tells Nextmv how to run your model
cd run_in_nextmv_state/
tar czf - diet.dat | nextmv app run -a gurobipy-example
nextmv app output -a gurobipy-example -r <insert runID here>What you unlock:
- β Observability: Detailed execution logs and metrics
- β Collaboration: Share apps with team members
- β Instance Management: Deploy and manage app versions
- β Version Control: Track model changes over time
- β Cloud Execution: Run on Nextmv's optimized infrastructure
Additional changes:
- Added statistics output - For experiment tracking and comparison
- Exposed options in
app.yaml- For model configuration
cd final_state/
tar czf - diet.dat | nextmv app run -a gurobipy-example -o "limit_dairy=true"
nextmv app output -a gurobipy-example -r <insert runID here>What you unlock:
- β Configuration Testing: Compare different solver configurations
- β Parameter Sweeps: Test multiple scenarios automatically
- β Performance Analytics: Track solution quality and runtime
- β Business Metrics: Custom statistics for your domain
This is a classic optimization problem that minimizes the cost of a diet while meeting nutritional requirements:
- Objective: Minimize total cost of food
- Constraints:
- Meet minimum nutritional requirements (calories, protein, vitamins, etc.)
- Stay within maximum volume limit
- Optional: Limit dairy products (experimentation feature)
type: python
runtime: ghcr.io/nextmv-io/runtime/python:3.11
python:
pip-requirements: requirements.txt
files:
- main.py
configuration:
content:
format: "multi-file"
multi-file:
input:
path: "."
output:
solutions: "."
statistics: "statistics.json"This tells Nextmv:
- Use the Python runtime
- Include your Python files
- How to handle input/output data
- Statistics Output (
main.py):
import nextmv
statistics = nextmv.Statistics(
result=nextmv.ResultStatistics(
duration=m.Runtime,
value=m.ObjVal,
custom={
"nvars": m.NumVars,
"ncons": m.NumConstrs,
},
),
)2.Configurable Options (app.yaml):
configuration:
options:
items:
- name: limit_dairy
option_type: bool
default: false
ui:
control_type: togglepip install -r requirements.txt
python main.py
python push.pyWith just one simple change (adding app.yaml), you transform a local script into a cloud-native optimization application with:
- Zero infrastructure management
- Built-in experiment tracking
- Team collaboration features
- Automatic scaling
- Version control and rollback
- Performance monitoring
This is the power of "Nextmvifying" your optimization models - minimal changes, maximum impact.