help-glpk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-glpk] Different constraint for first element of a set than fo


From: Noli Sicad
Subject: Re: [Help-glpk] Different constraint for first element of a set than for other elements
Date: Wed, 3 Feb 2010 03:36:40 +0700

The problem here is,  inventory [i,t-1]. I think you know this
already. It will not return the element of the set.

I think set PERIOD:= Jan Feb... Dec does not work in this case based
on my experience,  even using set PERIOD:= 1 2 3 4 5 6 ..12 as well.
In my case I use paramater instead of set for PERIOD..

param PERIOD:= 12;

subject to Supply_Capacity {i in SUPPLIERS, t in 2..PERIOD}:
    purchase [i,t] <= capacity [i,t] + inventory [i,t-1] - inventory [i,t] ;

subject to Supply_Capacity_Initial {i in SUPPLIERS, t in 1}:
    purchase [i,t] <= capacity [i,t] + initial_inventory [i] - inventory[i,t];

or  probably

subject to Supply_Capacity_Initial {i in SUPPLIERS, 1}:
    purchase [i,1] <= capacity [i,1] + initial_inventory [i] - inventory[i,1];

Just use the months in the print statement in result section, if you
want the months to be display for the  presentation of results.

Noli




On 2/3/10, Marc Goetschalckx <address@hidden> wrote:
> Following are the two constraints:
> subject to Supply_Capacity {i in SUPPLIERS, t in OTHER_PERIODS}:
>     purchase [i,t] <= capacity [i,t] + inventory [i,t-1] - inventory [i,t] ;
>
> subject to Supply_Capacity_Initial {i in SUPPLIERS, t in INITIAL_PERIOD}:
>     purchase [i,t] <= capacity [i,t] + initial_inventory [i] -
> inventory[i,t];
>
> Is there a function, similar to card() that returns the first element of
> a set?
> I did not see different constraints for the first period and the other
> ones in your answer, all constraints are over the full set of months?
>
> Noli Sicad wrote:
>> Hi Marc,
>>
>> Could you show us the constraint that make this error as well as the
>> data sets for these 3 sets so we can fix it.
>>
>> Anyway, here is example how to this period in months:
>>
>> ~~~~~~~~~~
>> set MONTHS;
>>
>> param Land_Coef{m in MONTHS, i in CROP};
>> param Forest_Coef{m in MONTHS,j in FORCROP};
>>
>> var Land{i in CROP};
>>
>> # constraint
>> #subject to LandAllocation(Months): Crop - ForestCrop <= TotalArea
>>
>> subject to LandAllo{m in MONTHS}:
>>       sum{i in CROP} Land_Coef[m,i] * Land[i] -  sum{j in FORCROP}
>> Forest_Coef[m,j] * LandForest[j] <= TotalArea;
>>
>> data;
>> set MONTHS:= Jan Feb Mar Apr May Jun Jul Aug Sept Oct Nov Dec;
>>
>> ~~~~~~~~~~
>>
>> Regards, Noli
>>
>> On 2/2/10, Marc Goetschalckx <address@hidden> wrote:
>>
>>> The model has a different constraint for the first element of a set (say
>>> PERIODS) than for all remaining elements.
>>> I have defined three sets:
>>> INITIAL_PERIOD;
>>> OTHER_PERIODS;
>>> PERIODS := INITIAL_PERIOD union OTHER_PERIODS;
>>> when MathProg is generating the model and specifically constraints over
>>> the PERIODS set it terminates with the following error
>>>
>>> cannot convert JAN to floating-point number
>>>
>>> where JAN is the first period in OTHER_PERIODS
>>> How should the model be written in MathProg to allow different
>>> constraints for the first element.
>>> Thanks
>>>
>>>
>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]