diff --git a/.nextmv/golden/knapsack-pyoptinterface/inputs/input.json b/.nextmv/golden/python-pyoptinterface-knapsack/inputs/input.json similarity index 100% rename from .nextmv/golden/knapsack-pyoptinterface/inputs/input.json rename to .nextmv/golden/python-pyoptinterface-knapsack/inputs/input.json diff --git a/.nextmv/golden/knapsack-pyoptinterface/inputs/input.json.golden b/.nextmv/golden/python-pyoptinterface-knapsack/inputs/input.json.golden similarity index 100% rename from .nextmv/golden/knapsack-pyoptinterface/inputs/input.json.golden rename to .nextmv/golden/python-pyoptinterface-knapsack/inputs/input.json.golden diff --git a/.nextmv/golden/knapsack-pyoptinterface/main_test.go b/.nextmv/golden/python-pyoptinterface-knapsack/main_test.go similarity index 91% rename from .nextmv/golden/knapsack-pyoptinterface/main_test.go rename to .nextmv/golden/python-pyoptinterface-knapsack/main_test.go index 4216d56..9613e77 100644 --- a/.nextmv/golden/knapsack-pyoptinterface/main_test.go +++ b/.nextmv/golden/python-pyoptinterface-knapsack/main_test.go @@ -41,7 +41,7 @@ func TestGolden(t *testing.T) { }, ExecutionConfig: &golden.ExecutionConfig{ Command: "python3", - Args: []string{"../../../knapsack-pyoptinterface/main.py"}, + Args: []string{"../../../python-pyoptinterace-knapsack/main.py"}, InputFlag: "-input", OutputFlag: "-output", }, diff --git a/.nextmv/readme/knapsack-pyoptinterface/0.sh b/.nextmv/readme/python-pyoptinterface-knapsack/0.sh similarity index 100% rename from .nextmv/readme/knapsack-pyoptinterface/0.sh rename to .nextmv/readme/python-pyoptinterface-knapsack/0.sh diff --git a/.nextmv/readme/knapsack-pyoptinterface/0.sh.golden b/.nextmv/readme/python-pyoptinterface-knapsack/0.sh.golden similarity index 100% rename from .nextmv/readme/knapsack-pyoptinterface/0.sh.golden rename to .nextmv/readme/python-pyoptinterface-knapsack/0.sh.golden diff --git a/.nextmv/readme/knapsack-pyoptinterface/1.sh b/.nextmv/readme/python-pyoptinterface-knapsack/1.sh similarity index 100% rename from .nextmv/readme/knapsack-pyoptinterface/1.sh rename to .nextmv/readme/python-pyoptinterface-knapsack/1.sh diff --git a/.nextmv/readme/knapsack-pyoptinterface/1.sh.golden b/.nextmv/readme/python-pyoptinterface-knapsack/1.sh.golden similarity index 100% rename from .nextmv/readme/knapsack-pyoptinterface/1.sh.golden rename to .nextmv/readme/python-pyoptinterface-knapsack/1.sh.golden diff --git a/.nextmv/readme/knapsack-pyoptinterface/2.sh b/.nextmv/readme/python-pyoptinterface-knapsack/2.sh similarity index 100% rename from .nextmv/readme/knapsack-pyoptinterface/2.sh rename to .nextmv/readme/python-pyoptinterface-knapsack/2.sh diff --git a/.nextmv/workflow-configuration.yml b/.nextmv/workflow-configuration.yml index 3f8e8bd..6279264 100644 --- a/.nextmv/workflow-configuration.yml +++ b/.nextmv/workflow-configuration.yml @@ -48,7 +48,7 @@ apps: app_id: python-pyomo-knapsack marketplace_app_id: knapsack.pyomo description: Solve a knapsack problem using Pyomo. - - name: knapsack-pyoptinterface + - name: python-pyoptinterace-knapsack type: python app_id: marketplace_app_id: diff --git a/README.md b/README.md index 8828172..31664f3 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,8 @@ run on Nextmv Cloud. assignment problem. Demonstrates how to use devcontainers. * [python-pyomo-shiftplanning]: Use Python and Pyomo to solve a shift planning problem. Demonstrates how to use devcontainers. +* [python-pyoptinterface-knapsack]: Use Python and PyOptInterface to solve a + knapsack problem. Demonstrates how to use devcontainers. * [python-pyvroom-routing]: Use Python and Pyvroom to solve a vehicle routing problem. Demonstrates how to use devcontainers. @@ -106,3 +108,4 @@ run on Nextmv Cloud. [python-pyomo-shiftplanning]: ./python-pyomo-shiftplanning/README.md [python-pyvroom-routing]: ./python-pyvroom-routing/README.md [python-xpress-knapsack]: ./python-xpress-knapsack/README.md +[python-pyoptinterface-knapsack]: ./python-pyoptinterface-knapsack/README.md diff --git a/knapsack-pyoptinterface/README.md b/knapsack-pyoptinterface/README.md deleted file mode 100644 index 3e1f1af..0000000 --- a/knapsack-pyoptinterface/README.md +++ /dev/null @@ -1,69 +0,0 @@ -# Nextmv PyOptInterface Python template - -This template demonstrates how to solve a Mixed Integer Programming problem -using the [highs][highs] solver through the [PyOptInterface][pyoptinterface] - -To solve a Mixed Integer Problem (MIP) is to optimize a linear objective -function of many variables, subject to linear constraints. We demonstrate this -by solving the knapsack problem using the [PyOptInterface][pyoptinterface] MIP -modeling interface. - -Knapsack is a classic combinatorial optimization problem. Given a collection of -items with a value and weight, our objective is to maximize the total value -without exceeding the weight capacity of the knapsack. - -The input defines a number of items which have an id to identify the item, a -weight and a value. Additionally there is a weight capacity. - -The most important files created are `main.py` and `input.json`. - -* `main.py` implements a MIP knapsack solver. -* `input.json` is a sample input file. - -Follow these steps to run locally. - -1. The packages listed in the `requirements.txt` will get bundled with the app - as defined in the `app.yaml` manifest. When working locally, make sure that - these are installed as well: - - ```bash - pip3 install -r requirements.txt - ``` - -1. Run the command below to check that everything works as expected: - - ```bash - python3 main.py -input input.json -output output.json -duration 30 - ``` - -1. A file `output.json` should have been created with the optimal knapsack - solution. - -## Mirror running on Nextmv Cloud locally - -Pre-requisites: Docker needs to be installed. - -To run the application locally in the same docker image as the one used on the -Nextmv Cloud, you can use the following command: - -```bash -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' -``` - -You can also debug the application by running it in a Dev Container. This -workspace recommends to install the Dev Container extension for VSCode. If you -have the extension installed, you can open the workspace in a container by using -the command `Dev Containers: Reopen in Container`. - -## Next steps - -* Open `main.py` and read through the comments to understand the model. -* Further documentation, guides, and API references about custom modeling and - deployment can also be found on our [blog](https://www.nextmv.io/blog) and on - our [documentation site](https://docs.nextmv.io). -* Need more assistance? Send us an [email](mailto:support@nextmv.io)! - -[highs]: https://highs.dev/ -[pyoptinterface]: https://github.com/metab0t/PyOptInterface diff --git a/knapsack-pyoptinterface/VERSION b/knapsack-pyoptinterface/VERSION deleted file mode 100644 index 45c7a58..0000000 --- a/knapsack-pyoptinterface/VERSION +++ /dev/null @@ -1 +0,0 @@ -v0.0.1 diff --git a/knapsack-pyoptinterface/.devcontainer/devcontainer.json b/python-pyoptinterface-knapsack/.devcontainer/devcontainer.json similarity index 100% rename from knapsack-pyoptinterface/.devcontainer/devcontainer.json rename to python-pyoptinterface-knapsack/.devcontainer/devcontainer.json diff --git a/knapsack-pyoptinterface/LICENSE b/python-pyoptinterface-knapsack/LICENSE similarity index 100% rename from knapsack-pyoptinterface/LICENSE rename to python-pyoptinterface-knapsack/LICENSE diff --git a/python-pyoptinterface-knapsack/README.md b/python-pyoptinterface-knapsack/README.md new file mode 100644 index 0000000..f42d64f --- /dev/null +++ b/python-pyoptinterface-knapsack/README.md @@ -0,0 +1,44 @@ +# Nextmv Python PyOptInterface Knapsack + +Example for running a Python application on the Nextmv Platform using the +PyOptInterface package. We solve a knapsack Mixed Integer Programming problem. + +1. Install packages. + + ```bash + pip3 install -r requirements.txt + ``` + +1. Run the app. + + ```bash + python3 main.py -input input.json -output output.json -duration 30 + ``` + +## Mirror running on Nextmv Cloud locally + +Docker needs to be installed. + +To run the application in the same Docker image as the one used on Nextmv +Cloud, you can use the following command: + +```bash +cat input.json | docker run -i --rm \ +-v $(pwd):/app ghcr.io/nextmv-io/runtime/pyomo:latest \ +sh -c 'python3 /app/main.py' +``` + +You can also debug the application by running it in a Dev Container. This +workspace recommends to install the Dev Container extension for VSCode. If you +have the extension installed, you can open the workspace in a container by +using the command `Dev Containers: Reopen in Container`. + +## Next steps + +* Open `main.py` and modify the model. +* Visit our [docs][docs] and [blog][blog]. Need more assistance? + [Contact][contact] us! + +[docs]: https://docs.nextmv.io +[blog]: https://www.nextmv.io/blog +[contact]: https://www.nextmv.io/contact diff --git a/knapsack-pyoptinterface/app.yaml b/python-pyoptinterface-knapsack/app.yaml similarity index 100% rename from knapsack-pyoptinterface/app.yaml rename to python-pyoptinterface-knapsack/app.yaml diff --git a/knapsack-pyoptinterface/input.json b/python-pyoptinterface-knapsack/input.json similarity index 100% rename from knapsack-pyoptinterface/input.json rename to python-pyoptinterface-knapsack/input.json diff --git a/knapsack-pyoptinterface/main.py b/python-pyoptinterface-knapsack/main.py similarity index 100% rename from knapsack-pyoptinterface/main.py rename to python-pyoptinterface-knapsack/main.py diff --git a/knapsack-pyoptinterface/knapsack-pyoptinterface.code-workspace b/python-pyoptinterface-knapsack/python-pyoptinterface.code-workspace similarity index 100% rename from knapsack-pyoptinterface/knapsack-pyoptinterface.code-workspace rename to python-pyoptinterface-knapsack/python-pyoptinterface.code-workspace diff --git a/knapsack-pyoptinterface/requirements-arm64.txt b/python-pyoptinterface-knapsack/requirements-arm64.txt similarity index 100% rename from knapsack-pyoptinterface/requirements-arm64.txt rename to python-pyoptinterface-knapsack/requirements-arm64.txt diff --git a/knapsack-pyoptinterface/requirements.txt b/python-pyoptinterface-knapsack/requirements.txt similarity index 100% rename from knapsack-pyoptinterface/requirements.txt rename to python-pyoptinterface-knapsack/requirements.txt