Hello, I wish to linearize the following constrain:

if(a>0) then b = 1 else b = 0

a (integer) is in {1..15} and b is binary

thank u

asked 22 Aug '16, 04:25

BastaN's gravatar image

accept rate: 0%

edited 22 Aug '16, 04:37


Perhaps you have a typo. If a is an integer in {1..15}, as you say, then it is always > 0. Hence you have an unconditional constraint b = 1. You need to tell us how to fix your typo before a corresponding solution can be provided.

(22 Aug '16, 12:06) Mark L Stone

if you are using something like CPLEX (or perhaps other solvers) then there is a so called "indicator constraint" which can help you to model it.

Otherwise, you can simply write it like:

a <= b M

b <= a

where M is a big M value.

if a is non zero then b is forced to take 1 and of course b<=a if a is 0 then b cannot be non zero and a<= M b becomes redundant


answered 22 Aug '16, 10:53

ShahinG's gravatar image

accept rate: 0%

edited 22 Aug '16, 10:55

Assuming you really meant that a is in {0..15}, you can write

b <= a <= 15 b

If a is any number in the range 1..15 then this can only be satisfied by b = 1, while if a is 0 then this can only be satisfied by b = 0. Replacing 15 with some large number M will work as well, but will in general offer no advantage and may make the problem harder to solve.


answered 23 Aug '16, 10:39

4er's gravatar image

accept rate: 0%

edited 23 Aug '16, 10:40

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 22 Aug '16, 04:25

Seen: 1,077 times

Last updated: 23 Aug '16, 10:40

OR-Exchange! Your site for questions, answers, and announcements about operations research.