\$title 'SELKIE test suite: obj variable setting' (SELKIE16,SEQ=772) \$ontext Test if the value of the objective variable is set correctly after solve. Contributor: Youngdae Kim (11.07.2017) \$offtext \$if not set TESTTOL \$set TESTTOL 1e-4 scalar tol / %TESTTOL% /; file opt / 'selkie.opt' /; file info / '%emp.info%' /; set i / 1*2 /; variable obj(i), x(i); equation defobj(i); defobj(i).. obj(i) =E= sqr(x(i)-1) + 2; model m / defobj /; put info 'equilibrium'; loop(i, put / 'min', obj(i), x(i), defobj(i); ); putclose; putclose opt 'use_mcpopt yes'; m.optfile = 1; option emp = selkie; solve m using emp; abort\$[ smax{i, abs(x.l(i) - 1)} > tol ] 'bad x.l', x.l; abort\$[ smax{i, abs(obj.l(i) - 2)} > tol ] 'bad obj.l', obj.l; \$onecho > agent1_gms Variables x3; Equations dL_dx3; dL_dx3.. (-2*(-1 + x3))/(-1) =E= 0; Model m / dL_dx3.x3 /; Solve m using mcp; \$offecho execute 'cat agent1_gms > agent1.gms.want'; execute 'cat "%gams.scrdir%agent1.gms" > agent1.gms.got'; execute '=diff -bw agent1.gms.want agent1.gms.got'; abort\$errorlevel 'Files agent1.gms.want and agent1.gms.got differ'; \$onecho > agent2_gms Variables x4; Equations dL_dx4; dL_dx4.. (-2*(-1 + x4))/(-1) =E= 0; Model m / dL_dx4.x4 /; Solve m using mcp; \$offecho execute 'cat agent2_gms > agent2.gms.want'; execute 'cat "%gams.scrdir%agent2.gms" > agent2.gms.got'; execute '=diff -bw agent2.gms.want agent2.gms.got'; abort\$errorlevel 'Files agent2.gms.want and agent2.gms.got differ'; obj.l(i) = 0; x.l(i) = 0; putclose opt 'agent_group {{1,2}}'; m.optfile = 1; option emp = selkie; solve m using emp; abort\$[ smax{i, abs(x.l(i) - 1)} > tol ] 'bad x.l', x.l; abort\$[ smax{i, abs(obj.l(i) - 2)} > tol ] 'bad obj.l', obj.l; \$onecho > agent3_gms Variables x3,x4; Equations dL_dx3,dL_dx4; dL_dx3.. (-2*(-1 + x3))/(-1) =E= 0; dL_dx4.. (-2*(-1 + x4))/(-1) =E= 0; Model m / dL_dx3.x3,dL_dx4.x4 /; Solve m using mcp; \$offecho execute 'cat agent3_gms > agent3.gms.want'; execute 'cat "%gams.scrdir%agent3.gms" > agent3.gms.got'; execute '=diff -bw agent3.gms.want agent3.gms.got'; abort\$errorlevel 'Files agent3.gms.want and agent3.gms.got differ'; obj.l(i) = 0; x.l(i) = 0; * Finally, test the case where we have no explicit objective variable. variable y; equation cons; cons.. sqr(y-2) =l= 1; model m2 / defobj, cons /; put info 'equilibrium'; loop(i, put / 'min', obj(i), x(i), defobj(i); ); put / 'min', y, cons; putclose; putclose opt 'use_mcpopt yes'; m2.optfile = 1; option emp = selkie; solve m2 using emp; abort\$[ smax{i, abs(x.l(i) - 1)} > tol ] 'bad x.l', x.l; abort\$[ smax{i, abs(obj.l(i) - 2)} > tol ] 'bad obj.l', obj.l; abort\$[ abs(y.l - 1) > tol ] 'bad y.l', y.l; \$onecho > agent3_y_gms Variables x5,u3; Negative Variables u3; Equations e3,dL_dx5; e3.. sqr((-2) + x5) =L= 1; dL_dx5.. 1 - (2*(-2 + x5))*u3 =E= 0; Model m / e3.u3,dL_dx5.x5 /; Solve m using mcp; \$offecho execute 'cat agent3_y_gms > agent3.gms.want'; execute 'cat "%gams.scrdir%agent3.gms" > agent3.gms.got'; execute '=diff -bw agent3.gms.want agent3.gms.got'; abort\$errorlevel 'Files agent3.gms.want and agent3.gms.got differ';