Skip to content

Commit

Permalink
Modify README
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-quintero committed Feb 20, 2024
1 parent 0b407b3 commit aebfa8a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 14 deletions.
23 changes: 13 additions & 10 deletions knapsack-ampl/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Nextmv OR-Tools Python template
# Nextmv AMPL Python template

This template demonstrates how to solve a Mixed Integer Programming problem
using the open source software suite [OR-Tools][or-tools].
using the AMPL Python package [amplpy][amplpy].

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 [integer
optimzation][integer-optimization] interface.
by solving the knapsack problem.

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
Expand All @@ -15,10 +14,14 @@ 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`.
The most important files created are `main.py`, `input.json`, and
`KEY.template`.

* `main.py` implements a MIP knapsack solver.
* `input.json` is a sample input file.
* `KEY.template` is a file demonstrating how to use the AMPL UUID license key.
Copy this file into a `KEY` file and replace the contents with your actual
license key.

Follow these steps to run locally.

Expand All @@ -28,13 +31,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
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 All @@ -45,5 +49,4 @@ Follow these steps to run locally.
our [documentation site](https://docs.nextmv.io).
* Need more assistance? Send us an [email](mailto:[email protected])!

[or-tools]: https://developers.google.com/optimization
[integer-optimization]: https://developers.google.com/optimization/mip
[amplpy]: https://amplpy.ampl.com/en/latest/?_gl=1*16ca5pw*_ga*Nzk4OTUwMDgwLjE3MDgzNTIzMzg.*_ga_FY84K2YRRE*MTcwODQ0NTgwMy42LjEuMTcwODQ0NTgzOC4wLjAuMA..
8 changes: 4 additions & 4 deletions knapsack-ampl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ def main() -> None:

# Read input "data", solve the problem and write the solution.
input_data = read_input(args.input)
log("Solving knapsack problem:")
log(f" - items: {len(input_data.get('items', []))}")
log(f" - capacity: {input_data.get('weight_capacity', 0)}")
log(f" - max duration: {args.duration} seconds")
# log("Solving knapsack problem:")
# log(f" - items: {len(input_data.get('items', []))}")
# log(f" - capacity: {input_data.get('weight_capacity', 0)}")
# log(f" - max duration: {args.duration} seconds")
solution = solve(input_data, args.duration, args.provider)
write_output(args.output, solution)

Expand Down
31 changes: 31 additions & 0 deletions knapsack-ampl/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
ampl-module-amplgsl==20231107
ampl-module-baron==20230405
ampl-module-base==20240126
ampl-module-cbc==20240115
ampl-module-coin==20240115
ampl-module-conopt==20211109
ampl-module-copt==20240115
ampl-module-cplex==20240115
ampl-module-gcg==20230919
ampl-module-gecode==20220504
ampl-module-gjh==20231111
ampl-module-gurobi==20240115
ampl-module-highs==20240115
ampl-module-ilogcp==20230228
ampl-module-knitro==20240209
ampl-module-lgo==20190908
ampl-module-lindoglobal==20210406
ampl-module-loqo==20210410
ampl-module-minos==20211109
ampl-module-mosek==20240118
ampl-module-open==20240121
ampl-module-plugins==20240102
ampl-module-scip==20240121
ampl-module-snopt==20211109
ampl-module-xpress==20240115
amplpy==0.13.2
ampltools==0.7.4
certifi==2024.2.2
charset-normalizer==3.3.2
idna==3.6
requests==2.31.0
urllib3==2.2.1

0 comments on commit aebfa8a

Please sign in to comment.