$title 'Test implicit/explicit loading in Embedded Code' (EMBPY12,SEQ=896) $onText This test ensures that $onECImplicitLoad/$offECImplicitLoad behaves correctly with Embedded Code Python Contributor: Clemens Westphal, February 2022 $offText $log --- Using Python library %sysEnv.GMSPYTHONLIB% set s1(*), s2(*); * Load sets implicitly $onECImplicitLoad $onEmbeddedCode Python: gams.set('s1', ['i1', 'i2', 'i3']) gams.set('s2', ['j1', 'j2', 'j3']) $offEmbeddedCode $onEmbeddedCode Python: if list(gams.get('s1')) != ['i1', 'i2', 'i3']: raise Exception("Unexpected Data in symbol s1") if list(gams.get('s2')) != ['j1', 'j2', 'j3']: raise Exception("Unexpected Data in symbol s2") $offEmbeddedCode $if not errorfree $abort "Unexpected data" * Load sets explicitly $clear s1 s2 $onMulti $onEmbeddedCode Python: gams.set('s1', ['i1', 'i3']) gams.set('s2', ['j1', 'j3']) $offEmbeddedCode s1 s2 $onEmbeddedCode Python: if list(gams.get('s1')) != ['i1', 'i3']: raise Exception("Unexpected Data in symbol s1") if list(gams.get('s2')) != ['j1', 'j3']: raise Exception("Unexpected Data in symbol s2") $offEmbeddedCode $if not errorfree $abort "Unexpected data" $offMulti * Mix implicit and explicit loading $clear s1 s2 $onMulti $onEmbeddedCode Python: gams.set('s1', ['i1', 'i2', 'i3']) gams.set('s2', ['j1', 'j2', 'j3']) $offEmbeddedCode s2 $onEmbeddedCode Python: if list(gams.get('s1')) != ['i1', 'i2', 'i3']: raise Exception("Unexpected Data in symbol s1") if list(gams.get('s2')) != ['j1', 'j2', 'j3']: raise Exception("Unexpected Data in symbol s2") $offEmbeddedCode $if not errorfree $abort "Unexpected data" $offMulti * Load parameter implicitly parameter p1(s1, s2); $onEmbeddedCode Python: s1 = gams.get('s1') s2 = gams.get('s2') p1 = [(i, j, 3.14) for i,j in zip(s1, s2) ] gams.set('p1', p1) $offEmbeddedCode $onEmbeddedCode Python: if list(gams.get('p1', keyFormat=KeyFormat.FLAT)) != p1: raise Exception("Unexpected Data in symbol p1") $offEmbeddedCode $if not errorfree $abort "Unexpected data" * Load domain set implicitly $onMultiR $clear s1 s2 $onEmbeddedCode Python: s1 = ['i1', 'i2', 'i3'] s2 = ['j1', 'j2', 'j3'] gams.set('s1', s1) gams.set('s2', s2) p1 = [(i, j, 3.14) for i,j in zip(s1, s2) ] gams.set('p1', p1) $offEmbeddedCode $onEmbeddedCode Python: if list(gams.get('s1')) != ['i1', 'i2', 'i3']: raise Exception("Unexpected Data in symbol s1") if list(gams.get('s2')) != ['j1', 'j2', 'j3']: raise Exception("Unexpected Data in symbol s2") $offEmbeddedCode $if not errorfree $abort "Unexpected data" $offMulti * Generate a domain violation with implicit loading and DomainCheckType.CHECKED $clear p1 $onMulti $onEmbeddedCode Python: p1 = [('i4', 'j1', 3.14)] gams.set('p1', p1, domCheck=DomainCheckType.CHECKED) $offEmbeddedCode $if errorfree $abort "Expected domain violation" $clearError $onEmbeddedCode Python: if len(list(gams.get('p1'))): raise Exception("Unexpected Data in symbol p1") $offEmbeddedCode $if not errorfree $abort "Unexpected data" $offMulti * Generate a domain violation with implicit loading and $offFiltered $clear p1 $onMulti $offFiltered $onEmbeddedCode Python: p1 = [('i4', 'j1', 3.14)] gams.set('p1', p1) $offEmbeddedCode $if errorfree $abort "Expected domain violation" $clearError $onFiltered $onEmbeddedCode Python: if len(list(gams.get('p1'))): raise Exception("Unexpected Data in symbol p1") $offEmbeddedCode $if not errorfree $abort "Unexpected data" $offMulti * Load a set implicitly by setting the alias set s3(*); alias(s3, s3_alias); $onEmbeddedCode Python: gams.set('s3_alias', ['i1', 'i2', 'i3']) $offEmbeddedCode $if not errorfree $abort "Problem with alias" * Load implicitly using the projection operator set s4; parameter p2(s4); $onEmbeddedCode Python: gams.set('p2', [('i1', 3.14), ('i2', 3.14)]) $offEmbeddedCode s4