if - then function in AIMMS

3,097 views
Skip to first unread message

DucMinh Nguye

unread,
Aug 1, 2013, 9:37:23 AM8/1/13
to ai...@googlegroups.com
Hi,

I need to use the If - then - else -endif; in Aimms 
But I do not know where can I use it: in Constraints or in Procedure
because I researched some typical examples in Aimms Tutorials, these authors mainly use "If - then" in Procedure

Many thanks,

Best regards,  

DucMinh Nguye

unread,
Aug 1, 2013, 9:40:55 AM8/1/13
to ai...@googlegroups.com
and when I do "If - then" in constraints, it occurs the fault sentence " the left and hand side of constraint should be separated by one of the operators <=,=,>=
while "If- then" function does not need these signal in constraints

Guido Diepen

unread,
Aug 1, 2013, 4:51:24 PM8/1/13
to ai...@googlegroups.com
Hi,

you can use if-then-(else-)endif as a control statement in a procedure. This way, if the condition holds, everything in the first part is executed and otherwise everything in the else block is executed.

However, you can also use if-then-else-endif as an expression.

So a constraint could have the definition:
if someParameter=1 then
      sum( i, myVariables(i) ) <= 10
else
      sum(i, myVariables(i) ) + sum(j, myOthervariables(j) ) <= 15
endif 

if the parameter someParameter has the value 1, then the definition of the constraint is considered to be the first option and otherwise the second one. Note that you cannot make use of variables in the if-condition if you want to keep a linear proble, because using a variable in the if-condition results in a non-linear problem. Using index values or parameters is no problem though.

Maybe you can post what you are trying to do when AIMMS gives you the error message.

Guido Diepen

DucMinh Nguye

unread,
Aug 2, 2013, 4:42:48 AM8/2/13
to ai...@googlegroups.com
Hi,

My constraint is

if y1(m1,i)=1 
then w1(i,j1a)+w2(i,j2a)=1
and w1(i,j1a)- x1(m1,j1a)=0
and w2(i,j2a)- x2(m1,j2a)=0
else w1(i,j1a)+w2(i,j2a)=0
endif

AIMMS occur the error sentence "the left and hand side of constraint should be separated by one of the operators <=,=,>="


I have not still solved this problem

Many thanks

DucMinh Nguyen 


On Thursday, August 1, 2013 3:37:23 PM UTC+2, DucMinh Nguye wrote:

Luis Pinto

unread,
Aug 2, 2013, 12:10:26 PM8/2/13
to AIMMS GoogleGroups
You cannot use the "and" statement in this manner.
My suggestion is to create 4 constraints and control them through the index domain.



--
You received this message because you are subscribed to the Google Groups "AIMMS - The Modeling System" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aimms+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

DucMinh Nguye

unread,
Aug 5, 2013, 10:28:21 AM8/5/13
to ai...@googlegroups.com
Hi, Luis Pinto
 I did what you mean, sharing the first constraint of "if_then_else_endif" into 4 sub constraints and control them through index domain.

 AIMMS reported "no Error"
but when I push running press, the Progress Windows shows that: the infeasibility: na; Best solution: na and variety of warning about "this may lead to non-unique shadow prices". These warnings comes from sub constraints of "if_then_else_endif". 

Can you help me to understand more

Many thanks
Best regards     

DucMinh Nguyen


On Thursday, August 1, 2013 3:37:23 PM UTC+2, DucMinh Nguye wrote:

Luis Pinto

unread,
Aug 5, 2013, 10:45:42 AM8/5/13
to AIMMS GoogleGroups
Could you please post the constraints.
Suggestion:
export as a text representation (see below)

Inline images 1


--
Sem título5.png

Marcel Hunting

unread,
Aug 5, 2013, 11:07:26 AM8/5/13
to ai...@googlegroups.com
Hi,

Is y1 a variable or a parameter?

Best regards,

Marcel Hunting
AIMMS Software Developer

DucMinh Nguye

unread,
Aug 5, 2013, 12:18:08 PM8/5/13
to ai...@googlegroups.com
Hi,
y1(m1,i) is parameter that receive value 0 or 1
w1(i,j1a), w2(i,j2a), x1(m1,j1a) and x2(m1,j2a) are binary variables

My constraints in set of "If-then" are:

(1) if y1(m1,i)=1
then w1(i,j1a)+w2(i,j2a)=1
else w1(i,j1a)+w2(i,j2a)=0
endif;

(2) if y1(m1,i)=1
then w1(i,j1a)= x1(m1,j1a)
else w1(i,j1a)= 0
endif

(3)if y1(m1,i)=1
then w2(i,j2a)= x2(m1,j2a)
else w2(i,j2a)= 0
endif

Thanks for your guidance,
Best regards,

DucMinh Nguyen

On Thursday, August 1, 2013 3:37:23 PM UTC+2, DucMinh Nguye wrote:

Marcel Hunting

unread,
Aug 6, 2013, 4:28:49 AM8/6/13
to ai...@googlegroups.com
Hi,

If y1 is a parameter then you can rewrite your constraints and get rid of the if-then-else.

(1) w1(i,j1a)+w2(i,j2a) = y1(m1,i)
(2) w1(i,j1a) = y1(m1,i) * x1(m1,j1a)
(3) w2(i,j2a) = y1(m1,i) * x2(m1,j2a)

Apparently AIMMS or the solver cannot find a solution for your model. This reformulation will not fix that but makes the model easier to understand.

The warnings about "this may lead to non-unique shadow prices" are not so important at this moment. More important is to find out why you get no solution. What is the program and solver status shown in the progress window?

Best regards,

Marcel

DucMinh Nguye

unread,
Aug 6, 2013, 8:51:00 AM8/6/13
to ai...@googlegroups.com
Hi, 

Actually, even I change the constraints as Marcel's Hunting guidance (get rid of the "if-then"), but AIMMS does not solve my model more, I do not know the reason more because of no error for input work. The alarm sentence attached in this file

Best regards,


On Thursday, August 1, 2013 3:37:23 PM UTC+2, DucMinh Nguye wrote:
Progress Windows.png

Marcel Hunting

unread,
Aug 6, 2013, 10:08:24 AM8/6/13
to ai...@googlegroups.com
Hi,

Apparently your model is infeasible, that is, no solution exists than satisfies all constraints and the conditions on the variables. There is knowledge base article on dealing with infeasible problems:

But before doing so it is better to look at the warnings about "this may lead to non-unique shadow prices". I wrote before that they are currently not important but looking at the statistics of your generated math program (number of constraints > 100 * number of variables) it seems that you generate many duplicated constraints. Can you show the constraint definition of one of the constraints for which you get the warning?

Best regards,

Marcel

DucMinh Nguye

unread,
Aug 6, 2013, 12:56:35 PM8/6/13
to ai...@googlegroups.com
Thanks for your explanation. Please keep contact and help me more 


On Thursday, August 1, 2013 3:37:23 PM UTC+2, DucMinh Nguye wrote:
Warning constraint.png

Marcel Hunting

unread,
Aug 7, 2013, 9:30:21 AM8/7/13
to ai...@googlegroups.com
It seems that y1(m1,Ostende) = 0 for m1=Metz, Amsterdam, Maastricht, etc, and for each of them AIMMS generates a (duplicate) constraint

   w1(Ostende,J1-1) = 0.

If y1(m1,Ostende) = 1 for one of the other m1, let's say Haarlem, then AIMMS generates the constraint

   w1(Ostende,J1-1) = x1(Haarlem,J1-1) 

which together with the previous constraint enforces x1(Haarlem,J1-1) = 0. Are you sure this is what you want to model?

Marcel

DucMinh Nguye

unread,
Aug 7, 2013, 12:03:59 PM8/7/13
to ai...@googlegroups.com
Hi,
my model need these constraints
- if y1(m1,i) = 0, there are all non-basic variables [w1(i,j1a);w2(i,j2a)] and [x1(m1,j1a);x2(m1,j2a)];
- if y1(m1,i)= 1 there is exactly one binary variable in {w1(i,j1a); w2(i,j2a)} = 1 corresponding to unique binary variable in {x1(m1,j1a); x2(m1,j2a)} = 1

The meaning of constraints is if y1(m1,i) = 0 then w1(i,j1a) + w2(i,j2a) = 0
                                                                        x1(m1,j1a) + x2(m1,j2a) = 0          

                                              if y1(m1,i) = 1 then w1(i,j1a) + w2(i,j2a) = 1
                                                                        x1(m1,j1a) + x2(m1,j2a) = 1   

Regarding about the question of Marcel Hunting, if y1(m1,Ostende)=1 for m1 = Haarlem, i = Ostende
w1(Ostende, J1-1) = x1(Haarlem, J1-1)      (j1a = J1-1)
w2(Ostende, J2-1) = x2(Haarlem, J2-1)       (j2a = J2-1)

and exactly 1 variable in {x1(Haarlem,J1-1); x2(Haarlem, J2-1)} = 1      

Actually, as Marcel Hunting analyzed, I make a lot of duplicated constraints, but how can I reduce or avoid them without losing the meaning of model?  

Best regards,


On Thursday, August 1, 2013 3:37:23 PM UTC+2, DucMinh Nguye wrote:
Reply all
Reply to author
Forward
0 new messages