{"id":26157193,"url":"https://github.com/fdabrandao/pympl","last_synced_at":"2025-04-14T08:53:52.855Z","repository":{"id":62581890,"uuid":"41339570","full_name":"fdabrandao/pympl","owner":"fdabrandao","description":"Mathematical Programming Toolbox for AMPL/GMPL","archived":false,"fork":false,"pushed_at":"2019-04-07T22:08:20.000Z","size":1020,"stargazers_count":14,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T22:23:27.641Z","etag":null,"topics":["ampl","modeling-language","optimization","optimization-tools"],"latest_commit_sha":null,"homepage":"https://pypi.python.org/pypi/PyMPL","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fdabrandao.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-25T02:57:56.000Z","updated_at":"2024-04-01T02:53:33.000Z","dependencies_parsed_at":"2022-11-03T21:34:22.249Z","dependency_job_id":null,"html_url":"https://github.com/fdabrandao/pympl","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fdabrandao%2Fpympl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fdabrandao%2Fpympl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fdabrandao%2Fpympl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fdabrandao%2Fpympl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fdabrandao","download_url":"https://codeload.github.com/fdabrandao/pympl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248553927,"owners_count":21123552,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ampl","modeling-language","optimization","optimization-tools"],"created_at":"2025-03-11T09:57:10.940Z","updated_at":"2025-04-14T08:53:52.832Z","avatar_url":"https://github.com/fdabrandao.png","language":"Python","readme":"## PyMPL: A Mathematical Programming Toolbox\nCopyright (C) 2015-2016, Filipe Brandão  \nFaculdade de Ciências, Universidade do Porto  \nPorto, Portugal. All rights reserved. E-mail: \u003cfdabrandao@dcc.fc.up.pt\u003e.\n\n---\n\n[PyMPL](https://github.com/fdabrandao/pympl) is a python extension to the AMPL modeling language that adds new [statements](https://github.com/fdabrandao/pympl/wiki/STMTS) for evaluating python code within AMPL/GMPL models. PyMPL also includes, among others, procedures for modeling [piecewise linear functions](https://github.com/fdabrandao/pympl/wiki/STMTS_SOS), [compressed arc-flow graphs](https://github.com/fdabrandao/pympl/wiki/STMTS_VPSolver) for vector packing, [sub-tour elimination constraints](https://github.com/fdabrandao/pympl/wiki/STMTS_TSP) for TSP, and [lot-sizing reformulations](https://github.com/fdabrandao/pympl/wiki/STMTS_LSLIB) (LS-LIB). PyMPL is fully compatible with both python 2 and 3.\n\n![](https://img.shields.io/badge/license-AGPLv3+-blue.svg)\n[![](https://travis-ci.org/fdabrandao/pympl.svg?branch=master)](https://travis-ci.org/fdabrandao/pympl)\n[![Coverage Status](https://coveralls.io/repos/github/fdabrandao/pympl/badge.svg?branch=experimental)](https://coveralls.io/github/fdabrandao/pympl)\n\n### Useful links\n\n* PyMPL documentation: \u003chttps://github.com/fdabrandao/pympl/wiki\u003e\n* GiHub repository: \u003chttps://github.com/fdabrandao/pympl\u003e\n* BitBucket repository: \u003chttps://bitbucket.org/fdabrandao/pympl\u003e\n* Docker repository: \u003chttps://hub.docker.com/r/fdabrandao/pympl\u003e\n* PyPI repository: \u003chttps://pypi.python.org/pypi/PyMPL\u003e\n\n### Setup\n\nInstall from the [repository](https://pypi.python.org/pypi/PyMPL):\n```bash\n$ pip install pympl\n```\n\nOr build and install locally:\n```\n$ pip install -r requirements.txt\n$ pip install . --upgrade\n$ cd examples; py.test -v --cov pympl\n```\n\nPyMPL can also be used inside a [Docker container](https://github.com/fdabrandao/pympl/wiki/Docker-container) that includes a simple web app for an easy usage.\n\n### Examples\n\n``piecewise_linear.mod``\n\n```ampl\n# Evaluate python code:\n$EXEC{\nxvalues = [0, 10, 15, 25, 30, 35, 40, 45, 50, 55, 60, 70]\nyvalues = [0, 20, 15, 10, 0, 50, 18, 0, 15, 24, 10, 15]\n};\n\nvar u \u003e= 0;\n# Model a piecewise linear function given a list of pairs (x, y=f(x)):\n$PWL[x,y]{zip(xvalues, yvalues)};\n\nmaximize obj: 2*x + 15*y;\ns.t. A: 3*x + 4*y \u003c= 250;\ns.t. B: 7*x - 2*y + 3*u \u003c= 170;\nend;\n```\n\n``vector_packing.mod``:\n\n```ampl\n# Load a vector packing instance from a file:\n$EXEC{\nfrom pyvpsolver import VBP\ninstance = VBP.from_file(\"data/instance.vbp\")\n};\n$PARAM[b{I}]{instance.b};\nvar x{I}, \u003e= 0;\n\n# Generate the arc-flow model:\n$VBP_FLOW[Z]{instance.W, instance.w, [\"x[{}]\".format(i) for i in range(instance.m)]};\n# Variable declarations and flow conservation constraints will be created here\n\nminimize obj: Z;\ns.t. demand{i in I}: x[i] \u003e= b[i]; # demand constraints\nend;\n```\n\n### PyMPL Parser\n\n```python\nimport os\nfrom pympl import PyMPL  # import the parser\n\n# Create a parser and pass local and global variables to the model:\nparser = PyMPL(locals_=locals(), globals_=globals())`\n\n# Parse a file with PyMPL statements and produce a valid AMPL model:\nparser.parse(\"pympl_model.mod\", \"ampl_model.mod\")\n\n# Call GLPK to solve the model (if the original model uses only valid GMPL statements):\nos.system(\"glpsol --math ampl_model.mod\")\n\n# Call AMPL to solve the model:\nos.system(\"ampl ampl_model.mod\")\n```\n\n[[Folder with examples](https://github.com/fdabrandao/pympl/tree/master/examples)]\n\nAdvanced features:\n\n* Given a function `f(varname)` that takes a variable name and returns its value:\n\n  * If any command used implements solution extraction you can use `parser[command_name].extract(f)` to extract the solution;\n  * If any command used implements cut generators you can use `parser[command_name].separate(f)` to generate cutting planes.\n\n***\nCopyright © 2015-2016 [Filipe Brandão](http://www.dcc.fc.up.pt/~fdabrandao/) \u003c [fdabrandao@dcc.fc.up.pt](mailto:fdabrandao@dcc.fc.up.pt) \u003e. All rights reserved.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffdabrandao%2Fpympl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffdabrandao%2Fpympl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffdabrandao%2Fpympl/lists"}