diff --git a/knapsack-ampl/README.md b/knapsack-ampl/README.md index 5f4965e..960f539 100644 --- a/knapsack-ampl/README.md +++ b/knapsack-ampl/README.md @@ -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 @@ -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. @@ -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 @@ -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:support@nextmv.io)! -[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.. diff --git a/knapsack-ampl/main.py b/knapsack-ampl/main.py index c3919cf..54c95f4 100644 --- a/knapsack-ampl/main.py +++ b/knapsack-ampl/main.py @@ -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) diff --git a/knapsack-ampl/requirements.txt b/knapsack-ampl/requirements.txt index 9106aa9..f2e3174 100644 --- a/knapsack-ampl/requirements.txt +++ b/knapsack-ampl/requirements.txt @@ -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