[Begginer] Solver error "can't convert 'K1' to a number

5 views
Skip to first unread message

Juan C

unread,
Feb 22, 2023, 9:06:51 AM2/22/23
to AMPL Modeling Language
Hi! I'm starting to use AMPL in my research project and I'm still learning about it.

The problem that i have had solving my model with cplexamp is the following:
Error executing "solve" command:
error processing constraint EACH_RESOURCE['K1']:
can't convert 'K1' to a number.

And the part of the .mod file that causes it is the following:
set J;
set K;
subject to EACH_RESOURCE {k in K}:
1 = sum{j in J} k;


I've read that maybe is a problem about the declaration of sets, but I'm confused and a little bit lost to be honest.

Thank you.

AMPL Google Group

unread,
Feb 22, 2023, 11:54:05 AM2/22/23
to AMPL Modeling Language
The "sum" operator can only be applied to numbers. So your immediate problem is that you have written "sum {j in J} k" where k is not a number. Specifically, the message "can't convert 'K1' to a number" suggests that k is equal to the character string "K1". (Since you defined {k in K}, it must be that "K1" is a member of your set K.)

However, you have a more serious problem, that the expression for your EACH_RESOURCE constraints does not have any variables in it. So you need to give more thought to what this constraint is really supposed to be saying, and what variables should appear in it.


--
Robert Fourer
AMPL Forum
{#HS:2163203748-114143#}
Reply all
Reply to author
Forward
0 new messages