Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Bintprog Constraints

Subject: Bintprog Constraints

From: Alfredo Martini

Date: 7 May, 2013 08:04:10

Message: 1 of 9

Hello everyone,
I'm in trouble with bintprog: are there any ways of adding other constraints equations, apart from the existing?
I mean, while in a standard case we have
A x <= b
Aeq x = beq
So, I would like to know if I can insert another equation like
A2eq x = b2eq
Or, even better
A2eq y = b2eq

Thanks in advice.

Subject: Bintprog Constraints

From: Alan_Weiss

Date: 7 May, 2013 11:41:50

Message: 2 of 9

On 5/7/2013 4:04 AM, Alfredo Martini wrote:
> Hello everyone,
> I'm in trouble with bintprog: are there any ways of adding other
> constraints equations, apart from the existing?
> I mean, while in a standard case we have
> A x <= b
> Aeq x = beq
> So, I would like to know if I can insert another equation like
> A2eq x = b2eq
> Or, even better
> A2eq y = b2eq
>
> Thanks in advice.

You might misunderstand the existing constraints. The constraint
Ax <= b
is a matrix inequality, meaning you can have as many rows of
inequalities as you like. That certainly covers your requested case
A2eq = b2eq

For more information, see
http://www.mathworks.com/help/optim/ug/writing-constraints.html#brhkghv-14

Alan Weiss
MATLAB mathematical toolbox documentation

Subject: Bintprog Constraints

From: Alfredo Martini

Date: 8 May, 2013 09:25:09

Message: 3 of 9

You're right but, in my case, is more complicated. I have to do something like the 2nd formula on this paper
http://www.ee.ucr.edu/~hamed/SMRWSj2013.pdf
Where I have to impose in Aeq a sequence of inputs that has to be "close" to each other (contiguous) but it will be bintprog to tell me wich interval will be composed by "1" or "0" for example.

I mean, I need to impose in Aeq something like

Aeq = [...
       1 1 0
       ];

or Aeq = [...
            0 1 1
            ];

in such a way that x1 + x2 + x3 = 2, but the solution should be or x1 + x2 = 1 or x2 + x3 = 1. Where I want that bintprog will choose wich solution to adopt.

Alan_Weiss <aweiss@mathworks.com> wrote in message <kmap9u$o42$1@newscl01ah.mathworks.com>...
> On 5/7/2013 4:04 AM, Alfredo Martini wrote:
> > Hello everyone,
> > I'm in trouble with bintprog: are there any ways of adding other
> > constraints equations, apart from the existing?
> > I mean, while in a standard case we have
> > A x <= b
> > Aeq x = beq
> > So, I would like to know if I can insert another equation like
> > A2eq x = b2eq
> > Or, even better
> > A2eq y = b2eq
> >
> > Thanks in advice.
>
> You might misunderstand the existing constraints. The constraint
> Ax <= b
> is a matrix inequality, meaning you can have as many rows of
> inequalities as you like. That certainly covers your requested case
> A2eq = b2eq
>
> For more information, see
> http://www.mathworks.com/help/optim/ug/writing-constraints.html#brhkghv-14
>
> Alan Weiss
> MATLAB mathematical toolbox documentation

Subject: Bintprog Constraints

From: Johan Lofberg

Date: 8 May, 2013 11:06:09

Message: 4 of 9

To do that, you have to introduce more variables.

The OR you talk about could for instance be implemented as

x1 + x2 == x4
x2 + x3 == x5
x4 + x5 == 1

"Alfredo Martini" <e2878090@rmqkr.net> wrote in message <kmd5ll$78o$1@newscl01ah.mathworks.com>...
> You're right but, in my case, is more complicated. I have to do something like the 2nd formula on this paper
> http://www.ee.ucr.edu/~hamed/SMRWSj2013.pdf
> Where I have to impose in Aeq a sequence of inputs that has to be "close" to each other (contiguous) but it will be bintprog to tell me wich interval will be composed by "1" or "0" for example.
>
> I mean, I need to impose in Aeq something like
>
> Aeq = [...
> 1 1 0
> ];
>
> or Aeq = [...
> 0 1 1
> ];
>
> in such a way that x1 + x2 + x3 = 2, but the solution should be or x1 + x2 = 1 or x2 + x3 = 1. Where I want that bintprog will choose wich solution to adopt.
>
> Alan_Weiss <aweiss@mathworks.com> wrote in message <kmap9u$o42$1@newscl01ah.mathworks.com>...
> > On 5/7/2013 4:04 AM, Alfredo Martini wrote:
> > > Hello everyone,
> > > I'm in trouble with bintprog: are there any ways of adding other
> > > constraints equations, apart from the existing?
> > > I mean, while in a standard case we have
> > > A x <= b
> > > Aeq x = beq
> > > So, I would like to know if I can insert another equation like
> > > A2eq x = b2eq
> > > Or, even better
> > > A2eq y = b2eq
> > >
> > > Thanks in advice.
> >
> > You might misunderstand the existing constraints. The constraint
> > Ax <= b
> > is a matrix inequality, meaning you can have as many rows of
> > inequalities as you like. That certainly covers your requested case
> > A2eq = b2eq
> >
> > For more information, see
> > http://www.mathworks.com/help/optim/ug/writing-constraints.html#brhkghv-14
> >
> > Alan Weiss
> > MATLAB mathematical toolbox documentation

Subject: Bintprog Constraints

From: Alfredo Martini

Date: 8 May, 2013 12:18:09

Message: 5 of 9

First of all thanks for your reply then, I thought about a similar solution but I don't know how to implement it because

Aeq * x = beq

And with

 x1 + x2 == x4
 x2 + x3 == x5
 x4 + x5 == 1

I'll have unknowns in beq vector. I mean, given that vector x is the final result, I can't write something like

[1 1 1 0 0; * [x1; x2; x3; x4; x5] = [2, x4, x5, 1]
 1 1 0 0 0;
 0 1 1 0 0
 0 0 0 1 1];

Or maybe it's me and I don't know how to write it.

"Johan Löfberg" wrote in message <kmdbj1$m9g$1@newscl01ah.mathworks.com>...
> To do that, you have to introduce more variables.
>
> The OR you talk about could for instance be implemented as
>
> x1 + x2 == x4
> x2 + x3 == x5
> x4 + x5 == 1
>
> "Alfredo Martini" <e2878090@rmqkr.net> wrote in message <kmd5ll$78o$1@newscl01ah.mathworks.com>...
> > You're right but, in my case, is more complicated. I have to do something like the 2nd formula on this paper
> > http://www.ee.ucr.edu/~hamed/SMRWSj2013.pdf
> > Where I have to impose in Aeq a sequence of inputs that has to be "close" to each other (contiguous) but it will be bintprog to tell me wich interval will be composed by "1" or "0" for example.
> >
> > I mean, I need to impose in Aeq something like
> >
> > Aeq = [...
> > 1 1 0
> > ];
> >
> > or Aeq = [...
> > 0 1 1
> > ];
> >
> > in such a way that x1 + x2 + x3 = 2, but the solution should be or x1 + x2 = 1 or x2 + x3 = 1. Where I want that bintprog will choose wich solution to adopt.
> >
> > Alan_Weiss <aweiss@mathworks.com> wrote in message <kmap9u$o42$1@newscl01ah.mathworks.com>...
> > > On 5/7/2013 4:04 AM, Alfredo Martini wrote:
> > > > Hello everyone,
> > > > I'm in trouble with bintprog: are there any ways of adding other
> > > > constraints equations, apart from the existing?
> > > > I mean, while in a standard case we have
> > > > A x <= b
> > > > Aeq x = beq
> > > > So, I would like to know if I can insert another equation like
> > > > A2eq x = b2eq
> > > > Or, even better
> > > > A2eq y = b2eq
> > > >
> > > > Thanks in advice.
> > >
> > > You might misunderstand the existing constraints. The constraint
> > > Ax <= b
> > > is a matrix inequality, meaning you can have as many rows of
> > > inequalities as you like. That certainly covers your requested case
> > > A2eq = b2eq
> > >
> > > For more information, see
> > > http://www.mathworks.com/help/optim/ug/writing-constraints.html#brhkghv-14
> > >
> > > Alan Weiss
> > > MATLAB mathematical toolbox documentation

Subject: Bintprog Constraints

From: Bruno Luong

Date: 8 May, 2013 12:23:09

Message: 6 of 9

"Alfredo Martini" <e2878090@rmqkr.net> wrote in message <kmdfq1$490$1@newscl01ah.mathworks.com>...
> First of all thanks for your reply then, I thought about a similar solution but I don't know how to implement it because
>
> Aeq * x = beq
>
> And with
>
> x1 + x2 == x4
> x2 + x3 == x5
> x4 + x5 == 1
>
> I'll have unknowns in beq vector. I mean, given that vector x is the final result, I can't write something like
>
> [1 1 1 0 0; * [x1; x2; x3; x4; x5] = [2, x4, x5, 1]
> 1 1 0 0 0;
> 0 1 1 0 0
> 0 0 0 1 1];
>
> Or maybe it's me and I don't know how to write it.

transform the eqt

x1 + x2 == x4

to

x1 + x2 - x4 = 0

etc...

% Bruno

Subject: Bintprog Constraints

From: Alfredo Martini

Date: 8 May, 2013 13:02:09

Message: 7 of 9

Ok, you're right too but, in this way, with

 [1 1 1 1 0 0 0; * [x1; x2; x3; x4; x5; x6; x7] = [2, x4, x5, x6, 3]
  1 1 0 0 0 0 0;
  0 1 1 0 0 0 0;
  0 0 1 1 0 0 0;
  0 0 0 0 1 1 1];

I have these equations

x1 + x2 + x3 +x4 = 2
x1 + x2 = x5
x2 + x3 = x6
x3 + x4 = x7
x5 + x6 + x7 = 3

where I want a result like

[x1 x2 x3 x4] = [1 1 0 0] or [0 1 1 0] or [0 0 1 1]

where x5 could be 0, 1 or 2, x6 could be 0, 1 or 2 and x7 could be 0, 1 or 2.

And seems that what you propose doesn't fit anymore. Am I wrong?




"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <kmdg3d$51n$1@newscl01ah.mathworks.com>...
> "Alfredo Martini" <e2878090@rmqkr.net> wrote in message <kmdfq1$490$1@newscl01ah.mathworks.com>...
> > First of all thanks for your reply then, I thought about a similar solution but I don't know how to implement it because
> >
> > Aeq * x = beq
> >
> > And with
> >
> > x1 + x2 == x4
> > x2 + x3 == x5
> > x4 + x5 == 1
> >
> > I'll have unknowns in beq vector. I mean, given that vector x is the final result, I can't write something like
> >
> > [1 1 1 0 0; * [x1; x2; x3; x4; x5] = [2, x4, x5, 1]
> > 1 1 0 0 0;
> > 0 1 1 0 0
> > 0 0 0 1 1];
> >
> > Or maybe it's me and I don't know how to write it.
>
> transform the eqt
>
> x1 + x2 == x4
>
> to
>
> x1 + x2 - x4 = 0
>
> etc...
>
> % Bruno

Subject: Bintprog Constraints

From: Bruno Luong

Date: 8 May, 2013 13:50:11

Message: 8 of 9

"Alfredo Martini" <e2878090@rmqkr.net> wrote in message <kmdich$ckd$1@newscl01ah.mathworks.com>...
> Ok, you're right too but, in this way, with
>
> [1 1 1 1 0 0 0; * [x1; x2; x3; x4; x5; x6; x7] = [2, x4, x5, x6, 3]
> 1 1 0 0 0 0 0;
> 0 1 1 0 0 0 0;
> 0 0 1 1 0 0 0;
> 0 0 0 0 1 1 1];

Please put all the unknowns in all equations in ONE side.

Bruno

Subject: Bintprog Constraints

From: Steven_Lord

Date: 8 May, 2013 15:34:29

Message: 9 of 9



"Alfredo Martini" <e2878090@rmqkr.net> wrote in message
news:kmdich$ckd$1@newscl01ah.mathworks.com...
> Ok, you're right too but, in this way, with
> [1 1 1 1 0 0 0; * [x1; x2; x3; x4; x5; x6; x7] = [2, x4, x5, x6, 3]
> 1 1 0 0 0 0 0;
> 0 1 1 0 0 0 0;
> 0 0 1 1 0 0 0;
> 0 0 0 0 1 1 1];
>
> I have these equations

I'm going to label them for reasons I'll explain in a bit.

a) > x1 + x2 + x3 +x4 = 2
b) > x1 + x2 = x5

Rewrite this as:

b) x1 + x2 - x5 = 0.

This is in the form Aeq in which expects the constraints to be provided.
Note that nothing requires the elements of f, A, b, Aeq, or beq to be solely
0 or 1. They can contain -1, 2, pi, 1.23456789, etc. The elements of X and
X0 are so required; the elements of the other inputs are not.

c) > x2 + x3 = x6
d) > x3 + x4 = x7

Do the same for these two.

e) > x5 + x6 + x7 = 3

Let's dig a little into those equations for this example problem. Combine
items a, b, and d to get:

x1 + x2 + x3 + x4 = x5 + x7 = 2

Combining this with e we learn that:

x5 + x7 + x6 = 3 = 2 + x6

So x6 must be 1. Since x2 and x3 must be either 0 or 1, we have that either
x2 = 1 and x3 = 0 or x2 = 0 and x3 = 1. In either case at most one of x1 and
x4 is 1 (by a.) So it looks like you have four candidate solutions.

Your real problem may not be this simple, but you may want to see if you can
apply these types of arguments to smaller pieces of it to simplify the
solution process by fixing some of the variables.

> where I want a result like
>
> [x1 x2 x3 x4] = [1 1 0 0] or [0 1 1 0] or [0 0 1 1]
>
> where x5 could be 0, 1 or 2, x6 could be 0, 1 or 2 and x7 could be 0, 1 or
> 2.
>
> And seems that what you propose doesn't fit anymore. Am I wrong?

Your objective "function" vector f will contain some zero elements
corresponding to the new variables you added. When you return the solution
to the function that called BINTPROG, you'll discard the "temporary"
components of the solution.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us