Defining a SOS1-Variable as binary, where not all Sets must contain a non-Zero Value

Problems with modeling
Post Reply
Pinguin_Fan
User
User
Posts: 5
Joined: 4 years ago

Defining a SOS1-Variable as binary, where not all Sets must contain a non-Zero Value

Post by Pinguin_Fan »

Dear Gams World Forum,

i've looked through the Post before but found nothing similar to my problem.

In the problem, I try to define a SOS1 variable, which could look like this.

Code: Select all

Sets
i	set which represents the later "Sets" of the SOS1 Variable 			/1*10/
l	set which represents the later "Elements" in each "Set" of the SOS1 Variable	/1*50/
;

SOS1 Variable
x(i,l)	SOS1-Variable consisting of 10 sets whith 50 elements each;
The next step is to ensure that the non-zero value of each set is exactly 1.
You can find the following code for this in the Gams Documentation (adapted to my definitions above):

Code: Select all

SOS1 Variable 
x(l); 
Equation 
defx;
defx.. sum(l, x(l)) =e= 1 ;
Applied to the problem I presented, the code could be reformulated as follows:

Code: Select all

SOS1 Variable
x(i,l)	SOS1-Variable consisting of 10 sets whith 50 elements each;
Equation 
defx(i);
defx(i).. sum(l, x(i,l)) =e= 1 ;
With this formulation now each "Set" of the SOS1-Variable must have one Element with the Value "1".
And thats where the tricky point starts :). For the formulation of my model, there must be a further condition that not all, but a maximum of 5 sets for example, may contain a 1. This could be realized by an additional condition:

Code: Select all

Equation
additionalEq;
additionalEq..	sum((i,l), x(i,l)) =e= 5;
Obviously the combination of both equations results in an infeasable model.

Therefore, my question now is whether it is possible to define the SOS1 variable in such a way that the non-zero values must be 1, but not every set needs a non-zero value (as required by the first equation).

I also attached a (sadly infeasable) minimalistic Model.
Minimal_Example.gms
(1009 Bytes) Downloaded 215 times
I hope i could explain my problem in a understandable way. Please excuse grammar mistakes, as english is not my mother tongue.

Thanks a lot and have a nice day.

Greetings Pinguin_Fan
User avatar
bussieck
Moderator
Moderator
Posts: 1042
Joined: 7 years ago

Re: Defining a SOS1-Variable as binary, where not all Sets must contain a non-Zero Value

Post by bussieck »

Just turn your x(i,l) into a binary variable and your equality constraint into a less-or-equal: defx(i).. sum(l, x(i,l)) =l= 1 ; That's it. Don't worry about x being binary instead of SOS 1. Most solvers will turn them into binary inside anyway, because nowadays modern MIP solvers prefer to work with binary variables much more than with SOS variables (they can do many more of their advanced techniques like cuts, rins, etc when the model has only binary and integer variables), at least that is my experience.

-Michael
Pinguin_Fan
User
User
Posts: 5
Joined: 4 years ago

Re: Defining a SOS1-Variable as binary, where not all Sets must contain a non-Zero Value

Post by Pinguin_Fan »

Hey Micheal,

first of all thanks for your answer. :)

I guess its my fault i didn't mention this in the post above.
Of course, what you are saying is perfectly correct and results in a working model.

The project i am working on is kind of an reasearch project for my study course.
There an already existing model (with binary variables, exactly as you suggested) will be examined. The goal is to reduce the solution time of the model. Therefore the approach was to replace the binary variables by binary-SOS-variables. I also believe that the improvements in computation time will be very small, but it would be better to prove the whole thing on a real model.
Although you're right :) doesn't your answer solve my actual problem (which I probably could have formulated a bit clearer in the beginning)?

So the question remains if it is possible to define SOS variables with binary character.

Greeting Pinguin_Fan
User avatar
bussieck
Moderator
Moderator
Posts: 1042
Joined: 7 years ago

Re: Defining a SOS1-Variable as binary, where not all Sets must contain a non-Zero Value

Post by bussieck »

You could reduce the number of binaries and do

Code: Select all

SOS1 Variable x(i,l)	SOS1-Variable consisting of 10 sets whith 50 elements each;
Binary Variable y(i);
Equation defx(i), defy;
defx(i).. sum(l, x(i,l)) =e= 0 + y(i) ;
defy.. sum(i, y(i)) =e= 5;
You can even mimic binary variables with SOS1 constraints if you need to get rid of all binary variables:

Code: Select all

positive variable poorMansBinary;
set s /s1,s2/;
sos1 variable sl(s);
equation e1,e2;
e1.. poorMansBinary =e= 1 - sl('s1');
e2.. poorMansBinary =e= 0 + sl('s2');
Why you would ever want to do this is unclear to me.

Good luck.

-Michael
Pinguin_Fan
User
User
Posts: 5
Joined: 4 years ago

Re: Defining a SOS1-Variable as binary, where not all Sets must contain a non-Zero Value

Post by Pinguin_Fan »

Thank you very much for your answers :)
Thats what i was searching for.
Have a great day.

-Pinguin_Fan
Post Reply