Skip to content

Commit

Permalink
Merge pull request #26 from nextmv-io/chore/ampl-uses-global-nextmv-l…
Browse files Browse the repository at this point in the history
…icense

Use the global nextmv license for AMPL
  • Loading branch information
sebastian-quintero authored Mar 13, 2024
2 parents c253123 + 10646fb commit 247788f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
14 changes: 10 additions & 4 deletions knapsack-ampl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 limits per AMPL's website.

Follow these steps to run locally.

Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion knapsack-ampl/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 8 additions & 5 deletions knapsack-ampl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
"xpress": "timelimit",
}

# Open source solvers.
OSS_SOLVERS = ["cbc", "gcg", "gecode", "highs", "scip"]

# Status of the solver after optimizing.
STATUS = [
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion knapsack-gurobi/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit 247788f

Please sign in to comment.