help-glpk
[Top][All Lists]
Advanced

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

Re: [Help-glpk] forall constraint in MathProg


From: Noli Sicad
Subject: Re: [Help-glpk] forall constraint in MathProg
Date: Tue, 6 Nov 2012 10:36:48 +1100

Hello Xypron,

There is a problem with the set STAND (below).

>set STAND := {1..nperiod};

It must be

set STAND := {1..nstand};


I remove the NATURE and just use STAND.

It seems this model below is  working. I got 60 lines of constraints.

###############
# file test.lp

param nperiod := 3;
param nstand := 20;

set PERIOD := {1..nperiod};
set STAND := {1..nstand};

param standarea {STAND} := 5 + 5 * Uniform01();

var forest{STAND, PERIOD};
var nh{STAND, PERIOD};

s.t. habitat{p in PERIOD,s in STAND} :
  sum{pp in PERIOD:pp <= p} forest[s, pp]  + nh[s, p] = standarea[s];

end;

#############

Danke. Alles in Ordnung :-).

Regards,

Noli

On 11/6/12, Noli Sicad <address@hidden> wrote:
> Hello Xypron,
>
> It seems that there is a still a problem.
>
> Upon closer inspection on the constraints generated by this statement,
>
> ####
> s.t. habitat{p in PERIOD, n in NATURE, s in STAND} :
>   sum{pp in PERIOD:pp <= p} forest[s, pp] + nh[n, p] = standarea[s];
> ####
>
> It generates 300 constraints instead of 60 (i.e. 3 x 20) constraints.
>
> Something wrong in  nh[n, p].
>
> Again, the desire out is like this,
>
>  S1P1 + N1P1 = 12.3
>  S1P1 + S1P2 + N1P2 = 12.3
>  S1P1 + S1P2 + S1P3 + N1P3 = 12.3
>
> S2P1 + N2P1 = 35.6
> S2P1 + S2P2 + N2P2 = 35.6
> S2P1 + S2P2 + S2P3 + N2P3 = 34.6
>
>
>
> It seems that it is doing like this.
>
> S1P1 + N1P1 = 12.3
> S1P1 + S1P2 + N1P2 = 12.3
> S1P1 + S1P2 + S1P3 + N1P3 = 12.3
>
> S1P1 + N2P1 = 12.3
>  S1P1 + S1P2 + N2P2 = 12.3
>  S1P1 + S1P2 + S1P3 + N2P3 = 12.3
>
> This is the actual output:
>
> Subject To
>  habitat(1,1,1): + forest(1,1) + nh(1,1) = 5.64155902015045
>  habitat(1,1,2): + forest(2,1) + nh(1,1) = 5.04798337584361
>  habitat(1,1,3): + forest(3,1) + nh(1,1) = 5.14843434561044
>
>
> This is not needed (below)
>
>  habitat(1,2,1): + forest(1,1) + nh(2,1) = 5.64155902015045
>  habitat(1,2,2): + forest(2,1) + nh(2,1) = 5.04798337584361
>  habitat(1,2,3): + forest(3,1) + nh(2,1) = 5.14843434561044
>  habitat(1,3,1): + forest(1,1) + nh(3,1) = 5.64155902015045
>  habitat(1,3,2): + forest(2,1) + nh(3,1) = 5.04798337584361
>  habitat(1,3,3): + forest(3,1) + nh(3,1) = 5.14843434561044
>  habitat(1,4,1): + forest(1,1) + nh(4,1) = 5.64155902015045
>  habitat(1,4,2): + forest(2,1) + nh(4,1) = 5.04798337584361
>  habitat(1,4,3): + forest(3,1) + nh(4,1) = 5.14843434561044
>  habitat(1,5,1): + forest(1,1) + nh(5,1) = 5.64155902015045
>  habitat(1,5,2): + forest(2,1) + nh(5,1) = 5.04798337584361
>  habitat(1,5,3): + forest(3,1) + nh(5,1) = 5.14843434561044
>
>
> Thanks.
>
> Noli
>
>
> On 11/6/12, Noli Sicad <address@hidden> wrote:
>> Hello Xypron,
>>
>> Yes, this is what I wanted. All the constraints are there.
>>
>> Nice tip as well with the param and set combo (below).
>>
>>> param nperiod := 3;
>>> param nnature := 20;
>>> param nstand := 20;
>>
>>> set PERIOD := {1..nperiod};
>>> set NATURE := {1..nnature};
>>> set STAND := {1..nperiod};
>>
>> Now, MathProg has easy way of implementing 'forall' constraints.
>>
>> Danke Schoen Xypron.
>>
>> It might be good to be added in the GLPK Wikibook.
>>
>> Robbie, would you like to add this in Wikibook?
>>
>> Thanks again.
>>
>> Regards,
>>
>> Noli
>>
>> On 11/6/12, Xypron <address@hidden> wrote:
>>> Hello Noli,
>>>
>>> could you provide the condition you want to formulate in mathematical
>>> notation?
>>>
>>> "forall" is used for logical expression. Did you mean "sum"?
>>> Instead of "p in 1..PERIOD" you may want to write "p in {1..PERIOD}".
>>> If p is a number {pp in p} does not make sense.
>>>
>>> Please, save the gmpl text below as test.mod, and run command.
>>> glpsol -m test.mod --check --wlp test.lp
>>>
>>> Check if test.lp contains the constraints you meant to write.
>>>
>>> Best regards
>>>
>>> Xypron
>>>
>>> # file test.lp
>>> param nperiod := 3;
>>> param nnature := 20;
>>> param nstand := 20;
>>
>>> set PERIOD := {1..nperiod};
>>> set NATURE := {1..nnature};
>>> set STAND := {1..nperiod};
>>
>>> param standarea {STAND} := 5 + 5 * Uniform01();
>>> var forest{STAND, PERIOD};
>>> var nh{NATURE, PERIOD};
>>> s.t. habitat{p in PERIOD, n in NATURE, s in STAND} :
>>>   sum{pp in PERIOD:pp <= p} forest[s, pp] + nh[n, p] = standarea[s];
>>> end;
>>>
>>>
>>> On 05.11.2012 19:29, Noli Sicad wrote:
>>>> Hi,
>>>>
>>>> I am trying to translate this set of LINDO constraint (below) into
>>>> MathProg. But I don't have any success.
>>>>
>>>> ######
>>>>
>>>> 37) S1P1 + N1P1 = 12.3
>>>> 38) S1P1 + S1P2 + N1P2 = 12.3
>>>> 39) S1P1 + S1P2 + S1P3 + N1P3 = 12.3
>>>>
>>>> 40) S2P1 + N2P1 = 35.6
>>>> 41) S2P1 + S2P2 + N2P2 = 35.6
>>>> 42) S2P1 + S2P2 + S2P3 + N2P3 = 34.6
>>>>
>>>> 43) S3P1 + N3P1 = 34.6
>>>> 44) S3P1 + S3P2 + N3P2 = 34.6
>>>> 45) S3P1 + S3P2 + S3P3 + N3P3 = 34.6
>>>>
>>>> .
>>>> .
>>>> .
>>>>
>>>> 94) S20P1 + N20P1 = 46.0
>>>> 95) S20P1 + S20P2 + N20P2 = 46.0
>>>> 96) S20P1 + S20P2 + S20P3 + N20P3 = 46.0
>>>>
>>>> ###########
>>>>
>>>> I tried to implement like this:
>>>>
>>>> subject to Habitat_Constraint{ p in 1..PERIOD, n in 1..NATURE, s in
>>>> STAND}:
>>>>    forall {pp in p} Forest[s,pp] + NH[n,p] = StandArea[s];
>>>>
>>>> However, I got this error below.
>>>>
>>>> #######
>>>> Running tool: GLPK/MathProg
>>>>
>>>> GLPSOL: GLPK LP/MIP Solver, v4.47
>>>> Parameter(s) specified in the command line:
>>>>  --math Model_I_1_original_5-evenflow_even-acres_OF_alter3.mod
>>>> Reading model section from
>>>> Model_I_1_original_5-evenflow_even-acres_OF_alter3.mod...
>>>> Model_I_1_original_5-evenflow_even-acres_OF_alter3.mod:77: domain
>>>> expression has invalid type
>>>> Context: ...ERIOD , n in 1 .. NATURE , s in STAND } : forall { pp in p
>>>> }
>>>> MathProg model processing error
>>>>
>>>> ########
>>>>
>>>> Anybody knows how to do this set of constraint properly in MathProg
>>>> properly?
>>>>
>>>> Any suggestions?
>>>>
>>>> Thanks.
>>>>
>>>> Regards,
>>>>
>>>> Noli
>>>>
>>>> _______________________________________________
>>>> Help-glpk mailing list
>>>> address@hidden
>>>> https://lists.gnu.org/mailman/listinfo/help-glpk
>>>>
>>>
>>>
>>
>



reply via email to

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