Page 1 of 1

converting an integer variable into a binary variable

Posted: Mon Apr 02, 2018 7:33 pm
by Only_God
Dear GAMS experts,
I have a modeling problem which seems not to be difficult to solve, but I cannot find a way to handle it. :|
Assume there are two variables in your model that one of the variables is integer (X) and another one is binary (Y).
If X is 0 then Y is 0 as well, otherwise if X=1,2,3, .... then Y=1.
I don't know how I can define these conditional equation in GAMS, since one cannot define an equation in GAMS with conditions on variables.
Can anybody help me?
Thanks for your time to read the post.

Re: converting an integer variable into a binary variable

Posted: Tue Apr 03, 2018 3:37 pm
by Manassaldi
Hi, try these equations:

eq.. X =l= M*Y
eq.. X =g= Y

M is a parameter and the upper bound of X

If Y =1
X =l= M
X =g= 1

if Y = 0
X =l= 0
X =g= 0

Bye!

Re: converting an integer variable into a binary variable

Posted: Wed Apr 04, 2018 9:05 am
by Only_God
Dear Manassaldi,
Thank you very much to reply my post.
Your idea is great and I would try to apply it to my model. :)
Sincerely yours.
Manassaldi wrote: 6 years ago Hi, try these equations:

eq.. X =l= M*Y
eq.. X =g= Y

M is a parameter and the upper bound of X

If Y =1
X =l= M
X =g= 1

if Y = 0
X =l= 0
X =g= 0

Bye!

Re: converting an integer variable into a binary variable

Posted: Sun Oct 02, 2022 5:14 pm
by kant_ravi04
Dear Manassaldi,
can you please tell how to handle binary variables in a model as a normal variable? like in TSP x(i,j) is a binary variable when an edge is chosen between vertex i and vertex j. Can we treat this variable as a normal variable? please help.

Re: converting an integer variable into a binary variable

Posted: Mon Oct 03, 2022 12:40 am
by Manassaldi
Hi, solving the relaxed problem the binary variables become continuous. Try solving the model as RMIP instead of MIP.
Cheers!

Re: converting an integer variable into a binary variable

Posted: Mon Oct 03, 2022 9:11 am
by kant_ravi04
But then it will give the wrong output in case of TSP. Lets say we have the following code, what if we want binary variable x(i,j) as normal variable?, can we do it and solve it using LP that still give us the same result as MIP in quick time.
mTSP.txt
(5.68 KiB) Downloaded 116 times

Re: converting an integer variable into a binary variable

Posted: Mon Oct 03, 2022 1:51 pm
by Manassaldi
Hi, I don't think you can change the nature of a problem. It is possible that there is an alternative LP version but I don't think so. Otherwise nobody would solve MIP models.
I hope I have been helpful
best

Re: converting an integer variable into a binary variable

Posted: Mon Oct 03, 2022 3:35 pm
by kant_ravi04
Thank you @Manassaldi

People have suggested different formulations (saying it as ILP) in their papers for TSP but all the ILP's given in GAMS library are solved by MIP only. Do you have any idea where can I find out GAMS code of TSP solved using LP.

Thanks in advance.

Re: converting an integer variable into a binary variable

Posted: Tue Oct 04, 2022 1:05 pm
by Manassaldi
Hi, I don't know where to find this. But, You can try to implement the proposed models in GAMS.
Best.