Constraint in optimization problem

1 view (last 30 days)
Chris B
Chris B on 19 Mar 2015
Commented: Chris B on 22 Mar 2015
Hello all,
I would like to kindly ask for your help, if you are familiar with optimization stuff...
Do you know how I can introduce a constraint in order to avoid having a vector solution without consecutive '1s' (either the number of '1' are two, or three etc)? (Let's say the vector is y and takes 6 binary values)
For example: vector1 = [1 0 1 0 0 0]
vector2 = [0 0 1 1 0 1]
vector3 = [1 0 0 0 1 0]
vector4 = [0 0 1 0 0 1]
are not valid solutions, but:
vector5 = [1 0 0 0 0 0]
vector6 = [0 0 1 1 1 0]
vector7 = [0 1 1 0 0 0]
vector8 = [0 0 1 0 0 0]
vector9 = [1 1 1 0 0 0]
are valid. I am really stuck with it!
Best regards, Chris

Accepted Answer

Alan Weiss
Alan Weiss on 19 Mar 2015
I am sorry, but I do not understand your constraint. Are "consecutive" in one vector? I see nothing wrong with vector1, vector3, or vector4 in terms of consecutive 1s. And vector6, vector7, and vector 9 seem to have consecutive 1s. So what is your constraint, in words or a formula?
Alan Weiss
MATLAB mathematical toolbox documentation
  6 Comments
Chris B
Chris B on 20 Mar 2015
Thank you for you answer!!! I think that in this way it solves everything, but it excludes the possibility of having [1 0 0 0 0 ... 0 0 0]...
Chris B
Chris B on 22 Mar 2015
Hello Alan,
It is finally solved with another introduced variable as you said, with slight enhancements! Thanks again all for your time.

Sign in to comment.

More Answers (2)

Torsten
Torsten on 19 Mar 2015
x(i) + x(i+1) <= 1
Best wishes
Torsten.
  1 Comment
Chris B
Chris B on 19 Mar 2015
Edited: Chris B on 19 Mar 2015
Thank you for your answer.
This one violates the case of having two consecutive '1s', that is something acceptable and it doesn't work for it!

Sign in to comment.


John D'Errico
John D'Errico on 19 Mar 2015
Edited: John D'Errico on 19 Mar 2015
You don't say what optimization tool you are working with. But as long as your favorite optimizer (intlinprog maybe) can handle inequality constraints, then just specify
x(1) + x(2) <= 1
x(2) + x(3) <= 1
x(3) + x(4) <= 1
x(4) + x(5) <= 1
x(5) + x(6) <= 1
  1 Comment
Chris B
Chris B on 19 Mar 2015
Thank you for your reply as well.
Yes, I am using intlinprog as a solver... According to your specifications, [1 1 0 0 0 0] is not an acceptable solution, but it should be..
The thing is that I only want either one '1' in the vector solution, or if it is two, two consecutive '1s', if it is three, three consecutive '1s' etc..

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!