[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-glpk] Emulating the AMPL ord() function
From: |
Jason Foster |
Subject: |
[Help-glpk] Emulating the AMPL ord() function |
Date: |
Sat, 27 Dec 2014 19:13:54 +0000 |
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
- [Help-glpk] Emulating the AMPL ord() function,
Jason Foster <=