Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds knapsack-pyoptinterface app #62

Merged
merged 14 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
63 changes: 63 additions & 0 deletions .nextmv/golden/knapsack-pyoptinterface/inputs/input.json.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"solutions": [
{
"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,
"version": "0.2.6"
},
"schema": "v1"
}
}
42 changes: 42 additions & 0 deletions .nextmv/golden/knapsack-pyoptinterface/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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,
},
},
ExecutionConfig: &golden.ExecutionConfig{
Command: "python3",
Args: []string{"../../../knapsack-pyoptinterface/main.py"},
InputFlag: "-input",
OutputFlag: "-output",
},
},
)
}
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
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
Loading