add conditional constrain in optimization

3 views (last 30 days)

if a=0 then q=0
if a=1 then q=24;
if a=2 then q=32;
if a=3 then q=44;

how to write this as constrain for optimization problem?

  5 Comments
Torsten
Torsten on 27 Feb 2023
Which optimizer do you use ?
Is a defined to be integer ?
Is q defined to be integer ?
Are a and q solution variables ?
Fathima
Fathima on 28 Feb 2023
Edited: Fathima on 28 Feb 2023
@Torsten @Rik I will explain my problem more clearly.. I have 3 pumps so number of pumps 'a' working at the time t denoted by a[t] can take values =0,1,2,3. Now supply of water at time t denoted by Q[t] depends on a[t] that is given by if a[t]=0 then Q[t]=0 if a[t]=1 then Q[t]=24; if a[t]=2 then Q[t]=32; if a[t]=3 then Q[t]=44;
Objective is to minimize number of pumps used at time t
My doubt it how to implement this conditional constraint in MATLAB ?

Sign in to comment.

Accepted Answer

Torsten
Torsten on 28 Feb 2023
Edited: Torsten on 28 Feb 2023
Define x_it be the decision variable if pump i is active at time t. That means x_it can take values 0 and 1 and equals 0 of pump i is off at time t and equals 1 if pump i is on at time t.
Then your problem somehow looks like
min: sum_t (x1t + x2t + x3t)
24*x1t + 32*x2t + 44*x3t >= amount of water needed at time t (t=1,...,T)
0 <= x_it < = 1
x_it integer
You can use "intlinprog" to solve.
  35 Comments
Torsten
Torsten on 5 Mar 2023
Edited: Torsten on 5 Mar 2023
Why should "intlinprog" use the strategy to switch on three pumps if h < 3.5, use 2 pumps of 3.5 < = h < 4.5 and use one pump if h >= 4.5 ? The values 3.5 and 4.5 are absolutely empirical and not optimal.
"Intlinprog" is given the water demands over the time period it optimizes because you use the demands in your constraints. That's why "Intlinprog" can find a much better strategy than the one above.
But usually, the demands are uncertain and not exactly known in advance. That's what the Deep Learning Tool is for. It develops a strategy based on data in the past (learning phase) and uses this strategy to take present decisions (now without knowing what exactly the future will bring). Thus both methods try to optimize the usage of the pumps, but the circumstances under which they optimize, namely exact or uncertain knowledge about the future demands, make the mathematical methods used and the results completely different.
If the future demands are known, "intlinprog" will always give the "best" solution. If the future demands are uncertain, you will have to refer to neural networks, Deep Learning or related methods.
Fathima
Fathima on 15 Mar 2023
@Torsten Thankyou sir . You are truely a good teacher :) ..

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!