From e9a412c6796c39e95aa83a33507d6125b7fed68c Mon Sep 17 00:00:00 2001 From: Sebastian Quintero Date: Wed, 13 Mar 2024 13:55:00 -0500 Subject: [PATCH] Use the global nextmv license for AMPL --- knapsack-ampl/README.md | 14 ++++++++++---- knapsack-ampl/app.yaml | 4 +++- knapsack-ampl/main.py | 13 ++++++++----- knapsack-gurobi/app.yaml | 2 +- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/knapsack-ampl/README.md b/knapsack-ampl/README.md index 426a0cc..6c58e23 100644 --- a/knapsack-ampl/README.md +++ b/knapsack-ampl/README.md @@ -20,8 +20,14 @@ The most important files created are `main.py`, `input.json`, and * `main.py` implements a MIP knapsack solver. * `input.json` is a sample input file. * `ampl_license_uuid.template` is a file demonstrating how to use the AMPL UUID - license key. Remove the `.template` extension and replace the contents with - your actual license key to be left with a file named `ampl_license_uuid`. + license key. + * If you have an AMPL license, remove the `.template` extension and replace + the contents with your actual license key to be left with a file named + `ampl_license_uuid`. Modify the `app.yaml` file to include the + `ampl_license_uuid` in the files list. + * If you are just testing and don’t have an AMPL license, you don’t need to + do anything, as this community app ships with a special license that allows + you to test AMPL with some limits. Follow these steps to run locally. @@ -34,14 +40,14 @@ Follow these steps to run locally. pip3 install -r requirements.txt ``` -1. Run the command below to check that everything works as expected: +2. Run the command below to check that everything works as expected: ```bash python3 main.py -input input.json -output output.json \ -duration 30 -provider cbc ``` -1. A file `output.json` should have been created with the optimal knapsack +3. A file `output.json` should have been created with the optimal knapsack solution. ## Next steps diff --git a/knapsack-ampl/app.yaml b/knapsack-ampl/app.yaml index fa266a4..9d77809 100644 --- a/knapsack-ampl/app.yaml +++ b/knapsack-ampl/app.yaml @@ -5,4 +5,6 @@ runtime: ghcr.io/nextmv-io/runtime/ampl:latest # (e.g.: configs/*.json) is supported. files: - main.py - - ampl_license_uuid # Store your license information here. + # If you have an AMPL license, uncomment the following line and make sure to + # store your license information in that file. + # - ampl_license_uuid diff --git a/knapsack-ampl/main.py b/knapsack-ampl/main.py index 2de8cdf..7b5248e 100644 --- a/knapsack-ampl/main.py +++ b/knapsack-ampl/main.py @@ -22,8 +22,6 @@ "xpress": "timelimit", } -# Open source solvers. -OSS_SOLVERS = ["cbc", "gcg", "gecode", "highs", "scip"] # Status of the solver after optimizing. STATUS = [ @@ -101,9 +99,14 @@ def solve(input_data: dict[str, Any], duration: int, provider: str) -> dict[str, start_time = time.time() # Activate license. - if provider not in OSS_SOLVERS: - license = read_license_uuid() - modules.activate(license) + modules.activate("nextmv") + + # If you have an AMPL license, uncomment the following block. + # try: + # license = read_license_uuid() + # modules.activate(license) + # except Exception: + # log("Using default AMPL license for Nextmv") # Defines the model. ampl = AMPL() diff --git a/knapsack-gurobi/app.yaml b/knapsack-gurobi/app.yaml index 1e580c2..10fc0e1 100644 --- a/knapsack-gurobi/app.yaml +++ b/knapsack-gurobi/app.yaml @@ -5,4 +5,4 @@ runtime: ghcr.io/nextmv-io/runtime/gurobi:latest # (e.g.: configs/*.json) is supported. files: - main.py - - gurobi.lic # Store your license information here. + - gurobi.lic # Store your license information in this file.