Ok, I came up with a possible solution, but it is not working. The
idea is to use recursion to construct the cartesian products and use
'setof' to obtain the final desired set, which is:
PivotalVotes = { (r_1, ..., r_L) : r_1 <= n_1, ..., r_L <= n_L and
sum {i in 1, ..., L} r_i = k }
The code is below, but if it helps reading it, here is the story:
there is a set of 'Parties', of cardinality 'L', and for each party
'l' there is a number of legislators 'n[l]'. The total number of
legislators is 'N', and to pass some piece of legislation, the
fraction of 'yes' votes must be greater than some fraction/quota 'q'.
That is, more than 'floor(N*q)' votes are needed. We want to define
the set of all possible combinations '(r1, ..., rL)' of 'yes' votes
(for example, (3,4) would be a configuration of 3 'yes' from the first
party, and 4 'yes' from the second party) such that the total number
of 'yes' is equal to 'floor(N*q)', that is, only one more 'yes' is
required pass the legislation. This set should be the set
'PivotalVotes' displayed above (same name in the code below).
The problems I'm having with the code (in the end of the message)
right now are the following:
1. If I import this code up to the definition of set 'C' (excluding
'D' and 'PivotalVotes') and create some data for it (Parties =
{Republicans, Democrats}), when I run 'display C', I get the following
error message:
Error executing "display" command:
can't convert 'Democrat' to a number.
I think the problem is when 'C[s-1]' is called (see code). I guess all
I need to do is to do everything in terms of numbers, not parties,
right? But I would like to keep the identity of the parties in the
code, and I would like to understand why the code below does not
define 'C' as I wanted.
2. If I import all of this code (saved as 'test.txt') and create some
data for it, I get an error when running 'model test.txt;':
ampl: model test.txt;
test.txt, line 12 (offset 409):
syntax error
context: set PivotalVotes = setof {r in D, i in {1..L}: >>> r[ <<<
i] <= n[i] and
Can anyone help?
Thanks in advance,
Guilherme
---- begin code ----
set Parties ordered; # Set of political parties
param L = card(Parties); # Number of parties
param n {Parties} integer > 0; # number of legislators in each party
param N = sum {l in Parties} n[l]
param q;
set C {s in Parties} = # auxiliary set
if s == first(Parties)
then {1..n[first(Parties)]}
else C[s-1] cross {1..n[member(s, Parties)]};
set D = C[last(Parties)]; # auxiliary set
set PivotalVotes = setof {r in D, i in {1..L} : r[i] <= n[i] and
sum {j in 1..L} r[j] = floor(N*q)} r;
# Set of pivotal votes. Auxiliar for the 'Prpiv' variable
set PivotalVotes = setof {r in D, i in {1..L}: r[i] <= n[i] and
sum {j in 1..L} r[j] = nq} r;
---- end code ----
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to
ampl@...
To unsubscribe from this group, send email to
ampl+unsubscribe@...
For more options, visit this group at
http://groups.google.com/group/ampl?hl=en-~----------~----~----~----~------~----~------~--~---