converting an integer variable into a binary variable

Problems with modeling
Post Reply
Only_God
User
User
Posts: 11
Joined: 6 years ago

converting an integer variable into a binary variable

Post 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.
Manassaldi
User
User
Posts: 118
Joined: 7 years ago
Location: Rosario - Argentina

Re: converting an integer variable into a binary variable

Post 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!
Only_God
User
User
Posts: 11
Joined: 6 years ago

Re: converting an integer variable into a binary variable

Post 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!
kant_ravi04
User
User
Posts: 3
Joined: 1 year ago

Re: converting an integer variable into a binary variable

Post 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.
Hi everyone, can anyone tell me, how to convert a binary variable to normal variable to solve the problem using IP instead of MIP, as in the case of the TSP.
Manassaldi
User
User
Posts: 118
Joined: 7 years ago
Location: Rosario - Argentina

Re: converting an integer variable into a binary variable

Post by Manassaldi »

Hi, solving the relaxed problem the binary variables become continuous. Try solving the model as RMIP instead of MIP.
Cheers!
kant_ravi04
User
User
Posts: 3
Joined: 1 year ago

Re: converting an integer variable into a binary variable

Post 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 89 times
Hi everyone, can anyone tell me, how to convert a binary variable to normal variable to solve the problem using IP instead of MIP, as in the case of the TSP.
Manassaldi
User
User
Posts: 118
Joined: 7 years ago
Location: Rosario - Argentina

Re: converting an integer variable into a binary variable

Post 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
kant_ravi04
User
User
Posts: 3
Joined: 1 year ago

Re: converting an integer variable into a binary variable

Post 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.
Hi everyone, can anyone tell me, how to convert a binary variable to normal variable to solve the problem using IP instead of MIP, as in the case of the TSP.
Manassaldi
User
User
Posts: 118
Joined: 7 years ago
Location: Rosario - Argentina

Re: converting an integer variable into a binary variable

Post by Manassaldi »

Hi, I don't know where to find this. But, You can try to implement the proposed models in GAMS.
Best.
Post Reply