$LOADDC domain violation as output Topic is solved

Problems with syntax of GAMS
Post Reply
pitters
User
User
Posts: 9
Joined: 4 months ago

$LOADDC domain violation as output

Post by pitters » 1 month ago

Hi!

Do you know of a way to output the domains violations in a txt or csv file?

Being more specific, I have two sets, set_db and set_nondb

set_db should have all elements
set_nondb should have only elements from db but in ocacions there will be new elements and we need to capture them.

Sets:
set_db
set_nondb(set_db)

Then, when loading the data..

$GDXIN somefile.gdx
$LOAD set_db
$LOADDC ser_nondb
$GXDIN

When set_nondb contains elements that are missing from sets_db an error will ocurr, I would like to output all the missing elements (no only the first 10) in a txt csv file, on that error

Any ideas?

User avatar
bussieck
Moderator
Moderator
Posts: 645
Joined: 5 years ago

Re: $LOADDC domain violation as output

Post by bussieck » 1 month ago

$loadDC puts the domain violations into the listing file only. If you want more control, you can program this as follows. Basically, if you find out that you had errors you call a sub GAMS job that reads both sets under the universe and then writes out the elements in set_nondb that are not in set_db:

Code: Select all

* Create GDX file
$echo set set_db / 1*10 /, set_nondb / 5*15 /; > mkgdx.gms
$call.checkErrorLevel gams mkgdx.gms lo=2 gdx=somefile

set set_db, set_nondb(set_db);
$gdxIn somefile
$load set_db
$loadDC set_nondb
$ifThen not errorFree
$ onEcho > printDV.gms
  set set_db, set_nondb;
  $$gdxIn somefile
  $$load set_db set_nondb
  file fx / 'dv.txt' /; put fx 'Domain violations for set_nondb:'; alias (*,u);
  loop(set_nondb, if (not set_db(set_nondb), put / set_nondb.tl ' is not contained in set_db'));
$ offEcho
$ call.checkErrorLevel gams printDV.gms lo=2
$ call cat dv.txt
$endif
For this example, dv.txt looks as follows:

Code: Select all

Domain violations for set_nondb:
11           is not contained in set_db
12           is not contained in set_db
13           is not contained in set_db
14           is not contained in set_db
15           is not contained in set_db
-Michael

pitters
User
User
Posts: 9
Joined: 4 months ago

Re: $LOADDC domain violation as output

Post by pitters » 1 month ago

Thanks Michael!

I implemented this and it help a lot!

I have two questions tho,

Whats the purpose of 'lo=2' in:
$ call.checkErrorLevel gams printDV.gms lo=2

Why did u alias the universal set?

User avatar
bussieck
Moderator
Moderator
Posts: 645
Joined: 5 years ago

Re: $LOADDC domain violation as output

Post by bussieck » 1 month ago

lo=2 means sending the GAMS log to a file instead of to stdout/console, see https://www.gams.com/latest/docs/UG_Gam ... Ologoption for details. No need for the alias(*,u) statement. I thought I need that, but I didn't and forgot to delete.

-Michael

Post Reply