Skip to content

Commit

Permalink
Merge pull request #62 from nextmv-io/merschformann/add-pyoptinterfac…
Browse files Browse the repository at this point in the history
…e-knapsack

Adds knapsack-pyoptinterface app
  • Loading branch information
merschformann authored Sep 10, 2024
2 parents 32b282f + a1d15cc commit 8717604
Show file tree
Hide file tree
Showing 21 changed files with 696 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .nextmv/golden/knapsack-pyoptinterface/inputs/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"items": [
{
"id": "cat",
"value": 100,
"weight": 20
},
{
"id": "dog",
"value": 20,
"weight": 45
},
{
"id": "water",
"value": 40,
"weight": 2
},
{
"id": "phone",
"value": 6,
"weight": 1
},
{
"id": "book",
"value": 63,
"weight": 10
},
{
"id": "rx",
"value": 81,
"weight": 1
},
{
"id": "tablet",
"value": 28,
"weight": 8
},
{
"id": "coat",
"value": 44,
"weight": 9
},
{
"id": "laptop",
"value": 51,
"weight": 13
},
{
"id": "keys",
"value": 92,
"weight": 1
},
{
"id": "nuts",
"value": 18,
"weight": 4
}
],
"weight_capacity": 50
}
66 changes: 66 additions & 0 deletions .nextmv/golden/knapsack-pyoptinterface/inputs/input.json.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"options": {
"duration": 30,
"input": "input.json",
"output": "output.json",
"version": "0.2.8"
},
"solution": {
"items": [
{
"id": "cat",
"value": 100,
"weight": 20
},
{
"id": "water",
"value": 40,
"weight": 2
},
{
"id": "phone",
"value": 6,
"weight": 1
},
{
"id": "book",
"value": 63,
"weight": 10
},
{
"id": "rx",
"value": 81,
"weight": 1
},
{
"id": "coat",
"value": 44,
"weight": 9
},
{
"id": "keys",
"value": 92,
"weight": 1
},
{
"id": "nuts",
"value": 18,
"weight": 4
}
]
},
"statistics": {
"result": {
"custom": {
"constraints": 1,
"status": "TerminationStatusCode.OPTIMAL",
"variables": 11
},
"value": 444
},
"run": {
"duration": 0.123
},
"schema": "v1"
}
}
50 changes: 50 additions & 0 deletions .nextmv/golden/knapsack-pyoptinterface/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package mip

import (
"os"
"testing"

"github.com/nextmv-io/sdk/golden"
)

func TestMain(m *testing.M) {
code := m.Run()
os.Exit(code)
}

func TestGolden(t *testing.T) {
golden.FileTests(
t,
"inputs",
golden.Config{
Args: []string{
"-duration",
"30",
},
TransientFields: []golden.TransientField{
{
Key: "$.statistics.result.duration",
Replacement: golden.StableFloat,
},
{
Key: "$.statistics.run.duration",
Replacement: golden.StableFloat,
},
{
Key: "$.options.output",
Replacement: "output.json",
},
{
Key: "$.options.input",
Replacement: "input.json",
},
},
ExecutionConfig: &golden.ExecutionConfig{
Command: "python3",
Args: []string{"../../../knapsack-pyoptinterface/main.py"},
InputFlag: "-input",
OutputFlag: "-output",
},
},
)
}
3 changes: 3 additions & 0 deletions .nextmv/golden/workflow-configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ apps:
- name: knapsack-pyomo
language: python
language-version: 3.11
- name: knapsack-pyoptinterface
language: python
language-version: 3.11
- name: hello-world
language: python
language-version: 3.11
Expand Down
1 change: 1 addition & 0 deletions .nextmv/readme/knapsack-pyoptinterface/0.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pip3 install -r requirements.txt
Empty file.
1 change: 1 addition & 0 deletions .nextmv/readme/knapsack-pyoptinterface/1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python3 main.py -input input.json -output output.json -duration 30
Empty file.
3 changes: 3 additions & 0 deletions .nextmv/readme/knapsack-pyoptinterface/2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cat input.json | docker run -i --rm \
-v $(pwd):/app ghcr.io/nextmv-io/runtime/python:3.11 \
sh -c 'pip install -r requirements.txt > /dev/null && python3 /app/main.py'
6 changes: 6 additions & 0 deletions .nextmv/readme/workflow-configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ apps:
silent: true
- name: 2.sh
skip: true
- name: knapsack-pyoptinterface
scripts:
- name: 0.sh
silent: true
- name: 2.sh
skip: true
- name: hello-world
scripts:
- name: 0.sh
Expand Down
5 changes: 5 additions & 0 deletions .nextmv/workflow-configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ apps:
app_id: knapsack-pyomo
marketplace_app_id: knapsack.pyomo
description: Solve a knapsack problem using Pyomo.
- name: knapsack-pyoptinterface
type: python
app_id:
marketplace_app_id:
description: Solve a knapsack problem using PyOptInterface.
- name: hello-world
type: python
app_id:
Expand Down
16 changes: 16 additions & 0 deletions knapsack-pyoptinterface/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/go
{
"name": "Python",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "ghcr.io/nextmv-io/runtime/python:3.11",
"customizations": {
"vscode": {
"extensions": ["ms-python.debugpy", "ms-python.python"],
"settings": {
"python.defaultInterpreterPath": "python"
}
}
},
"postCreateCommand": "pip install -r requirements.txt"
}
Loading

0 comments on commit 8717604

Please sign in to comment.