problem in Ampl

44 views
Skip to first unread message

Sara Vignoli

unread,
Jun 23, 2022, 1:17:27 PM6/23/22
to AMPL Modeling Language
hi, 
 i was wondering if anyone could help me write the constraint in the image. 

formula.png
where:
set V; #node
set E within {V,V}; #edge
set A within {V,V} ; #arc
set Gin {i in V} within A; #outgoing arcs from i
set Gout {i in V} within A; #incoming arcs in i

var f {i in V, j in V, (h,s) in A} binary;  

I tried to write it like this, but it tells me there is an error. 

subject to vincolo8 {i in V,j in V, k in V diff {i,j}, V: i<j}:
sum{(h,s)in Gin [k] and (h,s) not in  Gout[i]} f[i,j,h,s]
- sum{(h,s) in Gin [k] and (h,s) not in Gout[j]} f[i,j,h,s]=0;

Can you give me hand with this?

Thank you,
Sara

AMPL Google Group

unread,
Jun 23, 2022, 9:09:21 PM6/23/22
to AMPL Modeling Language
There is an extra V in the indexing of the constraint. It should be just {i in V, j in V, k in V diff {i,j}: i<j}. Also you can only define (h,s) once in an indexing set. For the first sum, you could use

{(h,s) in Gout[k]: (h,s) not in Gin[i]}

or equivalently

{(h,s) in Gout[k] diff Gin[i]}

The indexing for the second sum is written similarly.


--
Robert Fourer
am...@googlegroups.com
{#HS:1929582031-110669#}

Sara Vignoli

unread,
Jun 24, 2022, 12:16:33 PM6/24/22
to AMPL Modeling Language
thanks Robert for answering me.
 Hope you can help me complete my model. I am implementing an upgrade of the maximal covering location problem, in which it is possible to reduce the length of the edges, this has a certain cost and there is a pre-established budget. However, an error appears in the resolution phase: Error at _cmdno 3 executing "solve" command
(file MCLB.run, line 11, offset 103):
error processing constraint constraint6 ['I', 'I']: can't convert 'I' to a number.
this is the complete problem:
problema 1.png  
I am attaching the .mod and .dat files.

thanks to the availability,
Best regards
MCLB.mod
MCLB.dat

AMPL Google Group

unread,
Jun 24, 2022, 10:53:01 PM6/24/22
to AMPL Modeling Language
In your data, you say that V is a set of characters: "set V:= I B C D E F G H;". Thus when you write

subject to vincolo6 {i in V, j in V: i<j}: ...

you are using < to compare two characters. But "i < j" is only accepted in AMPL when i and j are numbers, and when you use < to compare two characters, you get an error message like "can't convert 'I' to a number."

You could avoid this problem by defining V as an ordered set:

set V ordered;

Then the indexing of your constraint could be written correctly like this:

subject to vincolo6 {i in V, j in V: ord(i)<ord(j)}: ...}:>

There are some other constraints in your model where an expression like this also needs to be fixed.

For an explanation of ordered sets and ordered set functions like ord, see section 5.6 Ordered sets and section A.6.2 Ordered sets in the AMPL book.


--
Robert Fourer
am...@googlegroups.com
{#HS:1929582031-110669#}
On Fri, Jun 24, 2022 at 4:16 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
thanks Robert for answering me.
Hope you can help me complete my model. I am implementing an upgrade of the maximal covering location problem, in which it is possible to reduce the length of the edges, this has a certain cost and there is a pre-established budget. However, an error appears in the resolution phase: Error at _cmdno 3 executing "solve" command
(file MCLB.run, line 11, offset 103):
error processing constraint constraint6 ['I', 'I']: can't convert 'I' to a number.
this is the complete problem:
problema 1.png
I am attaching the .mod and .dat files.

thanks to the availability,
Best regards

On Fri, Jun 24, 2022 at 1:08 AM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
There is an extra V in the indexing of the constraint. It should be just {i in V, j in V, k in V diff {i,j}: i<j}. Also you can only define (h,s) once in an indexing set. For the first sum, you could use

{(h,s) in Gout[k]: (h,s) not in Gin[i]}

or equivalently

{(h,s) in Gout[k] diff Gin[i]}

The indexing for the second sum is written similarly.


--
Robert Fourer
am...@googlegroups.com

Sara Vignoli

unread,
Jun 27, 2022, 8:47:47 AM6/27/22
to AMPL Modeling Language
Thank you so much for your help and availability 
Best regards.

Reply all
Reply to author
Forward
0 new messages