RE: Output to GMPL data file

2021-07-27 Thread Philippe Jugla
Hi Heinrich,

Thanks for your help, it works just fine.
Just had a look at the language reference too for the printf statement.

Best regards

Philippe


De : Heinrich Schuchardt 
Envoyé : mardi 27 juillet 2021 20:32
À : help-glpk@gnu.org ; Philippe Jugla 

Objet : Re: Output to GMPL data file

Am 27. Juli 2021 20:06:53 MESZ schrieb Philippe Jugla 
:
>Hello everyone,
>
>I am looping with a .bat file to run N simulations with glpsol.
>At the end of each simulation, I would like to use the value of a variable 
>which is calculated, as an input for the next simulation.
>What I have written in my .mod file doesn't work because it does not overwrite 
>my storage.dat file after each simulation...
>
>in the .mod file :
>TIME = 0..T-1;
>param initial_storage;
>var storage {t in TIME};
>/* I want to output the final storage value as initial storage for next 
>simulation*/
>printf ‘data; param initial_storage := ‘ & storage[T-1].val & ‘ ;’ >> 
>‘storage.dat’

Use a single > here.

>> is used to append.

Have a look at print format strings too.

Best regards

Heinrich

>printf ‘end ;’ >> ‘storage.dat’
>
>the .bat file :
>for /l %%k in (1,N,1) do (
>echo solving DAY %%k...
>"%GUSEKPATH%\glpsol.exe" --cuts -m "model.mod" -d "storage.dat" -d 
>"data_%%k.dat"
>)
>
>Is there a way of achieving this ?
>Thank you very much,
>
>Best regards,
>
>Philippe
>



Output to GMPL data file

2021-07-27 Thread Philippe Jugla
Hello everyone,

I am looping with a .bat file to run N simulations with glpsol.
At the end of each simulation, I would like to use the value of a variable 
which is calculated, as an input for the next simulation.
What I have written in my .mod file doesn't work because it does not overwrite 
my storage.dat file after each simulation...

in the .mod file :
TIME = 0..T-1;
param initial_storage;
var storage {t in TIME};
/* I want to output the final storage value as initial storage for next 
simulation*/
printf ‘data; param initial_storage := ‘ & storage[T-1].val & ‘ ;’ >> 
‘storage.dat’
printf ‘end ;’ >> ‘storage.dat’

the .bat file :
for /l %%k in (1,N,1) do (
echo solving DAY %%k...
"%GUSEKPATH%\glpsol.exe" --cuts -m "model.mod" -d "storage.dat" -d 
"data_%%k.dat"
)

Is there a way of achieving this ?
Thank you very much,

Best regards,

Philippe



RE: Constraint on a binary variable

2021-06-30 Thread Philippe Jugla
Hi Heinrich

That's a really elegant way to model it..
Just finished testing it, and works just fine.

Thanks a lot,
Best regards,
Philippe


De : Heinrich Schuchardt 
Envoyé : mercredi 30 juin 2021 17:40
À : Philippe Jugla 
Cc : help-glpk@gnu.org 
Objet : Re: Constraint on a binary variable

On 6/30/21 5:24 PM, Philippe Jugla wrote:
> Hi everyone,
>
> In my model, I have a variable "p" which has an upper bound pmax := 2.5
> and a lower bound pmin := -2.5.
> I would simply like to add a binary variable "sign" which takes the values :
>
> 1 if variable p is positive
> 0 if variable p is negative (or vice-versa)
>
> I thought of something like :
>
> s.t c1 : sign >= p[t] / pmax;
>
> So if p[t] is positive : sign >0 and <1, therefore sign will be forced to 1.
> However, if p[t] is negative, "sign" is greater than a negative value so
> the variable is no longer constrained, and can take values 0 or 1.
>
> How can I work things out ?
>
> Thanks for your help
>
> Best regards,
> Philippe

var sign, binary;
var p, >= -2.5, <= 2.5;
s.t. constraint: p <= 2.5 * sign;
#maximize obj: p;
minimize obj: p;
solve;
display p, sign;
end;

Best regards

Heinrich



Constraint on a binary variable

2021-06-30 Thread Philippe Jugla
Hi everyone,

In my model, I have a variable "p" which has an upper bound pmax := 2.5 and a 
lower bound pmin := -2.5.
I would simply like to add a binary variable "sign" which takes the values :

1 if variable p is positive
0 if variable p is negative (or vice-versa)

I thought of something like :

s.t c1 : sign >= p[t] / pmax;

So if p[t] is positive : sign >0 and <1, therefore sign will be forced to 1.
However, if p[t] is negative, "sign" is greater than a negative value so the 
variable is no longer constrained, and can take values 0 or 1.

How can I work things out ?

Thanks for your help

Best regards,
Philippe


Scheduling problem - cost function

2021-04-01 Thread Philippe Jugla
Hello everyone,

I have some difficulties to add a cost parameter that depends on 2 variables to 
a scheduling model in GLPK.

The problem is as follows :

If the unit has started up and been active for less than k hours than the cost 
follows a certain cost function, if it has been more than k hours then the cost 
follows another function.

I have tried the following example but doesn’t seem to work :

#set
set TIME:=0...T

#binary variables (already defined and working)
var start_up {TIME} binary;
var unit_on {TIME} binary;

#parameters
param T:=10;
param price {TIME};
param k:=2;

#this is what I’ve tried :
param cost {t in TIME} :=
  if sum { s in TIME : s = t - k and s >= 0 } start_up[s] + 
unit_on[s] < k+1 then 2.5*price[t] + 5 else 3.0*price[t] + 10;

The following error is thrown : « operand preceding < has invalid type ». I 
guess it is because of the variables ? I tried to define cost as a variable but 
with no success as well..

I am also trying to workaround things by defining another binary variable X 
{TIME} that I would constrain, and then define the cost with something like 
cost[t] = (1-X)*(cost_function_1) + X*cost_function_2 but it seems quite 
complicated for this type of problem.

Does anyone know what is the issue ? How could I work things out ?

Any help or advice would be greatly appreciated !

Best regards

Philippe



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


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