help-glpk
[Top][All Lists]

## Re: [Help-glpk] Empty Sets

 From: salani Subject: Re: [Help-glpk] Empty Sets Date: Wed, 23 Feb 2011 20:52:32 +0100

```Thanks to both of you (Xypron and Andrew).

Xypron, the reformulation you propose can be indeed better. But the model I
wrote was just
an illustrative example.

M

On Feb 23, 2011, at 8:11 PM, glpk xypron wrote:

> Hello Matteo,
>
> the following model works fine, what is you problem?
>
> param m, integer, >= 0;
> set T := 1 .. m;
> set S;
> param  aParameter{s in S}, integer, >= 0;
> param anotherParameter{s in S, t in T}, >= 0;
> set aSubSet{s in S} within T := {t in T : t > aParameter[s]};
> var aVariable{s in S}, >= 0;
> s.t. aConstraint{s in S, t in aSubSet[s]}: aVariable[s] >=
> anotherParameter[s,t];
> solve;
> display aSubSet;
> data;
> param m := 3;
> set S := ;
> param aParameter := 1 2 ;
> param anotherParameter := ;
> end;
>
> I would use the following formulation, which avoids parameter m:
>
> set A1, dimen 2;
> set A2, dimen 3;
> set S := setof{(i,j1) in A1, (i,j2,k2) in A2 : j1 < j2} (i,j2);
> set I := setof{(i,j) in S} i;
> param p{(i,j) in S} := sum{(i,j,k) in A2} k;
> var a{i in I}, >= 0;
> s.t. aConstraint{(i,j) in S}: a[i] >= p[i,j];
> solve;
> display p;
> data;
> set A1 :=
>  1 2;
> set A2 :=
>  1 1 10
>  1 2 20
>  1 3 30;
> end;
>
> Best regards
>
> Xypron
>
> -------- Original-Nachricht --------
>> Datum: Wed, 23 Feb 2011 16:02:17 +0100
>> Betreff: [Help-glpk] Empty Sets
>
>> I have a big model with sets, parameters, variables and constraints
>> divided in three sections and
>> interacting in 1 constraint.
>> I would like to use empty sets to basically "remove" parts of the model
>> dynamically via the data file.
>> The problem is that in my model some subsets are defined and this makes
>> GLPK unhappy.
>>
>>
>> Without posting the entire model, the problem is exactly equivalent to
>> make GLPK digest the following model:
>>
>> param m, integer, >= 0;
>>
>> set T := 1 .. m;
>> set S;
>>
>> param  aParameter{s in S}, integer, >= 0;
>> param anotherParameter{s in S, t in T}, >= 0;
>>
>> set aSubSet{s in S} within T := {t in T : t > aParameter[s]};
>>
>> var aVariable{s in S}, >= 0;
>>
>> s.t. aConstraint{s in S, t in aSubSet[s]}: aVariable[s] >=
>> anotherParameter[s,t];
>>
>>
>> This (clearly) works when S is non empty (e.g., with the following data)
>>
>> param m := 3;
>> set S := 1;
>> param aParameter := 1 2 ;
>> param anotherParameter :=
>>  1 1 10
>>  1 2 20
>>  1 3 10
>> ;
>>
>> S can be empty and the model works perfectly if I hard code this info,
>> i.e. the follwing model perfectly works:
>>
>> param m, integer, >= 0;
>> set T := 1 .. m;
>>
>> set S := {};  /* Hard coding an empty set */
>>
>> param  aParameter{s in S}, integer, >= 0;
>> set aSubSet{s in S} within T := {t in T : t > aParameter[s]};
>> param anotherParameter{s in S, t in T}, >= 0;
>> var aVariable{s in S}, >= 0;
>> s.t. aConstraint{s in S, t in aSubSet[s]}: aVariable[s] >=
>> anotherParameter[s,t];
>>
>> when I try to specify an empty set in the data file I cannot make it
>> work, though it is working in the above version:
>>
>> set S := {}; /* In the data file */
>>
>> obtaining: syntax error in set data block
>>
>> the other way round does not work either, i.e., defining an empty set in
>> the model and trying to override this in the data file.
>>
>> Whatever suggestion is appreciated.
>>
>> Thanks!
>> M
>>
>> --
>> *Matteo Salani*
>> IDSIA
>> Galleria 2
>> 6928 Manno-Lugano Switzerland
>> Web: http://www.idsia.ch/~salani <http://www.idsia.ch/%7Esalani>
>> Phone: +41 58 666 66 71
>>
>> _______________________________________________
>> Help-glpk mailing list