Binary variable declaration

53 views
Skip to first unread message

Ashok Krishnan

unread,
Oct 6, 2015, 4:23:55 AM10/6/15
to YALMIP
Hi Johan,

I am trying to solve a MILP problem in MPC framework using YALMIP plus CPLEX. The system has 8 states out of which 1 state is a binary variable and the other 7 are continuous. In addition, the system has 3 inputs out of which 1 input is binary and the other 2 are continuous.

The decision variables in the optimization problem are the states and inputs. 

I have used the following declaration to declare the decision variables as shown in the MPC tutorial:

x = sdpvar(repmat(nx,1,N+1),repmat(1,1,N+1));
u = sdpvar(repmat(nu,1,N),repmat(1,1,N));

How do I declare that certain variables are binary in x and u?

Thanks in advance.

Best Regards
Ashok Krishnan

Johan Löfberg

unread,
Oct 6, 2015, 4:55:07 AM10/6/15
to yal...@googlegroups.com
Third element in x is binary

X = [x{:}];
Model = binary(X(3,:));

or do it in a for-loop
...
 
Model = [Model, binary(x{i}(3))];
...



Ashok Krishnan

unread,
Oct 8, 2015, 11:48:22 AM10/8/15
to YALMIP
Hi Johan,

Many thanks for your reply. I have 2 more questions. In the code snippet for a prediction horizon N:

x = sdpvar(repmat(nx,1,N+1),repmat(1,1,N+1));
X=[x{:}];
Model = binary (X(3,:));

1) How do I declare multiple decision variables as binary? Should I use multiple assignments like: 

Model1=binary(X(3,:))
Model2=binary(X(2,:))

where 2nd and 3rd elements in x are binary.

Is there a simpler way to achieve this?

2) What is the syntax I should use to refer to the binary variables in my objective function? For example, if I need to include the term 20 * x3 (where x3 is a binary decision variable) in the objective function, should I use Model1 to refer to x3 or just use X(3,k)?

Best Regards
Ashok Krishnan

Johan Löfberg

unread,
Oct 8, 2015, 12:33:35 PM10/8/15
to YALMIP
1 That's one way. or model=binary(X(anyindiciesyouwant,:))

2 X(3,k) of course. there is nothing special about variables you've specified stuff as binary
Reply all
Reply to author
Forward
0 new messages