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

Use the global nextmv license for AMPL #26

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 some limits.
sebastian-quintero marked this conversation as resolved.
Show resolved Hide resolved

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.
Loading