# Binary constraint

(EHTISHAM ASGHAR) #1

Dear all please have a look at constraint to buy sell power from to grid but I want either buy or sell at a time how to manage this constraint
cvx_clear
%input data
alpha1 = 2; beta1 = 3;
alpha2 = 4; beta2 = 5;
alpha3 = 6; beta3 = 7;
D = [5 3 7 2 12 20 6 9 5 7 11 12 11 10 5 6 7 4 9 7 9 10 7 5];
u = [1 1 2 2 3 33 4 4 5 5 2 100 1 7 7 5 5 3 3 0 0 1 1 8];
T = 24; d = 3;
cvx_begin

``````minimize(sum(alpha1*p(:,1).^2 + beta1*p(:,1) + alpha2*p(:,2).^2 + beta2*p(:,2) + alpha3*p(:,3).^2 + beta3*p(:,3) +...

subject to

sum(p,2)+ pg_buy == D' + pg_sell;

0 <= p(:,1) <= 4;
0 <= p(:,2) <= 6;
0 <= p(:,3) <= 9;
0 <= pg_sell <= 100;          % constraint to sell power to grid
norms(p(2:T, : ) - p(1:T-1,:),Inf,1) <= [3 5 8];
cvx_end``````

(Michael C. Grant) #2

This is not a forum for general modeling assistance. If you don’t yet know how to write your mathematical model using standard mathematical notation (on paper, say, or in LaTeX), then you’re not ready to apply CVX to it.

(EHTISHAM ASGHAR) #3

sir micheal mathematically I know but I don’t know to apply that constraint in CVX, I dont want buying and selling power at the same time.
mathematically this constraint is like that.

(Mark L. Stone) #4

In the future, you’d be better served asking for help on this kind of question at https://www.or-exchange.org// . There are many integer programming and Big M whizzes there.

``````variable b(T,1) binary