|
Calling GAMS out of Excel requires some more work than just exchanging data with Excel. The application has to:
Using VisualBasic for Applications (VBA) this can be implemented with a few lines of code:
Sub solve() Dim WorkDir As String WorkDir = TempDir() Call ClearSolution If (Not AddGAMSPath()) Then ' needed to find gdxio.dll and gams.exe Exit Sub End If Call ExportGDXFile(WorkDir) Call WriteGAMSModel(WorkDir & "portfolio.gms") Call RunGAMS(WorkDir & "portfolio.gms", WorkDir) Call ReadListing(WorkDir & "portfolio.lst") Call ImportGDXFile(WorkDir) End Sub
For further details, please inspecte the VBA part of the examples below.
This very simple example shows how GAMS can be invoked from an Excel spreadsheet. The example spreadsheet has a button, which will cause GAMS to run the trnsport.gms model stored in c:/tmp. There is no data exchange.
A more complete application will write an include file for a GAMS model, and will import a comma delimited file with results when the run is finished. An example of such a complete application is described in http://www.gams.com/mccarl/excelgams.pdf.
This spreadsheet is a complete example that uses GDX files to exchange information solves a 25×25 Sudoku problem using CPLEX. You will need a GAMS/CPLEX license to be able to run the spreadsheet. The MIP model solves very easily: the solution is found in the presolve phase.
Note: This spreadsheet requires distribution 22.6 or younger to work properly. If you are using an older distribution, please download this one.