sum {r in R} r not defined

2,389 views
Skip to first unread message

pamela....@gmail.com

unread,
Aug 27, 2008, 12:46:01 PM8/27/08
to AMPL Modeling Language
Hi all,

I am trying to solve a non-linear system of equations, I am using
Knitro and I have my data in a data file. When I run the program I get
the following error:

"r is not defined"
context: focd1:sum{r in R} (1/(nn*d3))*bid[r,1]+(V[r]-pzero[r])*((1/nn)
+1)

I get that message twice for var focd1, four times for var focd2, and
four times for var focd3. Then I get a message that says "bailing out
after 10 warnings".

Does anyone knows what I am doing wrong (my program is pasted below)?

Thanks,
Pamela

The program

param nn; #:=3 # number of bidders
param nr; #:=100 # number of simulations
set N := 1..nn; # N is the index set of bidders
set R := 1..nr; # R is the vector simulations


## Define input data: This input data is defined in the data file
param V {r in R}; # V[r] is the value of the object at simulation r
param S {r in R, n in N} ; #S[r,n] signal for bidder n at simulation r
param Si {r in R}; #S[r] signal for bidder i (the first bidder) at
simulation r


#variables
var d1;
var d2 <= 0, := 0;# := starting value
var d3 <= 0, := 0;
var pzero{r in R}=(1-nn*d1-d2*sum{n in N}(1/S[r,n]))/(nn*d3);
var bid {r in R, n in N} = d1+d2/S[r,n]+d3*pzero[r];
##When I write bid[r,1], what I want is to sum the first column of the
matrix bid
var focd1 = sum{r in R} (1/(nn*d3))*bid[r,1]+(V[r]-pzero[r])*((1/nn)
+1);
var focd2 = sum{r in R} ((1/Si[r])/(nn*d3))*bid[r,1]+(V[r]-
pzero[r])*(((1/Si[r])/nn)+(1/Si[r]));
var focd3 = sum{r in R} (pzero[r]/(nn*d3))*bid[r,1]+(V[r]-
pzero[r])*((pzero[r]/nn)+pzero[r]);

maximize obj : 1;

subject to

focd11 : focd1 = 0;
focd21 : focd2=0;
focd31 : focd3 =0;
positivebids {r in R, n in N}: bid[r,n] >= 0;

Robert Fourer

unread,
Aug 29, 2008, 6:59:34 PM8/29/08
to am...@googlegroups.com, pamela....@gmail.com
Pamela,

Consider

var focd1 = sum {r in R}
(1/(nn*d3))*bid[r,1]+(V[r]-pzero[r])*((1/nn)+1);

By default a summation extends only to the first + sign following, so r is
defined only for (1/(nn*d3))*bid[r,1]. Subsequently r is not defined in
(V[r]-pzero[r])*((1/nn)+1), resulting in the two error messages. The
situation is similar for focd2 and focd3.

To get the results you want, put the entire argument of the summation in
parentheses. For example:

var focd1 = sum {r in R}

( (1/(nn*d3))*bid[r,1]+(V[r]-pzero[r])*((1/nn)+1) );

Bob Fourer
4...@ampl.com

Ziming Guan

unread,
Aug 29, 2008, 7:15:24 PM8/29/08
to am...@googlegroups.com
Put a bracket around all the terms after sum{r in R}.

Ziming

pamela....@gmail.com

unread,
Sep 2, 2008, 12:03:54 PM9/2/08
to AMPL Modeling Language
Thanks.

On 29 Aug, 18:15, Ziming Guan <z.g...@auckland.ac.nz> wrote:
> Ziming- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages