Re: Help: Switch constraints on or off

2020-11-24 Thread Heinrich Schuchardt

On 11/24/20 10:12 PM, Greg Gruber wrote:

Hi Manuel,

try setting StorageFlag to 1 or 0 as a parameter (based on your data),
and then doing this:

   subject to linctr14-1 {i in PeriodsCount: i == 1}:
           StorageEnergy[i] >= StorageFlag*( existing constraint ) ;
   subject to linctr14-0 {i in PeriodsCount: i == 1}:
           StorageEnergy[i] <= StorageFlag*( existing constraint ) +
(1-StorageFlag) * M   ;

When StorageFlag = 1, these two constraints equate to your equality
constraint.
When StorageFlag = 0, the constraints just become bounds (0 and M). If
you want to allow StorageEnergy[i] to be negative, you could add " -
(1-StorageFlag)*M" to the first constraint.



This approach is adequate if StorageFlag is a binary *variable*. For a
*parameter* selecting constraints see
https://en.wikibooks.org/wiki/GLPK/Conditional_Constraints.

Best regards

Heinrich



I *think* this will work -- good luck!

Best regards,
Greg


-

Message: 1
Date: Tue, 24 Nov 2020 18:59:09 +
From: Manuel Castro mailto:m.j.cas...@zoho.com>>
To: "help-glpk" mailto:help-glpk@gnu.org>>
Subject: Help: Switch constraints on or off
Message-ID: <175fb9fb6e3.12bae7aa873758.2962621200961588...@zoho.com
>
Content-Type: text/plain; charset="utf-8"

Hi there,



I am wondering how I can use an if statement to turn a constraint on
or off.

For example in my problem I have the following constraint:



subject to linctr14 {i in PeriodsCount: i == 1}: StorageEnergy[i] =
(StorageStateCharge * StorageEnergyRating +
((StorageEfficiencyCharge * (StoragePowerCharge[i])) -
((StoragePowerDischarge[i]) / StorageEfficiencyDischarge)));



Now, I only want to consider storage in my problem if an object
storage actually exists.

For that, I would have a StorageStatusFlag which if equal to "1"
then I would consider the constraint in my problem.

For example:



If (StorageStatusFlag == 1) then

     subject to linctr14 {i in PeriodsCount: i == 1}:
StorageEnergy[i] = (StorageStateCharge * StorageEnergyRating +
((StorageEfficiencyCharge * (StoragePowerCharge[i])) -
((StoragePowerDischarge[i]) / StorageEfficiencyDischarge)));

end if


This is what I used to do in "mosel" language from FICO Xpress (I
don't have a license anymore so I am discovering GLPK ). How can I
do this in GLPK language? What's the workaround that we can use for
this?



Many thanks in advance for your help. It's really appreciated.



Kind regards,

Manuel.






Re: Help: Switch constraints on or off

2020-11-24 Thread Greg Gruber
Hi Manuel,

try setting StorageFlag to 1 or 0 as a parameter (based on your data), and
then doing this:

  subject to linctr14-1 {i in PeriodsCount: i == 1}:
  StorageEnergy[i] >= StorageFlag*( existing constraint ) ;
  subject to linctr14-0 {i in PeriodsCount: i == 1}:
  StorageEnergy[i] <= StorageFlag*( existing constraint ) +
(1-StorageFlag) * M   ;

When StorageFlag = 1, these two constraints equate to your equality
constraint.
When StorageFlag = 0, the constraints just become bounds (0 and M). If you
want to allow StorageEnergy[i] to be negative, you could add " -
(1-StorageFlag)*M" to the first constraint.

I *think* this will work -- good luck!

Best regards,
Greg


> -
>
> Message: 1
> Date: Tue, 24 Nov 2020 18:59:09 +
> From: Manuel Castro 
> To: "help-glpk" 
> Subject: Help: Switch constraints on or off
> Message-ID: <175fb9fb6e3.12bae7aa873758.2962621200961588...@zoho.com>
> Content-Type: text/plain; charset="utf-8"
>
> Hi there,
>
>
>
> I am wondering how I can use an if statement to turn a constraint on or
> off.
>
> For example in my problem I have the following constraint:
>
>
>
> subject to linctr14 {i in PeriodsCount: i == 1}: StorageEnergy[i] =
> (StorageStateCharge * StorageEnergyRating + ((StorageEfficiencyCharge *
> (StoragePowerCharge[i])) - ((StoragePowerDischarge[i]) /
> StorageEfficiencyDischarge)));
>
>
>
> Now, I only want to consider storage in my problem if an object storage
> actually exists.
>
> For that, I would have a StorageStatusFlag which if equal to "1" then I
> would consider the constraint in my problem.
>
> For example:
>
>
>
> If (StorageStatusFlag == 1) then
>
> subject to linctr14 {i in PeriodsCount: i == 1}: StorageEnergy[i] =
> (StorageStateCharge * StorageEnergyRating + ((StorageEfficiencyCharge *
> (StoragePowerCharge[i])) - ((StoragePowerDischarge[i]) /
> StorageEfficiencyDischarge)));
>
> end if
>
>
> This is what I used to do in "mosel" language from FICO Xpress (I don't
> have a license anymore so I am discovering GLPK ). How can I do this in
> GLPK language? What's the workaround that we can use for this?
>
>
>
> Many thanks in advance for your help. It's really appreciated.
>
>
>
> Kind regards,
>
> Manuel.
>
>


Re: Help: Switch constraints on or off

2020-11-24 Thread Heinrich Schuchardt

On 11/24/20 9:30 PM, Heinrich Schuchardt wrote:

On 11/24/20 8:42 PM, Andrew Makhorin wrote:

On Tue, 2020-11-24 at 18:59 +, Manuel Castro wrote:

Hi there,

I am wondering how I can use an if statement to turn a constraint on
or off.
For example in my problem I have the following constraint:

subject to linctr14 {i in PeriodsCount: i == 1}: StorageEnergy[i] =
(StorageStateCharge * StorageEnergyRating + ((StorageEfficiencyCharge
* (StoragePowerCharge[i])) - ((StoragePowerDischarge[i]) /
StorageEfficiencyDischarge)));

Now, I only want to consider storage in my problem if an object
storage actually exists.
For that, I would have a StorageStatusFlag which if equal to "1" then
I would consider the constraint in my problem.
For example:

If (StorageStatusFlag == 1) then
     subject to linctr14 {i in PeriodsCount: i == 1}: StorageEnergy[i]
= (StorageStateCharge * StorageEnergyRating +
((StorageEfficiencyCharge * (StoragePowerCharge[i])) -
((StoragePowerDischarge[i]) / StorageEfficiencyDischarge)));
end if


Just add the condition to the constraint iterator:

subject to
linctr14{i in PeriodsCount: i == 1 && StorageStatusFlag == 1}: 


I have updated our wikibook

https://en.wikibooks.org/wiki/GLPK/Conditional_Constraints

Best regards

Heinrich





This is what I used to do in "mosel" language from FICO Xpress (I
don't have a license anymore so I am discovering GLPK ). How can I do
this in GLPK language? What's the workaround that we can use for this?



You could use the C preprocessor.




Many thanks in advance for your help. It's really appreciated.

Kind regards,
Manuel.











Re: Help: Switch constraints on or off

2020-11-24 Thread Heinrich Schuchardt

On 11/24/20 8:42 PM, Andrew Makhorin wrote:

On Tue, 2020-11-24 at 18:59 +, Manuel Castro wrote:

Hi there,

I am wondering how I can use an if statement to turn a constraint on
or off.
For example in my problem I have the following constraint:

subject to linctr14 {i in PeriodsCount: i == 1}: StorageEnergy[i] =
(StorageStateCharge * StorageEnergyRating + ((StorageEfficiencyCharge
* (StoragePowerCharge[i])) - ((StoragePowerDischarge[i]) /
StorageEfficiencyDischarge)));

Now, I only want to consider storage in my problem if an object
storage actually exists.
For that, I would have a StorageStatusFlag which if equal to "1" then
I would consider the constraint in my problem.
For example:

If (StorageStatusFlag == 1) then
     subject to linctr14 {i in PeriodsCount: i == 1}: StorageEnergy[i]
= (StorageStateCharge * StorageEnergyRating +
((StorageEfficiencyCharge * (StoragePowerCharge[i])) -
((StoragePowerDischarge[i]) / StorageEfficiencyDischarge)));
end if


Just add the condition to the constraint iterator:

subject to
linctr14{i in PeriodsCount: i == 1 && StorageStatusFlag == 1}: 

Best regards

Heinrich



This is what I used to do in "mosel" language from FICO Xpress (I
don't have a license anymore so I am discovering GLPK ). How can I do
this in GLPK language? What's the workaround that we can use for this?



You could use the C preprocessor.




Many thanks in advance for your help. It's really appreciated.

Kind regards,
Manuel.








Re: Help: Switch constraints on or off

2020-11-24 Thread Manuel Castro




Hi Andrew,Thank you for the prompt reply.What do you mean by C 
prepocessor?? Apologies, I know how to program but that’s pretty much it... 
On Tue, 24 Nov 2020 19:42:10 +  m...@gnu.org wrote On 
Tue, 2020-11-24 at 18:59 +, Manuel Castro wrote: > Hi there, >  > I am 
wondering how I can use an if statement to turn a constraint on > or off. > For 
example in my problem I have the following constraint: >  > subject to linctr14 
{i in PeriodsCount: i == 1}: StorageEnergy[i] = > (StorageStateCharge * 
StorageEnergyRating + ((StorageEfficiencyCharge > * (StoragePowerCharge[i])) - 
((StoragePowerDischarge[i]) / > StorageEfficiencyDischarge))); >  > Now, I only 
want to consider storage in my problem if an object > storage actually exists. 
> For that, I would have a StorageStatusFlag which if equal to "1" then > I 
would consider the constraint in my problem. > For example:  >  > If 
(StorageStatusFlag == 1) then >     subject to linctr14 {i in PeriodsCount: i 
== 1}: StorageEnergy[i] > = (StorageStateCharge * StorageEnergyRating + > 
((StorageEfficiencyCharge * (StoragePowerCharge[i])) - > 
((StoragePowerDischarge[i]) / StorageEfficiencyDischarge))); > end if >  > This 
is what I used to do in "mosel" language from FICO Xpress (I > don't have a 
license anymore so I am discovering GLPK ). How can I do > this in GLPK 
language? What's the workaround that we can use for this?   You could use the C 
preprocessor.   >  > Many thanks in advance for your help. It's really 
appreciated. >  > Kind regards, > Manuel.  >  








Re: Help: Switch constraints on or off

2020-11-24 Thread Andrew Makhorin
On Tue, 2020-11-24 at 18:59 +, Manuel Castro wrote:
> Hi there,
> 
> I am wondering how I can use an if statement to turn a constraint on
> or off.
> For example in my problem I have the following constraint:
> 
> subject to linctr14 {i in PeriodsCount: i == 1}: StorageEnergy[i] =
> (StorageStateCharge * StorageEnergyRating + ((StorageEfficiencyCharge
> * (StoragePowerCharge[i])) - ((StoragePowerDischarge[i]) /
> StorageEfficiencyDischarge)));
> 
> Now, I only want to consider storage in my problem if an object
> storage actually exists.
> For that, I would have a StorageStatusFlag which if equal to "1" then
> I would consider the constraint in my problem.
> For example: 
> 
> If (StorageStatusFlag == 1) then
>     subject to linctr14 {i in PeriodsCount: i == 1}: StorageEnergy[i]
> = (StorageStateCharge * StorageEnergyRating +
> ((StorageEfficiencyCharge * (StoragePowerCharge[i])) -
> ((StoragePowerDischarge[i]) / StorageEfficiencyDischarge)));
> end if
> 
> This is what I used to do in "mosel" language from FICO Xpress (I
> don't have a license anymore so I am discovering GLPK ). How can I do
> this in GLPK language? What's the workaround that we can use for this?


You could use the C preprocessor.


> 
> Many thanks in advance for your help. It's really appreciated.
> 
> Kind regards,
> Manuel. 
> 



Re: Change Path Input/Output file

2020-11-24 Thread Andrew Makhorin
On Tue, 2020-11-24 at 19:11 +, Manuel Castro wrote:
> Hi there,
> 
> I am currently using gusek as an IDE to model and run GLPK.
> I use the following statement to read from CSV file.
> 
> table tab_plant IN "CSV" "plants.csv" : I <- [plant], a ~ capacity;
> 
> This assumes that the file is placed in the same directory where the
> glpk solver is.
> How can I place my CSV file in a different directory and tell glpk to
> read it from there? How do I add the path on my model syntax? 

Conventions are the same as in C programs. You can write

"../foo/plants.csv"

or

MYDIR & "/plants.csv"

where MYDIR is a symbolic parameter declared like this:

param MYDIR, symbolic, := "../foo"


> 
> Many thanks in advance for your help. It's really appreciated.
> 
> Kind regards,
> Manuel. 
> 



Change Path Input/Output file

2020-11-24 Thread Manuel Castro
Hi there,



I am currently using gusek as an IDE to model and run GLPK.

I use the following statement to read from CSV file.



table tab_plant IN "CSV" "plants.csv" : I <- [plant], a ~ capacity;



This assumes that the file is placed in the same directory where the glpk 
solver is.

How can I place my CSV file in a different directory and tell glpk to read it 
from there? How do I add the path on my model syntax? 


Many thanks in advance for your help. It's really appreciated.



Kind regards,

Manuel. 

Help: Switch constraints on or off

2020-11-24 Thread Manuel Castro
Hi there,



I am wondering how I can use an if statement to turn a constraint on or off.

For example in my problem I have the following constraint:



subject to linctr14 {i in PeriodsCount: i == 1}: StorageEnergy[i] = 
(StorageStateCharge * StorageEnergyRating + ((StorageEfficiencyCharge * 
(StoragePowerCharge[i])) - ((StoragePowerDischarge[i]) / 
StorageEfficiencyDischarge)));



Now, I only want to consider storage in my problem if an object storage 
actually exists.

For that, I would have a StorageStatusFlag which if equal to "1" then I would 
consider the constraint in my problem.

For example: 



If (StorageStatusFlag == 1) then

    subject to linctr14 {i in PeriodsCount: i == 1}: StorageEnergy[i] = 
(StorageStateCharge * StorageEnergyRating + ((StorageEfficiencyCharge * 
(StoragePowerCharge[i])) - ((StoragePowerDischarge[i]) / 
StorageEfficiencyDischarge)));

end if


This is what I used to do in "mosel" language from FICO Xpress (I don't have a 
license anymore so I am discovering GLPK ). How can I do this in GLPK language? 
What's the workaround that we can use for this?



Many thanks in advance for your help. It's really appreciated.



Kind regards,

Manuel.