Table of Contents
Writing a GUI (Graphical User Interface) for a GAMS application requires some serious programming, and therefore place a burden on the knowledge and time of the modeler. In this section we show how extremely simple user interfaces can be built using a few simple tools. The main purpose of these tools is to allow a developer quickly put an application together such that an end-user does not have to edit GAMS files. We assume the end-user runs a GAMS model from the GAMS-IDE.
The ASK utility can be used to get input from an end-user and the GDXViewer tool can be used to present end-results. Together these tools allow you to build a minimalist GUI without any programming.
where the options are
stringidentifies the type of input item to go after and can be
integer- when one wants an integer number
float- when one wants a real number
radiobutton- when one wants a radio button choice
combobox- when one wants a combo (drop down choice) box
checklistbox- when one wants a check list box
fileopenbox- when one wants the name of a file to open
filesavebox- when one wants the name of a file to save
stringis the text to in the box.
M="Enter a number"
filenameis the name of a file in which to place the results for subsequent inclusion into GAMS
D="string 1|string 2..."
where the "string 1|string 2|string 3|...|string n" gives the n strings to be associated with multiple choices when using checkbox, radiobutton, combobox, or checklistbox. The individual strings are separated by the delimiter "|"
D="Small data set|Medium data set|Large data set"
E="number 1|number 2..."
where the "number 1|number 2|number 3|...|number n" gives the n numbers to be returned to GAMS associated with the choices made when using checkbox, radiobutton, combobox, or checklistbox. The individual numbers are separated by the delimiter "|"
filepathgives the path in which to look for the file under the fileopenbox and filesavebox dialogues. If not specified this is the project directory
filemaskgives the mask for acceptable files under the fileopenbox and filesavebox dialogues. If not specified this is *.*.
stringgives a line of GAMS code to place in the include file.
This can contain a s parameter in which the information to return is substituted
Example: R="$include '%s'" or R="set i /1990*%s/;"
A title for the dialogue box being used
C="Box to ask for a file"
numbergives a lower bound on a numeric entry
numbergives an upper bound on a numeric entry
filenamegives the name of a file of input instructions containing the options above in this table
In addition a number by itself can be entered to put multiple entries into columns under the
The ASK utility is a simple tool to ask simple interactive questions to the end-user. For instance, if your model requires a scalar to be changed regularly, instead of letting the end-user change the
.gms source file, it may be better to pop up a window, with a question text, where the required number can be entered. The ASK tool allows you to do this. As the ASK tool generates a standard GAMS include file, this file can then be used through a
$call statement will invoke the ASK tool. If
ASK.EXE is not located in the GAMS system directory but placed somewhere else you may have to provide a path, as in:
T=integer indicates we want to ask for an integer number (
T means type). The parameter
M="text" specifies the question text. Finally
O=filename sets the name of the include file that ASK should create.
When we run this GAMS fragment from the IDE, we will see:
After enter a number and hitting the OK button GAMS will continue. The listing file will demonstrate clearly how the include file was formed:
In this case
12 was entered and the
OK button was pressed. If the user pressed the
CANCEL button, an error will be generated and the listing file will show that the
CANCEL button was pressed:
In case you want to limit the integer that the user is allowed to enter you can specify a lower and an upperbound as in:
This will only accept values between
To allow the user to specify a floating point number, we can use
T=float. An example is:
The floating point popup window can be told to make sure the number entered is within certain bounds, using the
Up to now, the include file generated by ASK just contained a single number. ASK can generate mode complicated include files. Consider the example:
R="resultstring" are new. The caption is simple: it sets the name of the window. The result string is a string that is returned after ASK has substituted
s for the result. I.e. if we enter
1991, then the result written to the include file is
set i /1990*1991/;.
The listing file can be used to check the correct behavior:
Radio buttons can be used through the parameter
T=radiobuttons as in:
D="option 1|option 2|option 3|option 4|option 5" specifies the text of the options shown. The list
E="1|2|3|4|5" gives the return (exit) strings when a certain option is chosen. I.e. if the second option os chosen in the list specified with the
D parameter, then the second string in the
E list is returned. The result is again substituted in the string specified in the
R parameter if it exists.
In this example the command line became rather long and difficult to handle. In addition some Windows systems have restrictive maximum lengths for the command line. Therefore we offer the possibility to specify the command line arguments in a separate external text file. This text file is passed using
. Assume the file
ask.opt looks like:
Every command line parameter is specified on a separate line. Notice the strange option
2; this tells ASK to display the radio buttons in two columns. We can use this option file as follows:
The quotes around the filename are optional, and really only needed if the filename contains blanks.
If you want to keep all the logic in one place, then one can use GAMS to generate the option file. It is noted that it is not possible to use the PUT facility for this. I.e.:
is not correct: the
$call is handled at compile time, before the
PUT statement has done its work. However, one could use the following:
The next type is
T=combobox which also allows a single selection:
As an example consider the case where the model comes with three data sets: a small one, a medium sized one and a large data set. Each data set is stored in a separate include file:
large.inc. We want to ask the user which data set should be used and the correct include file should be used. This can be accomplished by:
Newer GAMS systems allow:
In this case
dataset.inc will contain a single line: another include statement, which is either
$include medium.inc or
In some cases it may be useful to be able to select multiple items from a list. This can be done with
Selecting multiple entries involves holding down the CTRL key. Sometimes a convenient alternative is
When we select options
5, the following include file is generated:
which will populate the set
k2 as follows:
The last type is the generic string type:
T=string. This allows the user to enter any string, which is then copied to an include file as is.
T=fileopenbox will display a file open dialog box from which the user can select a file.
Related options are
F=Filter. A complete example to ask for an include file could be:
This will open a file open dialog box with the starting directory being the
GAMS project/working directory (this is also where GAMS looks for include files by default). Only files with mask
SELECT*.INC are shown. The file
FLN.INC will contain an include statement with the file the user has selected.
A related method would be:
where we use a
$setglobal to set the macro incfile to contain the user-specified file name.
To let the user choose from a set of related GDX files, one could use something like:
In case you want to ask for a filename of a file to be written, use the type
In case you want to ask for a directory, use the type
T=selectdirectory. In this case the filter option
F is ignored. E.g.: