evaluate log(0)

33 views
Skip to first unread message

Mirou

unread,
Jan 12, 2018, 7:44:33 AM1/12/18
to AMPL Modeling Language

I have an error  when i run my code 
error processing constraint dLldev[1]:
	can't evaluate log(0):

param NJ;
param U_mmaxl:=2.8;
param rho:=100;
param J_sowing:=1; 
param J_lev:=22;
param J_amf:=50;
#param J_let;
param J_flo:=142;                    
param J_DRP:=238;                      
param J_lax:=261;
param J_eed:=200;                    
param J_mat:=356;                              
param:  t_th:=
var u_l{1..NJ};
var dL_ldev{1..NJ};
s.t. ul{j in 1..NJ}:u_l[j]= if j< J_lev then 1
                            else if J_lev<=j<J_amf then 1+(u_dev[j]/t_th['amf'])*(U_optl-1)
                            else if J_amf< j <=J_lax then U_optl+((u_dev[j]-t_th['amf'])/(t_th['lax']-t_th['amf']))*(3-U_optl)
                            else 3;

s.t. dLldev{j in 1..NJ}:dL_ldev[j]= if u_l[j] < U_mmaxl then (P_l/(1+exp(Upsilon*(U_optl-u_l[j]))))
                                    else ((1/rho)*log((sum{k in J_sowing+1..j-1} exp(rho*dL_ldev[k])))*(1-((u_l[j]-U_mmaxl)/(3-U_mmaxl)))^2);
                                 

but when j=1 , u_l[1]=1<2.8 do dL_lev[1]= (P_l/(1+exp(Upsilon*(U_optl-u_l[1]))))  then  we will not calculate  ((1/rho)*log((sum{k in J_sowing+1..j-1} exp(rho*dL_ldev[k])))*(1-((u_l[j]-U_mmaxl)/(3-U_mmaxl)))^2).


Thank you for your help

ptiwari

unread,
Jan 12, 2018, 2:57:08 PM1/12/18
to AMPL Modeling Language
AMPL does not calculate else portion when if condition is satisfied. You could test that behavior using a small program in the terminal.

param w := 1;

param x := if w==1 then log(2) else log(0);

display x;


When you execute above statements, x will have log(2) and AMPL doesn't throw error message about log(0). 


You might have some value of 'j' that doesn't satisfy the 'if' condition and else condition is executed, which might throw log(0) error.


Thanks,

Paras 

Mirou

unread,
Jan 12, 2018, 6:56:34 PM1/12/18
to AMPL Modeling Language
Thank you for your reply
but
u_l [*] :=
  1  1          54 -4.98298   107 -4.98298   160 -4.98298   213 -4.98298
  2  1          55 -4.98298   108 -4.98298   161 -4.98298   214 -4.98298
  3  1          56 -4.98298   109 -4.98298   162 -4.98298   215 -4.98298
  4  1          57 -4.98298   110 -4.98298   163 -4.98298   216 -4.98298
  5  1          58 -4.98298   111 -4.98298   164 -4.98298   217 -4.98298
  6  1          59 -4.98298   112 -4.98298   165 -4.98298   218 -4.98298
  7  1          60 -4.98298   113 -4.98298   166 -4.98298   219 -4.98298
  8  1          61 -4.98298   114 -4.98298   167 -4.98298   220 -4.98298
  9  1          62 -4.98298   115 -4.98298   168 -4.98298   221 -4.98298
 10  1          63 -4.98298   116 -4.98298   169 -4.98298   222 -4.98298
 11  1          64 -4.98298   117 -4.98298   170 -4.98298   223 -4.98298
 12  1          65 -4.98298   118 -4.98298   171 -4.98298   224 -4.98298
 13  1          66 -4.98298   119 -4.98298   172 -4.98298   225 -4.98298
 14  1          67 -4.98298   120 -4.98298   173 -4.98298   226 -4.98298
 15  1          68 -4.98298   121 -4.98298   174 -4.98298   227 -4.98298
 16  1          69 -4.98298   122 -4.98298   175 -4.98298   228 -4.98298
 17  1          70 -4.98298   123 -4.98298   176 -4.98298   229 -4.98298
 18  1          71 -4.98298   124 -4.98298   177 -4.98298   230 -4.98298
 19  1          72 -4.98298   125 -4.98298   178 -4.98298   231 -4.98298
 20  1          73 -4.98298   126 -4.98298   179 -4.98298   232 -4.98298
 21  1          74 -4.98298   127 -4.98298   180 -4.98298   233 -4.98298
 22 -5.01628    75 -4.98298   128 -4.98298   181 -4.98298   234 -4.98298
 23 -5.01628    76 -4.98298   129 -4.98298   182 -4.98298   235 -4.98298
 24 -5.01628    77 -4.98298   130 -4.98298   183 -4.98298   236 -4.98298
 25 -5.01628    78 -4.98298   131 -4.98298   184 -4.98298   237 -4.98298
 26 -5.01628    79 -4.98298   132 -4.98298   185 -4.98298   238 -4.98298
 27 -5.01628    80 -4.98298   133 -4.98298   186 -4.98298   239 -4.98298
 28 -5.01628    81 -4.98298   134 -4.98298   187 -4.98298   240 -4.98298
 29 -5.01628    82 -4.98298   135 -4.98298   188 -4.98298   241 -4.98298
 30 -5.01628    83 -4.98298   136 -4.98298   189 -4.98298   242 -4.98298
 31 -5.01628    84 -4.98298   137 -4.98298   190 -4.98298   243 -4.98298
 32 -5.01628    85 -4.98298   138 -4.98298   191 -4.98298   244 -4.98298
 33 -5.01628    86 -4.98298   139 -4.98298   192 -4.98298   245 -4.98298
 34 -5.01628    87 -4.98298   140 -4.98298   193 -4.98298   246 -4.98298
 35 -5.01628    88 -4.98298   141 -4.98298   194 -4.98298   247 -4.98298
 36 -5.01628    89 -4.98298   142 -4.98298   195 -4.98298   248 -4.98298
 37 -5.01628    90 -4.98298   143 -4.98298   196 -4.98298   249 -4.98298
 38 -5.01628    91 -4.98298   144 -4.98298   197 -4.98298   250 -4.98298
 39 -5.01628    92 -4.98298   145 -4.98298   198 -4.98298   251 -4.98298
 40 -5.01628    93 -4.98298   146 -4.98298   199 -4.98298   252 -4.98298
 41 -5.01628    94 -4.98298   147 -4.98298   200 -4.98298   253 -4.98298
 42 -5.01628    95 -4.98298   148 -4.98298   201 -4.98298   254 -4.98298
 43 -5.01628    96 -4.98298   149 -4.98298   202 -4.98298   255 -4.98298
 44 -5.01628    97 -4.98298   150 -4.98298   203 -4.98298   256 -4.98298
 45 -5.01628    98 -4.98298   151 -4.98298   204 -4.98298   257 -4.98298
 46 -5.01628    99 -4.98298   152 -4.98298   205 -4.98298   258 -4.98298
 47 -5.01628   100 -4.98298   153 -4.98298   206 -4.98298   259 -4.98298
 48 -5.01628   101 -4.98298   154 -4.98298   207 -4.98298   260 -4.98298
 49 -5.01628   102 -4.98298   155 -4.98298   208 -4.98298   261 -4.98298
 50  3         103 -4.98298   156 -4.98298   209 -4.98298   262  3
 51 -4.98298   104 -4.98298   157 -4.98298   210 -4.98298   263  3
 52 -4.98298   105 -4.98298   158 -4.98298   211 -4.98298   264  3
 53 -4.98298   106 -4.98298   159 -4.98298   212 -4.98298   265  3
;

then stage else is satisfied in j=50,262,263,264,265 then for j=1 he have't any problem with log

ptiwari

unread,
Jan 13, 2018, 3:40:03 PM1/13/18
to AMPL Modeling Language
 It seems that you might need to work on formulation. 

You are using equality constraint. Sometimes, the model is correct even if the equality constraint is replaced by  inequality constraint <= or >=. Inequality constraints are easier to handle than the equality constraints. 
You are using if-else in the constraint and this will make your formulation nonlinear. For example you could rewrite your constraint s.t. ul{j in 1..NJ} as follows:

s.t. ul0{ j in 1... J_lev}: ul[j] <= 1; (if your model is still correct by replacing equality by less than or equal to)  
s.t. ul1{j in J_lev.. J_amf}: ul[j] <= <your expression>
...

You are summing up dl_dev and your output suggests that exponential of the sum will turn to be zero. I think you need to check if you are properly translating your formulation. Sometimes, we might misunderstand the indexes and that makes difference in the formulation.

Mirou

unread,
Jan 26, 2018, 9:16:57 AM1/26/18
to AMPL Modeling Language
thank you very much  i going test that .
Reply all
Reply to author
Forward
0 new messages