ampl / amplpy

Python API for AMPL
https://amplpy.ampl.com
BSD 3-Clause "New" or "Revised" License
63 stars 19 forks source link

Benders Decomposition #37

Closed ahmadanaqreh closed 3 years ago

ahmadanaqreh commented 3 years ago

I have seen a model related to Benders Decomposition about transportation location (just the .mod and .dat files) but I couldn't find the python file that runs the model, is it available somewhere?? Moreover, there is a slide talking about callback for the TSP problem in your slides: is the implementation available for that?? Thanks a lot

fdabrandao commented 3 years ago

Thanks for reporting this issue. The example location transportation has been added in https://github.com/ampl/amplpy/commit/bb827e00f9f80a06f7cfe4c77bf95eac48211da1. You can find the example at https://github.com/ampl/amplpy/blob/master/examples/locationtransportation.py.

Regarding the callbacks, they are in the repository https://github.com/ampl/ampls-api. You can find examples at https://github.com/ampl/ampls-api/tree/master/python/examples. You can find documentation at https://ampls.readthedocs.io/. Please note that this feature is still in beta.

ahmadanaqreh commented 3 years ago

Thank you so much for your help, I have another question please, now I am trying to run the example called simple_callback_gurobi.py here: https://github.com/ampl/ampls-api/blob/master/python/examples/simple_callback_gurobi.py with amplpy-gurobi 0.1.0b6 I got an error "module 'amplpy_gurobi' has no attribute 'GurobiCallback " and when I am using amplpy-gurobi 0.1.0b8 the error is "DLL load failed while importing _amplpy_gurobi_swig: The specified module could not be found."

fdabrandao commented 3 years ago

Thanks for reporting this issue. This issue has now been fixed in version amplpy-gurobi 0.1.0b10. The examples in ampls-api were also updated since simple_callback_gurobi.py in particular was outdated.

ahmadanaqreh commented 3 years ago

Thank you for your collaboration, I can see the new version, but on the same example there is this runtime error "RuntimeError: Unknown exception License file ampl.lic not found anywhere in $PATH. gurobi (Windows AMD64), licchk(20131021), ASL(20190605)"

fdabrandao commented 3 years ago

You need to have the path to the AMPL folder in your environment variable path before importing amplpy_gurobi. You can either set if on your system our do it in python as follows:

import os
os.environ["PATH"] += os.pathsep + r'C:/complete/path/to/ampl_mswin64/'
import amplpy_gurobi as ampls

Please note that this only works if you have an ampl license, it does not work if you have a time-limited bundle.

fdabrandao commented 3 years ago

Version 0.1.0b17 of amplpy_gurobi and amplpy_cplex now work with both license files and time-limited bundles.