RE: Constraint modelling on a subset

2021-03-24 Thread Philippe Jugla
Hi Heinrich,

It works really well, I would have never thought of it that way.

Thanks again for your help,

Best regards

Philippe


De : Heinrich Schuchardt 
Envoyé : mercredi 24 mars 2021 00:05
À : Philippe Jugla ; help-glpk@gnu.org 

Objet : Re: Constraint modelling on a subset

On 23.03.21 22:28, Philippe Jugla wrote:
> Hello,
>
>
>
> I am rather new to GLPK and I am seeking help regarding the modelling of
> a constraint in a unit commitment problem.
>
> I hope someone will kindly help me on this one.
>
>
>
> I am trying to model a constraint which constrains a sum, but on a
> sequence of subsets of an initial set TIME.
>
> A bit of context with a simple example below :
>
>
>
> *#sets *
>
> set TIME := 1..T;
>
> set PLANTS :=P1, P2;
>
> * *
>
> *#parameters *
>
> param T;
>
> param max_startups_year {PLANTS};
>
> param max_startups_week {PLANTS};
>
> * *
>
> *#variable *
>
> var startup {p in PLANTS, t in TIME} binary;
>
> * *
>
> *#constraint 1 *
>
> subject to C1 {p in PLANTS}:
>
> sum {t in TIME} startup[p,t] <= max_startups_year[p];
>
> *_ _*
>
> *Now this is where I am struggling : I would like to constrain sum of
> startup[p,t] with parameter max_startups_week[p] but on subsets of the
> set TIME with step k (let’s say k=5). *
>
> * *
>
> *The following works but obviously is not flexible at all. *
>
> *It gives you the idea of what I would like to do : *
>
>
>
> sum {t in 0..5} startup[p,t] <= max_startups_week[p];
>
> sum {t in 6..10} startup[p,t] <= max_startups_week[p];
>
> …
>
> Etc…
>
> …
>
> sum {t in T-5..T} startup[p,t] <= max_startups_week[p];
>
>
>
>
> I have tried to define another set TIME_2 but it’s not satisfying as it
> is hard-coded as well…
>
>
>
> *Set TIME_2 := (0..5 union 6..10.. union /[etc]/ union T-5..T)  *
>
> *subject to C2 {p in PLANTS}: *
>
> *sum {s in TIME_2} startup[p,s] <= max_startups_week[p]; *
>
>
>
> How would you work this constraint out to be robust and flexible ? At
> the end, the number of steps k should be a parameter.
>
> To simplify things, let’s say that k divides exactly set TIME.
>
>
>
> Thanks very much for your help,
>
>
>
> Philippe
>
>

All you need is an indexed constraint like:

s.t. constraint{w in WEEKS}:
max_startups_week[w] >=
sum{d in DAYS_OF_WEEK} startup[d + days_per_week * w];

Best regards

Heinrich


Re: Constraint modelling on a subset

2021-03-23 Thread Heinrich Schuchardt
On 23.03.21 22:28, Philippe Jugla wrote:
> Hello, 
>
>  
>
> I am rather new to GLPK and I am seeking help regarding the modelling of
> a constraint in a unit commitment problem. 
>
> I hope someone will kindly help me on this one. 
>
>  
>
> I am trying to model a constraint which constrains a sum, but on a
> sequence of subsets of an initial set TIME. 
>
> A bit of context with a simple example below : 
>
>  
>
> *#sets *
>
> set TIME := 1..T; 
>
> set PLANTS :=P1, P2; 
>
> * *
>
> *#parameters *
>
> param T; 
>
> param max_startups_year {PLANTS}; 
>
> param max_startups_week {PLANTS}; 
>
> * *
>
> *#variable *
>
> var startup {p in PLANTS, t in TIME} binary; 
>
> * *
>
> *#constraint 1 *
>
> subject to C1 {p in PLANTS}: 
>
> sum {t in TIME} startup[p,t] <= max_startups_year[p]; 
>
> *_ _*
>
> *Now this is where I am struggling : I would like to constrain sum of
> startup[p,t] with parameter max_startups_week[p] but on subsets of the
> set TIME with step k (let’s say k=5). *
>
> * *
>
> *The following works but obviously is not flexible at all. *
>
> *It gives you the idea of what I would like to do : *
>
>  
>
> sum {t in 0..5} startup[p,t] <= max_startups_week[p]; 
>
> sum {t in 6..10} startup[p,t] <= max_startups_week[p];
>
> … 
>
> Etc… 
>
> … 
>
> sum {t in T-5..T} startup[p,t] <= max_startups_week[p]; 
>
>  
>
>
> I have tried to define another set TIME_2 but it’s not satisfying as it
> is hard-coded as well… 
>
>  
>
> *Set TIME_2 := (0..5 union 6..10.. union /[etc]/ union T-5..T)  *
>
> *subject to C2 {p in PLANTS}: *
>
> *sum {s in TIME_2} startup[p,s] <= max_startups_week[p]; *
>
>  
>
> How would you work this constraint out to be robust and flexible ? At
> the end, the number of steps k should be a parameter. 
>
> To simplify things, let’s say that k divides exactly set TIME. 
>
>  
>
> Thanks very much for your help, 
>
>  
>
> Philippe 
>
>

All you need is an indexed constraint like:

s.t. constraint{w in WEEKS}:
max_startups_week[w] >=
sum{d in DAYS_OF_WEEK} startup[d + days_per_week * w];

Best regards

Heinrich



Constraint modelling on a subset

2021-03-23 Thread Philippe Jugla
Hello,

I am rather new to GLPK and I am seeking help regarding the modelling of a 
constraint in a unit commitment problem.
I hope someone will kindly help me on this one.

I am trying to model a constraint which constrains a sum, but on a sequence of 
subsets of an initial set TIME.
A bit of context with a simple example below :

#sets
set TIME := 1..T;
set PLANTS :=P1, P2;

#parameters
param T;
param max_startups_year {PLANTS};
param max_startups_week {PLANTS};

#variable
var startup {p in PLANTS, t in TIME} binary;

#constraint 1
subject to C1 {p in PLANTS}:
sum {t in TIME} startup[p,t] <= max_startups_year[p];

Now this is where I am struggling : I would like to constrain sum of 
startup[p,t] with parameter max_startups_week[p] but on subsets of the set TIME 
with step k (let’s say k=5).

The following works but obviously is not flexible at all.
It gives you the idea of what I would like to do :

sum {t in 0..5} startup[p,t] <= max_startups_week[p];
sum {t in 6..10} startup[p,t] <= max_startups_week[p];
…
Etc…
…
sum {t in T-5..T} startup[p,t] <= max_startups_week[p];


I have tried to define another set TIME_2 but it’s not satisfying as it is 
hard-coded as well…

Set TIME_2 := (0..5 union 6..10.. union [etc] union T-5..T)
subject to C2 {p in PLANTS}:
sum {s in TIME_2} startup[p,s] <= max_startups_week[p];

How would you work this constraint out to be robust and flexible ? At the end, 
the number of steps k should be a parameter.
To simplify things, let’s say that k divides exactly set TIME.

Thanks very much for your help,

Philippe