cagdxrw.gms : Test Connect agent GDXReader/Writer

Description

This test ensures the correctness of the Connect agent "GDXReader/Writer".

Contributor: Michael Bussieck, March 2022


Small Model of Type : GAMS


Category : GAMS Test library


Main file : cagdxrw.gms

$title 'Test Connect agent GDXReader/Writer' (CAGDXRW,SEQ=891)

$ontext
This test ensures the correctness of the Connect agent "GDXReader/Writer".

Contributor: Michael Bussieck, March 2022
$offtext


* On the major platforms (Windows, Linux, Mac), GMSPYTHONLIB gets automatically set 
* to use the internal Python installation in sysdir/GMSPython.
$if not setEnv GMSPYTHONLIB $abort.noError Embedded code Python not ready to be used
$log --- Using Python library %sysEnv.GMSPYTHONLIB%

$onEcho > t.gms
Set inew(*) canning plants /
'seattle',
'san-diego' /;

Set j(*) markets /
'new-york',
'chicago',
'topeka' /;

Parameter anew(*) capacity of plant i in cases /
'seattle' 350,
'san-diego' 600 /;

Parameter b(*) demand at market j in cases /
'new-york' 325,
'chicago' 300,
'topeka' 275 /;

Parameter d(*,*) distance in thousands of miles /
'seattle'.'new-york' 2.5,
'seattle'.'chicago' 1.7,
'seattle'.'topeka' 1.8,
'san-diego'.'new-york' 2.5,
'san-diego'.'chicago' 1.8,
'san-diego'.'topeka' 1.4 /;

Scalar f freight in dollars per case per thousand miles / 90 /;

positive Variable xnew(*,*) shipment quantities in cases /
'seattle'.'new-york'.L 50,
'seattle'.'chicago'.L 300,
'seattle'.'topeka'.M 0.036,
'san-diego'.'new-york'.L 275,
'san-diego'.'chicago'.M 0.009,
'san-diego'.'topeka'.L 275 /;

Equation supplynew(*) observe supply limit at plant i /
'seattle'.L 350,
'seattle'.M Eps,
'seattle'.LO -Inf,
'seattle'.UP 350,
'san-diego'.L 550,
'san-diego'.LO -Inf,
'san-diego'.UP 600 /;
$offEcho
$call.checkErrorLevel gams t.gms lo=%gams.lo% a=c gdx=ctgdxref.gdx

$onEchoV > t.gms
Set
   i 'canning plants'
   j 'markets';
Parameter
   a(i)   'capacity of plant i in cases'
   b(j)   'demand at market j in cases'
   d(i,j) 'distance in thousands of miles';
Scalar
   f      'freight in dollars per case per thousand miles';
Variable
   x(i,j) 'shipment quantities in cases';
Equation
   supply(i) 'observe supply limit at plant i';  

$ifThenI %MODE%==gdxin
$gdxin ctgdxref
$load i=inew j a=anew b d f x=xnew supply=supplynew
$elseIf %MODE%==ecreadall
$onEmbeddedCode Connect:
- GDXReader:
    file: ctgdxref.gdx
    readAll: True
- GAMSWriter:
    symbols:
      - name: inew
        newName: i
      - name: j
      - name: anew
        newName: a
      - name: b
      - name: d
      - name: f
      - name: xnew
        newName: x
      - name: supplynew
        newName: supply
- GDXWriter:
    file: ctgdxout1.gdx
    symbols:
      - name: inew
        newName: i
      - name: j
      - name: anew
        newName: a
      - name: b
      - name: d
      - name: f
      - name: xnew
        newName: x
      - name: supplynew
        newName: supply
$offEmbeddedCode
$else
$onEmbeddedCode Connect:
- GDXReader:
    file: ctgdxref.gdx
    symbols:
      - name: inew
        newName: i
      - name: j
      - name: anew
        newName: a
      - name: b
      - name: d
      - name: f
      - name: xnew
        newName: x
      - name: supplynew
        newName: supply
- GAMSWriter:
    writeAll: True
- GDXWriter:
    file: ctgdxout2.gdx
    writeAll: True
$offEmbeddedCode    
$endif
$offEcho
$call.checkErrorLevel gams t.gms lo=%gams.lo% --MODE=gdxin     gdx=1.gdx
$call.checkErrorLevel gams t.gms lo=%gams.lo% --MODE=ecreadall gdx=2.gdx
$call.checkErrorLevel gams t.gms lo=%gams.lo% --MODE=ecreadsym gdx=3.gdx

$call.checkErrorLevel gdxdiff ctgdxout1.gdx ctgdxout2.gdx > %system.NullFile%
$call.checkErrorLevel gdxdiff ctgdxout1.gdx 1.gdx         > %system.NullFile%
$call.checkErrorLevel gdxdiff ctgdxout1.gdx 2.gdx         > %system.NullFile%
$call.checkErrorLevel gdxdiff ctgdxout1.gdx 3.gdx         > %system.NullFile%