Description of the issue
I have found an issue and have a general question about handling NaN values.
np.nan
values are not interpreted as gp.SpecialValues.NA
Maybe I 'm misunderstanding what gp.SpecialValues.NA
is supposed to represent, but np.nan
values are not interpreted as this. Is this intended, meaning I would have to map np.nan
values to gp.SpecialValues.NA
?
import gamspy as gp
ct = gp.Container()
S = ct.addSet("S", records=["a", "b"])
p1 = ct.addParameter("p1", domain=S, records=np.array([[np.nan, 1]]))
p2 = ct.addParameter("p2", domain=S, records=np.array([[gp.SpecialValues.NA, 1]]))
print(p1.countNA())
print(p2.countNA())
Output:
0
1
Edit: I just realized that the np.nan
value in p1
is considered both “missing” and “undefined” since p1.dropMissing()
and p1.dropUndefined()
both work, removing this np.nan
value. Now I am a bit confused. I would expect that a state of “NA” (not available?) would be implied by both the “missing” and “undefined” states. So in this case I would expect that p1.dropNA()
should lead to the same results as p1.dropMissing()
and p1.dropUndefined()
.
Also, while I understand that there can be a difference between “undefined” and “missing”, I do not understand how there can be a difference between “NA” and “missing”.
General question on handling NaN values
My use case is the following: I have a parameter based on which I want to define variable limits. This parameter is not defined for all set elements, and naturally I do not want to set any limit in the undefined cases. However, since GAMS assumes Parameters to be zero where they are not defined, it would simply set the limit to zero.
How do I circumvent this? My first idea was to explicitly set the Parameter to NaN in the undefined cases and then adding a condition in the assignment requiring the Parameter to not be equal to NaN. But this feels a little backwards and may decrease performance. Is there a better way?
GAMSPy version
1.1.0