# How to use GAMS with Octeract Engine

## Get Started

Would you like to solve a problem using GAMS? Let us take you through the steps.

### GAMS on Windows

Our section on solving your first problem has everything you need to get up and running. After going through this section, you’ll have:

Whether GAMS is your go-to modelling language or you’re keen to try it out, we’ve got a breakdown of how to use it with the Engine. Let’s take it one step at a time.

To download the language, you’ll need to go to the GAMS downloads page. Select MS Windows from the Platform options. A licence agreement pop-up window will appear. Click download. An executable file will be downloaded to your PC. To install, double click the file and the installer will start running. Choose either GAMS Studio or GAMS IDE in the installer. In this tutorial, we’ll be using GAMS Studio.

### Step 2: Get a Demo Licence

Before you go any further, scroll down the GAMS downloads page to where you see “Request a Free Demo License”. In order to use GAMS, you’ll need to complete this form. Once you’ve submitted your request, you’ll get an email from GAMS with the licence.

### Step 3: Add the Engine as a Solver in GAMS

To do this, locate the file gmscmpNT.txt in the GAMS folder on your PC. Open it with text editor. Copy the snippet below and paste it in the file. Save the file. Now go to where the Engine was installed on your PC. Locate the bin folder. Go inside it and copy file libocteract.dll and paste it in the GAMS folder.

OCTERACT 111 0 0001020304 1 0 2 LP MIP RMIP NLP MCP MPEC RMPEC CNS DNLP RMINLP MINLP QCP MIQCP RMIQCP EMP
gmsgennt.cmd
gmsgennx.exe
libocteract.dll oct 1 0


### Step 4: Write a Model in GAMS

GAMS has two different interfaces: GAMS Studio and GAMS IDE. You either write your model directly in one of the interfaces or in text editor. In this tutorial, we’ll be using a text editor, Notepad. Copy and paste the snippet below to create a model in your session. Then save the model as my_example.gms

$offdigit *Declare variables VARIABLES x1,x2,x3,x4,x5; VARIABLES objvar; *Declare equations (such as constraints, etc) EQUATIONS con1,objeqn; *Define what the equations declared above are equal to con1 .. 4*x5+11*x3+7*x4+12*x2+20*x1+0=L=40; objeqn .. (-50*(x5)**(2))+(-50*(x3)**(2))+(-50*(x2)**(2)) +(-50*(x1)**(2))+(-50*(x4)**(2))+47.5*x5+45*x3+ 47*x4+44*x2+42*x1+0 - objvar =E= 0; * set non default upper bounds x1.up = 1; x2.up = 1; x3.up = 1; x4.up = 1; x5.up = 1; * set non default lower bounds x1.lo = 0; x2.lo = 0; x3.lo = 0; x4.lo = 0; x5.lo = 0; *declare the model name and state that all equations should be included as part of it Model m / all /; m.limrow=0; m.limcol=0;$if NOT '%gams.u1%' == '' $include '%gams.u1%' *set Octeract as the solver to solve the problem option nlp=octeract; *state the model will be solved using the defined NLP solver and minimising the objective function Solve m using NLP minimizing objvar; ### Step 5: Solve the Model In GAMS Studio or GAMS IDE, open the saved file. Once the file is loaded in GAMS, run the problem. To do this in GAMS Studio, press the green arrow. In GAMS IDE, press the button with the file and red arrow. The problem will now be solved. You can see how the solution will be displayed in either interface below. A more detailed version of the solution is written and stored on your PC. You’ll be able to access it by using the path in the line “Solution file written to:”. From there, you can view the solution file (.octsol) in text editor. ### And that’s it – you’re all done!You’ve just solved a problem using GAMS. Would you like to try solving with AMPL on Windows? We can walk you through it. ### GAMS on Linux In our section on getting started, you’ll find all information you need to get up and running. Once you’ve gone through the guide, you’ll have: Let’s solve a problem usings GAMS and the Engine. ### Step 1: Download GAMS To download this modelling language, you’ll need to go to the GAMS downloads page. From the list of platform options, choose Linux. A licence agreement pop-up will appear. Click download. A file will be downloaded to your PC. To check that this file has “execute permission”, open a Shell session and insert the command found in the snippet below. From here, choose a location for the GAMS directory. The GAMS installer will create a subdirectory.  chmod 755 linux_x64_64_sfx.exe ### Step 2: Get a Demo Licence Before you go any further, scroll down the GAMS downloads page to where you see “Request a Free Demo License”. In order to use GAMS, you’ll need to complete this form. Once you’ve submitted your request, you’ll get an email from GAMS with the licence. ### Step 3: Install GAMS To create a directory that contains the GAMS system directory, type the command mkdir /gams in your Shell session. You’ll need to include the entire path where you want the folder to be created. For example: mkdir /Users/Octeract/gams. Change to this directory by using the cd command and ensure the name of directory is returned correctly by typing pwd. Now you can run the executable file by providing the whole path where it can be found. You’ll find an example in the snippet. To start the installation, go into the GAMS installation folder and run ./gamsinst Follow the instructions on the Shell session during the installation. Once the installation is completed, add the licence file you received in the newly created GAMS folder. mkdir /c/Users/Octeract/gams cd /gams pwd /c/Users/Octeract/Downloads/linux_x64_64_sfx_.exe cd /gams31.2_linux_x64_64_sfx ./gamsinst ### Step 4: Include the Engine as a Solver in GAMS To do this, go to where the Engine was installed on your PC and locate the bin folder. In this folder, you’ll find a file called install-for-gams. Run it. You’ll then be prompted to provide the whole path where GAMS is installed. You’ll find an example in the snippet below. Once you’ve done this, the process of adding the Engine to GAMS will begin. You’ll see a message in your Shell session when the Octeract library is installed in the GAMS directory. cd /octeract/bin ./install-for-gams c/Users/Octeract/gams/gams24.3_linux_x64_64_sfx ### Step 5: Write a Model in GAMS In this tutorial, we’ll write the model in text editor. Copy and paste the snippet below to create a model in your session. Then save the model as my_example.gms $offdigit

*Declare variables
VARIABLES x1,x2,x3,x4,x5;

VARIABLES objvar;

*Declare equations (such as constraints, etc)
EQUATIONS con1,objeqn;

*Define what the equations declared above are equal to
con1    ..  4*x5+11*x3+7*x4+12*x2+20*x1+0=L=40;

objeqn  ..  (-50*(x5)**(2))+(-50*(x3)**(2))+(-50*(x2)**(2))
+(-50*(x1)**(2))+(-50*(x4)**(2))+47.5*x5+45*x3+
47*x4+44*x2+42*x1+0 - objvar =E= 0;

* set non default upper bounds
x1.up     = 1;
x2.up     = 1;
x3.up     = 1;
x4.up     = 1;
x5.up     = 1;

* set non default lower bounds
x1.lo     = 0;
x2.lo     = 0;
x3.lo     = 0;
x4.lo     = 0;
x5.lo     = 0;

*declare the model name and state that all equations should be included as part of it
Model m / all /;

m.limrow=0; m.limcol=0;

$if NOT '%gams.u1%' == ''$include '%gams.u1%'

*set Octeract as the solver to solve the problem
option nlp=octeract;

*state the model will be solved using the defined NLP solver and minimising the objective function
Solve m using NLP minimizing objvar;

### Step 6: Solve the Modelin GAMS

To solve the model, navigate to where GAMS was installed using the whole path. For example: c/Users/Octeract/gams/gams24.3_linux_x64_64_sfx. You can run the problem from there using the command in the snippet below. The whole path to where the example file was saved needs to be included in the command. You’ll be able to see the Engine running in the Shell session.

./gams /whole/path/to/where/my_example.gms

A more detailed version of the solution is written and stored on your PC. You’ll be able to access it by using the path in the line “Solution file written to:”. From there, you can view the solution file (.octsol) in text editor.

### And that’s it – you’re done!You’ve just solved a problem using GAMS.

Would you like to try solving with AMPL on Linux? We can walk you through it.