One storage constraint help

I met a problem about the storage constraint. Below is the simple code.
I want to constrain that the storage only have one cycle charge/discharge state in one day. If charge is 1, discharge is -1,remaining is 0, that means 1 1 1 1 0 0 -1 -1 -1 -1…, or 1 0 1 0 1 -1 -1…, only one change trailing edge.

I am not sure the problem is clear, below also paste the fig.

cvx begin
variable E(24) nonnegtive;energy starage
variable P(24) ;power input/output
min objective
subject to
        Emin<=E<=Emax; 
        -Pm<=P<=Pm;
        E0=0;
        E=[E0;E(1:end-1)]+P;
        ***add one cycle charge and discharge constraint***
cvx end

John, these questions you have been asking are really not CVX, specific are they? That is to say: do you know how to formulate them already in other modeling frameworks like AMPL or GAMS? Do you know how to feed them to MILP solvers directly, but CVX is not as capable?

This is not the forum to go to for general modeling help. For one thing we focus this forum on CVX-specific questions; and again, this is not one. But also there aren’t that many of us here :slight_smile: Please consider Math StackExchange or OR-Exchange for questions like these.