# One-way dependence in a constraint

Hi,

Can I make a constraint such that variable A must be smaller than variable B, but B should not me affected by the value of variable A?

Aka:
A <= maxA
B<= maxB
B<= A,

where the last constraint should not inflate A.

Your help would be much appreciated!

Kind regards,
Nyn

I don’t understand what you want.

Your words seem to express different constraint(s) than the 3 constraints you show (“variable A must be smaller than variable B”, but you show the constraint `B <= A`).

What does “B should not me affected by the value of variable A” mean? In a constraint involving `A` and `B`, `A` will be “affected” by `B` and `B` will be affected by `A`.

If the 3 constraints you show collectively accomplish what you want, you can include all 3 constraints in your program.

Thank you for your quick response and my apologies for the unclarity.

It should indeed have been “A should not be affected by the value of variable B”.

On top of the three constraints, I need the constraint that A should not be affected by B in the sense that for one period there should be two decision moments, A has to be determined first and only after more information becomes available B can be set and must be smaller than A.

The problem I am trying to solve is the planning of wind power, during the second decision moment, which is closer to the delivery of power, some adjustments can still be made to account for differences between the forecasted and the actual generated power.

The problems cannot be separated completely, since there is a storage level involved in the problem that updates from period to period and the adjustments made during the second decision moment affect this storage level.

I hope this makes it clear what I am trying to achieve.

It sounds like a two stage modeling problem. You are probably better off getting detailed guidance for that elsewhere, such as https://or.stackexchange.com/, and which should be focused on modeling (define variables, constraints, objective), rather than CvX per se. You need to get that clear first.

Anyhow, it sounds like you need additional variables. Each decision moment or stage may need its own variables (at least some of them). Then form the constraints accordingly to relate the stages.

I have modeled the variables, objective, and constraints as follows:

wgen <- Variable(t) #wind power sold in the day-ahead market
wbal <- Variable(t) #wind power sold in the balancing market (up-regulation)
el <- Variable(t) #power used to perform electrolysis
inst <- Variable(t) #hydrogen that goes to the storage
fc <- Variable(t) #power generated using the fuel cell for the day-ahead market
fcbal <- Variable(t) #power generated using the fuel cell for the balancing market (up-regulation)
sth <- Variable(t) #hydrogen sold to industry from the storage
h <- Variable(t) #hydrogen sold immediately after electrolysis
st <- Variable(t+1) #the storage level
wdown <- Variable(t) #negative amount of wind power sold in the balancing market (down-regulation)
fcdown <- Variable(t) #negative amount of fuel cell power sold in the balancing market (down-regulation)

#objective
objective <- Maximize(sum((wgen+fc)*p[1:(t)]+(wbal+fcbal)*pbal_up+(wdown+fcdown)*pbal_down+(h+sth)*h2p))

#contraints
constraints <- list(st==0, wgen>=0, wbal>=0, wdown <= 0, el>=0, fc>=0, fcdown <=0, fcbal>=0,
h>=0, st>=0, inst>=0, sth>=0,
wgen + wbal + wdown+ el <= wind[1:(t)],
0 <= wbal + fcbal, wbal + fcbal <= max_up,
wdown + fcdown >= max_down, wdown + fcdown <= max_up,
abs(wdown) <= solution_a\$getValue(wgen), abs(fcdown) <= solution_a\$getValue(fc), #problematic constraint
h + sth <= heat[1:(t)],
el*eel==inst+h,
inst <= sendin,
el<= elmax, fc+fcbal+fcdown<= fcmax,
(fc+fcbal+fcdown)/efc+sth<= st[1:t],
(fc+fcbal+fcdown)/efc+sth<= sendout,
st[1:t+1] <= maxst,
diff(st)==inst-(fc+fcbal+fcdown)/efc-sth #diff is the increase from the last hour
)

CvX fits the requirements of my model, except for this one issue.

In the code above I have used output from a version of the model that only includes the first scheduling moment to constrain the desired variables, in the line with “problematic constraint”.

The result is not yet quite satisfactory, since it might still be that during the first moment extra power is sold, because it can be sold as down-regulation of power (negative supply of power because there is too much electricity supply compared to demand and this needs to balance) during the second scheduling moment. The two scheduling moments represents different submarkets in the electricity market. It might indeed be a good idea to separate them in two stages, but I don’t know if or how this can be done.

As I am already pretty invested in the use of CvXR, I am trying to figure out a way to solve my problem within CvXR. Perhaps this is too much to ask, but if you could see if, or even better, how CvXR can facilitate what I need this would be a great help.

This is the CVX (MATLAB) forum, not the CVXR (R language) forum.

I don’t understand what you want the constraint to be, and don’t have the energy to attempt to figure it out. So your question is doubly off-topic for this forum.

Nevertheless, perhaps you want some type of logic constraint (if something, then specified constraint applies). That can be handled by introduction of binary variables, as discussed at https://or.stackexchange.com/search?q=logic+constraints .and handled by CVX or CVXR, presuming a solver capable of handling integer variables is available to you in that modeling tool.