display "no value" error for computed parameter

967 views
Skip to first unread message

Chaimaa ESSAYEH

unread,
Jun 22, 2017, 7:48:21 AM6/22/17
to AMPL Modeling Language
Hello,

I have a computed parameter which is a function of other parameters as well as some variables.

So, I first declare it:
    
     param beta{battery, panel, 1..T};

And then after, I write its expression as a constraint:

      subject to beta_limits {b in battery, pv in panel, t in 1..T}: 
       
      beta[b,pv,t] = (if  (N_PV[pv,b] * G[pv,t] )- L[t]   < max (-(N_B[pv,b] * betamin[b]) , (N_B[pv,b] * Cmin[b] - SE[b,pv,t]) * n_dis[b]) then 0
   else
(if  (N_PV[pv,b] * G[pv,t] )- L[t]  >  min ( betamax[b] * N_B[pv,b] , (N_B[pv,b] * Cmax[b] - SE[b,pv,t]) / n_char[b])  then min ( betamax[b] * N_B[pv,b] , (N_B[pv,b] * Cmax[b] - SE[b,pv,t]) / n_char[b])
 else (N_PV[pv,b] * G[pv,t] )- L[t] 
 )
  );

I note that the expression of the constraint contains parameters except:

       N_PV[pv,b], N_B[pv,b] which are variables, and
       SE[b,pv,t] which is a computed parameter having variables in its expression

When trying to solve the model, I get the error:

           error processing objective total_cost['pv1','b1']:
   no value for beta['b1','pv1',1]

The files .mod and .dat are attached for clearer readability.

Can anybody help me with that please?

Thank you in advance
ampl-data.dat
sizingampl.mod

Robert Fourer

unread,
Jun 23, 2017, 9:46:48 AM6/23/17
to am...@googlegroups.com
Every parameter must have a known value before you invoke "solve" to send the problem to the solver. A message like "no value for beta['b1','pv1',1]" indicates that you are trying to solve but AMPL does not know a value for this parameter.

Since a parameter must have a known value before solving, it cannot be a function of variables. If you want beta[b,pv,t] to be a function of variables in your model, then you must declare beta as a variable.

Bob Fourer
am...@googlegroups.com

=======

Chaimaa ESSAYEH

unread,
Jun 23, 2017, 10:22:04 AM6/23/17
to AMPL Modeling Language, 4...@ampl.com
Thank you for the reply Mr. Robert.

However, even if the parameter beta is function of variables, I did give initial values to all the variables that are included in its expression so that to avoid the error. Besides, "Variables in AMPL are decision variables. They should be used only for values that are to be set by the solver" (That was your quote from the discussion https://groups.google.com/forum/#!topic/ampl/9ed1xDsbTYI :) )

So, if I set beta as a variable, its values will be set by the solver, which is not feasible in my case. 

Despite that fact, I've tried to set beta as variable, but the model were too complicated that it runs out of memory when I tried to solve it!

Thank you for your help.

Robert Fourer

unread,
Jun 24, 2017, 12:34:57 PM6/24/17
to am...@googlegroups.com
You can define parameter beta in terms of the initial values of the variables. To do this, you must include a defining expression in the "param beta ..." statement, and you must use .val after any variables in the defining expression. Thus your definition of beta should begin like this:

param beta {b in battery, pv in panel, t in 1..T} =
if N_PV[pv,b].val * G[pv,t] - L[t] < ...

When you write .val after a variable reference, you tell AMPL to use the current value of the variable, which normally would be the same as the initial value. However if you do not write .val after some variable reference in this definition, then AMPL will give you a "variable in = expression" error. (AMPL requires .val in this circumstance so that you do not accidentally write a variable in a param definition and get unexpected results.)

Bob Fourer
am...@googlegroups.com

=======

From: am...@googlegroups.com [mailto:am...@googlegroups.com] On Behalf Of Chaimaa ESSAYEH
Sent: Friday, June 23, 2017 9:22 AM
To: AMPL Modeling Language

Chaimaa ESSAYEH

unread,
Jun 24, 2017, 2:16:33 PM6/24/17
to AMPL Modeling Language, 4...@ampl.com
Thank you Mr Robert!

I appreciate it. Your help was very useful for my model.

Thank you.

Chaimaa ESSAYEH

unread,
Jun 30, 2017, 11:51:19 AM6/30/17
to AMPL Modeling Language, 4...@ampl.com
Hello again,

I have two parameters indexed over time: A[t] and B[t].  
         B[t] is a function of A[t]  ( B[t] = f { A[t] } ) 
  and  A[t+1] =  A[t] - B[t].

Once we have just A[1], We can see the process of the definition of the two parameters like this: A[1] -> B[1] -> A[2] -> B[2] -> ... A[T] -> B[T].

The problem is that I cannot define the param "A" before "B" because AMPL returns the error "no value for B[1]" (which is evident since the A[2] calls B[1] not yet defined)
 nor define "B" before "A" because it returns "no value for A[1]"  (because B is dependent on A)

I tried to define the two parameters in a for loop in my model like this:
##############################"
param A{t in 1..T}  default a;       # a is the value of initialization that has to be assigned to A[1]
param B{ t in 1 ..T}         
for {t in 1..T}
{
let B[t]= ...;
let A[t+1] := A[t] - B[t];
}
##########################
and this returns that T is not defined.

I also tried to use update data instead of let, but it didn't work (apparently update can only be used in a .run file). I don't know if I can use a for loop inside a model...

I know that the two parameters should be defined in a recursive way, but I don't know how to write it in an AMPL syntax.

Does anybody have an idea?
Thank you in advance!



Robert Fourer

unread,
Jul 3, 2017, 10:46:15 AM7/3/17
to am...@googlegroups.com
The idea of your "for" loop is good, but there are syntax errors: a missing ";" at the end of a param statement, an = instead of := in a let statement. Also the last time through the loop you will get an error because you try to assign a value to A[T+1] which does not exist; you could fix the loop to avoid this or else define A to be indexed over {1..T+1}.

Also be sure that you have a "param T;" statement in your model.

Bob Fourer
am...@googlegroups.com

=======

From: am...@googlegroups.com [mailto:am...@googlegroups.com] On Behalf Of Chaimaa ESSAYEH
Sent: Friday, June 30, 2017 10:51 AM
To: AMPL Modeling Language
Cc: 4...@ampl.com

Chaimaa ESSAYEH

unread,
Jul 5, 2017, 2:11:32 PM7/5/17
to am...@googlegroups.com
Yes, you are right. I've corrected the syntax, but the error still occur.

When I put the loop in the model, AMPL returns the error 'T is not defined' which means that it did not read the data (T is declared in the .mod file, and it is given a value in the .dat file).

So, I've tried to put the loop in the .dat file, and in the .run file, but in both cases, AMPL returns another error 'no value for B[1]'

--
You received this message because you are subscribed to a topic in the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ampl/wSkTmMu3pDQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ampl+unsubscribe@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.



--
Chaimaa ESSAYEH

Certified SAP Associate Consultant (HANA Modeling)
Engineer in ICTs (Information & Communication Technologies)
PhD. Student  
CEDOC-2IT, INPT (National Institut of Posts et Télécommunications)

Robert Fourer

unread,
Jul 7, 2017, 7:36:33 AM7/7/17
to am...@googlegroups.com
The "T is not defined" message indicates a model error: At the point in your model where "T" is used, it has not yet been declared. If the problem was that T had been declared but no data had been given for T, then you would see a message like "no value for T" instead.

It is best to put a loop in the .run file, however. If you can post your files, with the loop in the .run file, then it may be possible to give more specific help. It's best to reply to this forum with your files as attachments to your email.

Chaimaa ESSAYEH

unread,
Jul 10, 2017, 10:44:35 AM7/10/17
to AMPL Modeling Language, 4...@ampl.com
Attached the files (.mod, .dat and .run) of my model.

parameter A is called in my model SE, and param B as beta.

I forgot to mention that the expressions of the two parameters contain .val suffix. Would it be the source of the error?
ampl-data.dat
amplsize.run
sizingampl.mod

Robert Fourer

unread,
Jul 12, 2017, 10:14:32 AM7/12/17
to am...@googlegroups.com
The error that I see when running your example is

Error at _cmdno 2 executing "for" command
(file ../sizingampl.mod, line 53, offset 2621):
no data for set battery

This is because you are trying to execute a "for" loop in your model, before the data file has been read. This could be fixed by moving the loop to amplsize.run, after the data statement, but then I see the problem you are referring to, where something triggers the processing of objective total_cost before the computation of beta can be carried out:

Error at _cmdno 3 executing "let" command
(file ../amplsize.run, line 6, offset 102):
error processing objective total_cost['pv1','b1']:
no value for beta['b1','pv1',1]

A workaround is to give beta a default value:

param beta {b in battery, pv in panel, t in 1..T} default 0;

Then the solver runs as shown below. The use of N_B[pv,b].val in the expressions is probably triggering this issue, though I haven't had time to test it. Note that .val gives the current value of the variable at the time that the expression is evaluated; since you have not solved yet, this would be the default value of 1 unless you have assigned a different value.

Bob Fourer
am...@googlegroups.com


ampl: include amplsize.run
Knitro 10.2.0: Locally optimal solution.
objective 2584.41092; integrality gap 0
3 nodes; 4 subproblem solves

suffix incumbent OUT;
suffix relaxbnd OUT;
: N_PV N_B :=
pv1 b1 6 1
pv1 b2 1 1
pv2 b1 1 1
pv2 b2 1 1
pv3 b1 1 1
pv3 b2 1 1
;

ampl:

=======

From: am...@googlegroups.com [mailto:am...@googlegroups.com] On Behalf Of Chaimaa ESSAYEH
Sent: Monday, July 10, 2017 9:45 AM
To: AMPL Modeling Language
Cc: 4...@ampl.com

Chaimaa ESSAYEH

unread,
Jul 12, 2017, 12:35:32 PM7/12/17
to am...@googlegroups.com
Indeed Mr. Robert.

When I give a default value to the beta parameter, the resolution does not include optimizing the second variable. And the beta parameter is not changing over the time, it keeps the default value.

--
You received this message because you are subscribed to a topic in the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ampl/wSkTmMu3pDQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ampl+unsubscribe@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.

Robert Fourer

unread,
Jul 13, 2017, 9:13:13 AM7/13/17
to am...@googlegroups.com
Did you move the loop for assigning beta values into amplsize.run, after the data statement? Then you can temporarily add "display beta >beta.out;" after the loop to confirm that the correct values were assigned. (Look in the file beta.out to see the values -- it is a long listing.)

Bob Fourer
am...@googlegroups.com

=======

From: am...@googlegroups.com [mailto:am...@googlegroups.com] On Behalf Of Chaimaa ESSAYEH
Sent: Wednesday, July 12, 2017 11:35 AM
To: am...@googlegroups.com

Chaimaa ESSAYEH

unread,
Jul 21, 2017, 7:28:42 AM7/21/17
to am...@googlegroups.com
Sorry for this late response,

I've done what you asked me, and run the system many times to check the correctness of the model.
Apparently, when the variable N_PV is incremented (or more generally updated), the parameter beta remains stuck in its first value when N_PV=1. (As you can see in the .run file, the expression of the beta involves N_PV, and it should change when N_PV is updated. Yet, that was not the case here even with putting .val after the variable N_PV)


 

--
You received this message because you are subscribed to a topic in the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ampl/wSkTmMu3pDQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ampl+unsubscribe@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.

Robert Fourer

unread,
Jul 21, 2017, 1:23:49 PM7/21/17
to am...@googlegroups.com
Can you post your files again? You can provide them as attachments to your email to this group. We want to be sure that we are giving advice based on the exact versions of the files that you are currently using.

Chaimaa ESSAYEH

unread,
Jul 22, 2017, 6:04:09 AM7/22/17
to am...@googlegroups.com
Yes, of course. You find them attached.
Thank you for the valuable help.

--
You received this message because you are subscribed to a topic in the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ampl/wSkTmMu3pDQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ampl+unsubscribe@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.
ampl-data.dat
amplsize.run
sizingampl.mod

Robert Fourer

unread,
Jul 22, 2017, 9:10:59 PM7/22/17
to am...@googlegroups.com
When you assign values to beta using "let" statements in a loop,

for {b in battery, pv in panel, t in 1..T} {
let beta[b,pv,t] := (if (( N_PV[pv,b].val ...

then the values for beta are only changed when the loop is executed. In this situation, if you change the N_PV values, AMPL does not automatically recompute the beta values. Instead to update the beta values, after each time that the N_PV values are changed, your AMPL run file needs to execute the whole loop again.

You could try instead moving the definition of beta to the model file, replacing your current "param beta" statement with

param beta {b in battery, pv in panel, t in 1..T} :=
(if (( N_PV[pv,b].val ...

Then the beta values *will* be updated each time that the N_PV values are changed. However in your run file you will still need to execute

let {b in battery, pv in panel, t in 1..T}
SE[b,pv,t+1] := SE[b,pv,t] + ( if (( N_PV[pv,b].val * G[pv,t] )- L[t]) < 0
then -beta[b,pv,t]/n_dis[b] else beta[b,pv,t]*n_char[b]);

to update the SE values each time that the N_PV (and beta) values change.
Reply all
Reply to author
Forward
0 new messages