help-glpk
[Top][All Lists]
Advanced

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

Re: [Help-glpk] Emulating the AMPL ord() function


From: Heinrich Schuchardt
Subject: Re: [Help-glpk] Emulating the AMPL ord() function
Date: Tue, 30 Dec 2014 23:58:32 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.3.0

Hello Jason,

any of the following two models should do. If you want an other order but the lexical one just provide ord in the data section.

You write that you are using a generator program to create the exclude matrix. Why don't you directly write the allowed pairs instead of the matrix?

set P;
param exclude{P, P};
set ALLOWED_PAIRS, dimen 2 := setof{i in P, j in P : exclude[i,j] == 0 && exclude[j,i] == 0 && i < j} (i,j);
display ALLOWED_PAIRS;
data;
set P := person01 person02 person03 person04;
param   exclude:        person01 person02 person03 person04 :=  
        person01        0       1       0       0
        person02        1       0       0       1
        person03        1       0       0       1
        person04        0       1       1       0
;
end;

====

set P;
param exclude{P, P};
param ord{i in P} := sum{j in P: i > j} 1;
set ALLOWED_PAIRS, dimen 2 := setof{i in P, j in P : exclude[i,j] == 0 && exclude[j,i] == 0 && ord[i] < ord[j]} (i,j);
display ord;
display ALLOWED_PAIRS;
data;
set P := person01 person02 person03 person04;
param   exclude:        person01 person02 person03 person04 :=  
        person01        0       1       0       0
        person02        1       0       0       1
        person03        1       0       0       1
        person04        0       1       1       0
;
end;

Best regards

Heinrich Schuchardt

On 27.12.2014 20:13, Jason Foster wrote:
As part of shifting my group towards open source tools I've been working on 
converting some AMPL models to GMPL.  So far it's been working really well 
(thanks for some great work!) and I've just run into my first multi-hour snag.  
I've searched online and near as I can tell:

1) GMPL doesn't implement "ordered sets" (because "ordered" implies a 
mathematical ordering vs. the lexical ordering of the input text)
2) it is possible to work around some of these issues using a variety of 
techniques that require a reasonably deep understanding of GMPL

Regarding (2) there is a construct documented at 
http://lists.gnu.org/archive/html/help-glpk/2006-11/msg00059.html that I can't 
get to work as written:

set S;
param ref{i in 1..card(S)}, symbolic, in S; # ref[i] refers to i-th element of 
S;
param a{S};
a[ref[i]] # means a[i-th element of S]

The error I get is that ref[i] is empty.

There is also a fairly involved discussion at 
http://en.wikibooks.org/wiki/GLPK/GMPL_Workarounds that addresses sorted 
output.  I poked at that for a bit and ran into some difficulties because I am 
looking for the lexical position within the set, not the result of a 
calculation.

The problem I am trying to solve is that I have the following data:

set PEOPLE := person01 person02 person03 person04;

param   exclude:        person01 person02 person03 person04 :=  
        person01        0       1       0       0
        person02        1       0       0       1
        person03        1       0       0       1
        person04        0       1       1       0
;

exclude is "guaranteed" to be a symmetric matrix (assuming the generation code 
is working properly).  The AMPL code I have is trying to create:

set ALLOWED_PAIRS := {i in PEOPLE, k in PEOPLE: ( exclude[i, k] = 0 and exclude[k, 
i] = 0 ) and ( ord(i) < ord(k) )};

Of course this code doesn't work in GMPL because of the missing ord() function. 
 I believe that the goal is to precent the set from including redundant 
elements which will help keep the number of constraints down to something 
reasonable.

Based on what I've seen this should be a solvable problem using the tools 
available within GMPL but my current mental model isn't sufficient to work it 
out. I'm hoping that someone on the list can show a workaround and as such can 
help me continue the push to transition to a purely open source toolchain.

Thanks for any help or insights that you can offer!

Jason

Best regards

Heinrich Schuchardt




reply via email to

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