Notebook Pyampl tuto

#Install package
import sys
!{sys.executable} -m pip install numpy
!{sys.executable} -m pip install matplotlib
!{sys.executable} -m pip install amplpy
from amplpy import AMPL # import pyAMPL
from amplpy import ampl_notebook

ampl = ampl_notebook(
    modules=["cplex"],  # modules to install
    license_uuid="default",  # license to use
)  # instantiate AMPL object and register magics
%%ampl_eval
# define decision variables

reset;

# Declaration of optimization variables
var xx;
var yy;
# Declaration of parameters
param aa=-4;
param bb=2;
%%ampl_eval
# Cost function
minimize f: 
    xx**2 + aa*(xx+yy) + 2*yy**2;
# Constraints
subject to g: xx+yy = bb;
subject to h: xx >= 0;
%%ampl_eval
let xx:= 1;
let yy:=2;
# exhibit the model that has been built
ampl.eval("show;")
ampl.eval("expand;")

# solve using two different solvers
ampl.option["solver"] = "cplex"
ampl.solve()

#ampl.option["solver"] = "highs"
#ampl.solve()
ampl.display("xx");# xx,yy;
ampl.display("f");
ampl.display("g.dual");
ampl.display("h.dual");
Elise Grosjean
Elise Grosjean
Assistant Professor

My research interests include numerics, P.D.E analysis, Reduced basis methods, inverse problems.