Properly formulating NLP - syntax issues

Problems with syntax of GAMS
Post Reply
cds169
User
User
Posts: 1
Joined: 5 years ago

Properly formulating NLP - syntax issues

Post by cds169 »

Hi,

I am relatively new to GAMS and am stuck on how to formulate a NLP I am working on. So far I have read through the https://www.gams.com/latest/docs/UG_NLP ... tions.html docs which have helped with a few bugs but one remains. I am getting a FUNC DOMAIN: x**y, x < 0 error in the objective function when I should not be. See below for the code. Here is the strange part, if I remove the "logsum" portion (the denominator) in the objective function the program complies just fine (no exponentiation error) but when I include the logsum variable in the denominator the error occurs. I have tried flipping the sign of beta and putting that portion of the obj function in the denominator but that doesn't help.

Code: Select all

set c column lables /ID, work_dist, income, hhsize, sales_price, unit_sqft, sum_residential_unit, avg_unit_sqft, avg_lot_sqft, l_sales_price, l_unit_sqft, fixed_portion, dist_from_min, b1, b2, b3, row, row_and_ID/
    i row lables /i1*i1000/

alias(i,k);

parameter p(i,c);
*$call GDXXRW df_10k_1.xlsx trace=3 par=p rng=Sheet1!a1:s1000 cdim=1 rdim= 1 
$GDXIN df_10k_1.gdx
$LOAD p
$GDXIN

free variable profit;
parameter
b3(i)
fixed_portion(i)
sales_price(i);

b3(i) = p(i,'b3');
fixed_portion(i) = p(i,'fixed_portion');
sales_price(i) = p(i,'sales_price');

positive variables subsidy(i) 'subsidy';
subsidy.lo(i) = .0001;

variable logsum;
logsum.lo = .001

scalar budget_constraint /10000/;
scalar beta /-0.114/;
scalar J /1000/;

equations
obj
denom
eq1(i)
eq2(i)
;

denom.. logsum =e= sum(k, fixed_portion(k) * (sales_price(k)-subsidy(k))**beta);
obj..profit =e= sum(i, ((b3(i)  - subsidy(i)) * fixed_portion(i)* (sales_price(i)-subsidy(i))**beta) / logsum);
eq1(i).. subsidy(i)=l= budget_constraint;
eq2(i).. subsidy(i)=g= 0;


Model subsidy_opt_test /All/;

option optCR = 1e-6, optCA =1e-6;

solve subsidy_opt_test using NLP maximizing profit;
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: Properly formulating NLP - syntax issues

Post by bussieck »

It's seems not a compilation error but anb evaluation error during the solve. Just from the algebra, there is nothing that prevents the solver to move the variables so that sales_price(k)-subsidy(k) becomes negative. Sure the point is probably not optimal, probably not even feasible, but the solver should be able to evaluate all points with variables between their bounds. So why don't you set an upper bound on subsidy(k) so that this won't happen? The model seems non-convex. Have you tried a global solver?

-Michael
Post Reply