[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Re: [Help-glpk] Indexing a subset from 1..n

**From**: |
glpk xypron |

**Subject**: |
Re: [Help-glpk] Indexing a subset from 1..n |

**Date**: |
Tue, 27 Nov 2012 22:53:20 +0100 |

Hello Joel,
param nPeriods := 12;
set Periods, default{1.. nPeriods};
# let even period be open
param FacilityOpen{p in Periods}, binary := if p mod 2 == 0 then 1 else 0;
set OpenPeriods:= setof{p in Periods: FacilityOpen[p] = 1}(p);
param nOpen := card(OpenPeriods);
set NOpen := {1..nOpen};
# beware this will take n^2 time
param pOpen{n in NOpen} := sum{p in OpenPeriods :
n ==card(setof{i in OpenPeriods: i <=p }i) } p;
display pOpen;
end;
Best regards
Xypron
-------- Original-Nachricht --------
>* Datum: Wed, 28 Nov 2012 08:15:46 +1100*
>* Betreff: [Help-glpk] Indexing a subset from 1..n*
>* Hello all,*
>* I have a set of Periods from which I create the subset OpenPeriods when*
>* the facility is open.*
>* param nPeriods;set Periods, default{1.. nPeriods};param FacilityOpen{p in*
>* Periods}, binary;set OpenPeriods:= setof{p in Periods: FacilityOpen[p] = 1}*
>* (p);*
>* The facility is not open during all periods and I have a constraint that*
>* considers the configuration of the facility the previous time it was open.*
>* So I am trying to index the set of OpenPeriods from 1...card(OpenPeriods)*
>* rather than with p but so far without any luck.*
>* Any help would be much appreciated.*
>* Thanks,*
>* Joel*