!pip install -q amplpy ampltools

"""
Explanation: AMPLPY: Jupyter Notebook Integration


Documentation: http://amplpy.readthedocs.io
GitHub Repository: https://github.com/ampl/amplpy
PyPI Repository: https://pypi.python.org/pypi/amplpy
Jupyter Notebooks: https://github.com/ampl/amplpy/tree/master/notebooks
Setup
End of explanation
"""


MODULES=['ampl', 'gurobi']
from ampltools import cloud_platform_name, ampl_notebook
from amplpy import AMPL, register_magics
if cloud_platform_name() is None:
    ampl = AMPL() # Use local installation of AMPL
else:
    ampl = ampl_notebook(modules=MODULES) # Install AMPL and use it
register_magics(ampl_object=ampl) # Evaluate %%ampl_eval cells with ampl.eval()

"""
Explanation: Google Colab & Kaggle interagration
End of explanation
"""


%%ampl_eval
set SIZES;
param capacity >= 0;
param value {SIZES};
var Qty {SIZES} binary;
maximize TotVal: sum {s in SIZES} value[s] * Qty[s];
subject to Cap: sum {s in SIZES} s * Qty[s] <= capacity;

"""
Explanation: Use %%ampl_eval to pass the model to AMPL
End of explanation
"""


ampl.set['SIZES'] = [5, 4, 6, 3]
ampl.param['value'] = [10, 40, 30, 50]
ampl.param['capacity'] = 10

"""
Explanation: Set data
End of explanation
"""


%%ampl_eval
display SIZES;
display value;
display capacity;

"""
Explanation: Use %%ampl_eval to display values
End of explanation
"""


print('SIZES:', ampl.set['SIZES'].getValues().toList())
print('value:', ampl.param['value'].getValues().toDict())
print('capacity:', ampl.param['capacity'].value())

"""
Explanation: Use amplpy to retrive values
End of explanation
"""


%%ampl_eval
option solver gurobi;
option gurobi_options 'outlev=1';
solve;

"""
Explanation: Use %%ampl_eval to solve the model
End of explanation
"""


