[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Help: Switch constraints on or off
From: |
Heinrich Schuchardt |
Subject: |
Re: Help: Switch constraints on or off |
Date: |
Tue, 24 Nov 2020 22:19:40 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux aarch64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 |
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 +0000
From: Manuel Castro <m.j.castro@zoho.com <mailto:m.j.castro@zoho.com>>
To: "help-glpk" <help-glpk@gnu.org <mailto:help-glpk@gnu.org>>
Subject: Help: Switch constraints on or off
Message-ID: <175fb9fb6e3.12bae7aa873758.2962621200961588692@zoho.com
<175fb9fb6e3.12bae7aa873758.2962621200961588692@zoho.com">mailto:175fb9fb6e3.12bae7aa873758.2962621200961588692@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.