|
GAMS part of implementation |
Top Previous Next |
|
There is also a base GAMS model underlying this application which is listed below
SETS Supply Locations of supply points Demand Location of Demand markets; $Call 'Gdxxrw Excelincharge.XLS skipempty=0 trace=2 index=inputs!g10' $gdxin excelincharge.gdx $Load supply demand set tranparm parameters of transport rate function /fixed, permile/ PARAMETERS Available(supply) Supply available in cases Needed(demand) demand requirement in cases Distance(supply,demand) distance in thousands of miles tranrate(tranparm) transport rate data; $Load available needed distance tranrate $gdxin PARAMETER Cost(supply,demand) transport cost in thousands of dollars per case ; Cost(supply,demand) = tranrate("Fixed") + tranrate("permile") * Distance(supply,demand) / 1000 ; positive VARIABLES ship(supply,demand) shipment quantities in cases variable Z total transportation costs in thousands of dollars ; EQUATIONS COSTacct define objective function SUPPLYbal(supply) observe supply limits at sources DEMANDbal(demand) satisfy demand requirements at markets ; COSTacct .. Z =E= SUM((supply,demand), Cost(supply,demand)*ship(supply,demand)) ; SUPPLYbal(supply) .. SUM(demand, ship(supply,demand)) =L= Available(supply) ; DEMANDbal(demand) .. SUM(supply, ship(supply,demand)) =G= needed(demand) ; MODEL TRANSPORT /ALL/ ; SOLVE TRANSPORT USING LP MINIMIZING Z ; parameter misc(*); misc("cost")=z.l; misc("modelstat")=transport.modelstat; Execute_Unload 'excelincharge.gdx',ship, supplybal, demandbal, misc; Execute 'Gdxxrw Excelincharge.gdx skipempty=0 zeroout=0 trace=2 index=results!e1'
This code goes through several notable stages in terms of the Excel in charge application.
Function optstatus() As String Dim oResults As Range, oX As Range, nj As Integer, stat As Integer Set oResults = Worksheets("Results").Range("A1").CurrentRegion ' for each production center, update the results stat = 0 For nj = 2 To oResults.Rows.Count If Trim(UCase(oResults.Cells(nj, 1))) = "MODELSTAT" Then stat = oResults.Cells(nj, 2) End If Next optstatus = "Unknown I cant find model stat" If stat > 0 Then Select Case stat Case 1 optstatus = "Optimal" Case 2 optstatus = "Optimal" Case 3 optstatus = "Unbounded" Case 4 optstatus = "Infeasible" Case Else optstatus = "Bad Result from GAMS" End Select End If End Function
|