Ampl
Introduction
In this example, we will explore how to submit an AMPL program to Multivac to compute a simple objective function.
Example Code
Suppose we want to minimize the following objective function:
We will create a file named test_ampl.mod to compute the objective function value for a specific value of x:
# minimitzacio.mod
# Define the decision variable
var x;
# Define the objective function
minimize obj: x^2 + 3*x + 2;
# Define the constraint: x must be equal to 5
s.t. restriccio_x: x = 5;
# Solve the problem
solve;
# Show results
display x;
display obj;
This code defines the objective function, assigns a specific value to x (in this case, 5), and computes the objective function result for that value.
We will create a .dat file, for example test_ampl.dat, containing the input variables:
# minimitzacio.dat
# No input data is required for this example
Execution
We will create a configuration file, for example test_ampl.slurm, containing the execution settings for this AMPL script.
VERSION=1.3
JOB_NAME=ampl_example
NAME_OUTPUT=out
PARTITION=all
N_TASKS=1
CPUS_PER_TASK=1
MAIL_TYPE=END,FAIL
MAIL_USER=nom.usuari@upc.edu
MEMORY=1G
BEGIN=now
TIME_LIMIT=00:05:00
LOG_OUTPUT=log
FORCED_NODES=
EXCLUDED_NODES=
ROUTE=~/
COMMANDS=(
"hostname" # To know which machine executed the job
"/opt/ampl.linux-intel64/ampl test_ampl.mod test_ampl.dat"
)
We will submit this script from ``iocex`` using the following command:
multivac test_ampl.slurm
Once execution is complete, the output of our program will be visible in the same directory where the job was launched.