After implementation of the optimization model it is often needed to
package the model into a user-friendly software package or to embed the
optimization routines into a larger system. This can mean interfacing
with enterprise databases or desktop office applications. Below we mention
some possible congifurations.
Although these examples are simple, the background machinery to run
GAMS is fairly complex. First it is needed to find out where GAMS
is installed. The path needs to be extended to be able to call
GAMS and to find the needed DLL's. Finally complexities are introduced
to support transparently both GDX file formats of GAMS version 22.5 and
before and of GAMS version 22.6.
These examples can be used as a starting point for implementing a
practical application.
This model implements the calculation of an efficient frontier, as
graph that is used in portfolio theory to depict pareto optimal
portfolio's.
In this application the user can change what investment instruments are
available. When the solve button is pressed a GDX input file is
created, a GAMS model is
solved containing a number of NLP models, and the solution results in
the form
of a GDX file are read back. The graph is then updated to refect
the user specifications. This application is small enough to fit in
the student/demo version of GAMS.
Although this is a small one sheet application, it can be used as the
basis for more complex applications with multiple sheets.
Sub solve() |
This code implements the basic algorithm described above. |
This model requires a valid GAMS and GAMS/Cplex license to run. In this
application we solve a large Sudoku problem using a MIP formulation.
Cplex can solve this (large) model quickly without doing any branch-and-bound
nodes. The presolver solves this model completely.
The spreadsheet uses VBA code to call GAMS and to read and write GDX
files to exchange data with GAMS. The model generated is too large to fit in
the Student/Demo version of GAMS.
Much of the VBA code used in the above examples can be
used when calling GAMS from MS Access. An important extension is to allow for
a progress window, with a multi-line text-box that shows progress by
displaying the log. For longer running jobs it is also important to
introduce an Interrupt (Ctrl-C) and Stop (Ctrl-Break) facility. We
have implemented this using Access as shown in the picture above. This
approach can also be used in an Excel based application.
| Code to interrupt a long running GAMS job. The low-level code to handle the code-injection and the remote-thread management is implemented as a C DLL callable by VBA. |
Private Declare Function GamsInterrupt Lib "gamsinterrupt.dll" _ |
$if not set db $error db is not set set i 'cities'; |
Passing data from Access to GAMS is very easy with MDB2GMS. We can use this GAMS code to handle this. The %db% macro can be passed on to GAMS via the command line. |
The complete example has a main menu with some buttons, a progress window described above and a report
window displaying the traveling salesman tour or the minimum spanning tree as found by the optimization model.
The basic architecture as demonstrated in this mini-application has been used in several commercial systems.
Here are some examples: