Forum Discussion
FICO
5 years agoCommunity Manager
How to debug E-108: Logical expression expected here for If statement.
I am trying to minimize the absolute difference between some value dependent on "g" and some constant. I have attached some partial code that I would like to fix. The thing is that I just don't understand why `Points_Total(g) - mean_points >= 0` is not considered a logical expression.
forall(g in Groups) Points_Total(g):= sum(n in Nations) Groupings(g,n)*Points(n)
mean_points := (sum(g in Groups) Points_Total(g))/8
forall(g in Groups) do
if Points_Total(g) >= mean_points then
points_diff(g) := Points_Total(g) - mean_points
else
points_diff(g) := mean_points - Points_Total(g)
end-if
end-do
total_error := sum(g in Groups)(points_diff(g))6 Replies
- FICOCommunity Manager
Could you share the declaration of the different arrays and scalars that are used in your code extract?
- FICOCommunity Manager
declarations Groups = 1..8 Nations: set of string Points: array(Nations) of real Groupings: array(Groups, Nations) of mpvar end-declarations forall(g in Groups, n in Nations) Groupings(g,n) is_binary - FICOCommunity Manager
I would suggest that you simply use the 'abs' constraint relation to state lines 7-13 of your first code snippet:
forall(g in Groups) points_diff(g):=abs(Points_Total(g) - mean_points)or if you declare 'points_diff' as mpvar:
forall(g in Groups) points_diff(g)=abs(Points_Total(g) - mean_points)Note that you need to work with the 'mmxnlp' module in place of 'mmxprs', but the resulting model will still be handled by the MIP solver.
For further discussion of formulation alternatives for absolute value constraints please refer to the 'MIP formulations' whitepaper: https://www.fico.com/fico-xpress-optimization/docs/latest/mipform/dhtml/chap2s1_sec_ssecabsval.html
- FICOCommunity Manager
I think the constraint works now, thanks!
It takes about 3-4 min to compute but I really needed that constraint implemented.
- FICOCommunity Manager
And just out of curiosity, do you have any idea why my first idea did not work. More precisely, why:
Points_Total(g) - mean_points >= 0was not considered logical expression?
- FICOCommunity Manager
'Points_Total(g)' is of type linctr and so is 'mean_points', so this whole expression is of type 'linctr'. It is not possible to use a 'linctr' within an 'if' for stating a logical constraint: you need to work with an 'implies' relation in this case (using package 'advmod').
Related Content
Related Content
Combining sum and overall statement
Hi, I am trying to build a perishable supply chain model. To include perishability, I want to include a constraint in which for every period in time (T is the set of periods, indexed by t) the model...5 years agoPlace FICO® Xpress Optimization ForumFICO® Xpress Optimization Forum2 unread comments2 unread12Views0likes2Comments