Writing and reading set of indexed arcs data from spreadsheet

52 views
Skip to first unread message

Vivi

unread,
Jan 22, 2021, 2:52:14 AM1/22/21
to AMPL Modeling Language
Dear Mr Robert,

I'm writing to you for the following issue I have:

set NP ; # Set of the plants
set ND ; # :set of DC
set STL {NP} within ND; # :set of DC served by  plant p
set NC ; # :Set of customers
set CUST {ND} within NC; # set of customers served by  DC d
set A1 {p in NP} within ((NP cross STL [p]) union (STL [p] cross (NP union STL [p]))) ; # Set of arcs between Plant p and DC served by this plant and between those DC served by this plant
set A2 {d in ND} within ((ND cross CUST[d]) union (CUST[d] cross (NS union CUST[d]))); # Set of arcs between a DC d and its customers and between thoses customers
 
I would like to read the parameter
param T_LINKS_F1 {d in ND, A1[d]} >= 0 ; # Travel  time on arcs of set A1
from spreadsheet, I am not very sure how to write it.
I'am writing to you to request your help.

Thanks in advance

Best regards.

Viviane

Vivi

unread,
Jan 22, 2021, 4:42:58 PM1/22/21
to AMPL Modeling Language
Dear Mr Robert,

I'm writing to you again because I have forgotten to give data for the sets in my model . So the definition of the sets is as follow:

set NP ; # Set of the plants
set ND ; # :set of DC
set STL {NP} within ND; # :set of DC served by  plant p
set NC ; # :Set of customers
set CUST {ND} within NC; # set of customers served by  DC d
set A1 {p in NP} within (({p} cross STL [p]) union (STL [p] cross ({p}union STL [p]))) ; # Set of arcs between Plant p and DC served by this plant and between those DC served by this plant
set A2 {d in ND} within (({d} cross CUST[d]) union (CUST[d] cross ({d} union CUST[d]))); # Set of arcs between a DC d and its customers and between thoses customers
 
And data for those sets are:
set NP := P1 P2 ;
set ND := DC1 DC2 ;
set NC := C1 C2 C3 C4 ;
set STL[P1] := DC1 ;
set STL[P2] := DC2 ;
set CUST[DC1]  := C1 C2 ;
set CUST[DC2]  := C3 C4 ;

I would like to read  the set  A1 {p in NP} and also param T_LINKS_F1 {d in ND, A1[d]} from spreadsheet. I am not very sure how to write it.
I'am writing to you to request your help.

Thanks in advance

Best regards.

AMPL Google Group

unread,
Jan 22, 2021, 6:19:51 PM1/22/21
to AMPL Modeling Language
These definitions do not seem right:

set A1 {p in NP};
param T_LINKS_F1 {d in ND, A1[d]}
;

A1 is defined for p in NP, but here you have A1[d] where d in is ND. I would expect to see this instead:

param T_LINKS_F1 {p in NP, A1[p]};

Is this what you mean? Or should A1 be indexed over {d in ND}?

Also, to get help with the spreadsheet, you will need to give the data for A1 and for T_LINKS_F1.


--
Robert Fourer
am...@googlegroups.com
{#HS:1403459003-98899#}

Viviane AGNIMO

unread,
Jan 22, 2021, 9:39:31 PM1/22/21
to am...@googlegroups.com
Dear Mr Robert,

I'am sorry for the mistake. As you have noticed, the parameter T_LINKS_F1 that I would like to ask you how to write it on spreedsheat file is indexed over p like this expression param T_LINKS_F1 {p in ND, A1[p]}. I would also like to ask you how to write the set  A1 {p in NP} on spreedsheat.

The data for those parameters are in the data file joined.

The other sets are defined as follow:


set NP ; # Set of the plants
set ND ; # :set of DC
set STL {NP} within ND; # :set of DC served by  plant p
set NC ; # :Set of customers
set CUST {ND} within NC; # set of customers served by  DC d
set A1 {p in NP} within (({p} cross STL [p]) union (STL [p] cross ({p}union STL [p]))) ; # Set of arcs between Plant p and DC served by this plant and between those DC served by this plant
set A2 {d in ND} within (({d} cross CUST[d]) union (CUST[d] cross ({d} union CUST[d]))); # Set of arcs between a DC d and its customers and between thoses customers

Please receive my best regards.
m2.dat

AMPL Google Group

unread,
Jan 24, 2021, 6:00:52 PM1/24/21
to AMPL Modeling Language
An indexed collection of sets can be read from a single range in the spreadsheet, using a similarly indexed collection of tables. As an example, for your "set A1 {p in NP}" with the given data, the spreadsheet range could be named setA1, and could arranged like this:

f9347ca849def1e0d12c9385a90b1fae.png

Columns A1_P1_1 and A1_P1_2 contain the pairs that are in set A1["P1"], and columns A1_P2_1 and A1_P2_2 contain the pairs that are in set A1["P2"]. (It happens that A1["P1"] and A1["P2"] have the same number of members, but that is not necessary.) The corresponding table statement defines a table for each p in NP:

table setA1 {p in NP} IN "amplxl" "setofsets.xlsx":
A1[p] <- [("A1_"&p&"_1"),("A1_"&p&"_2")];


String expressions like ("A1_"&p&"_1") are used to specify the column names, which are different for each value of p.) Since there is an indexed collection of tables, a for-loop is used to read them:

for {p in NP} read table setA1[p];

Since A1[p] is a set of pairs, your "param T_LINKS_F1 {p in NP, A1[p]}" is indexed over a set of triples. Thus the spreadsheet table for this param should have 3 key columns and a data column:

5e28467f7d82491cb1098f6194d78565.png

and the table statement is straightforward:

table T_LINKS_F1 IN "amplxl" "setofsets.xlsx": [NP,A1_1,A1_2], T_LINKS_F1;

I have attached files for this example, which you can adapt to your full model.


--
Robert Fourer
am...@googlegroups.com
{#HS:1404311788-98953#}
On Fri, Jan 22, 2021 at 11:19 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
These definitions do not seem right:

set A1 {p in NP};
param T_LINKS_F1 {d in ND, A1[d]}
;

A1 is defined for p in NP, but here you have A1[d] where d in is ND. I would expect to see this instead:

param T_LINKS_F1 {p in NP, A1[p]};

Is this what you mean? Or should A1 be indexed over {d in ND}?

Also, to get help with the spreadsheet, you will need to give the data for A1 and for T_LINKS_F1.


--
Robert Fourer
am...@googlegroups.com
On Fri, Jan 22, 2021 at 9:43 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Dear Mr Robert,

I'm writing to you again because I have forgotten to give data for the sets
in my model . So the definition of the sets is as follow:


set NP ; # Set of the plants
set ND ; # :set of DC
set STL {NP} within ND; # :set of DC served by plant p
set NC ; # :Set of customers
set CUST {ND} within NC; # set of customers served by DC d
set A1 {p in NP} within (({p} cross STL [p]) union (STL [p] cross ({p}union
STL [p]))) ; # Set of arcs between Plant p and DC served by this plant and
between those DC served by this plant
set A2 {d in ND} within (({d} cross CUST[d]) union (CUST[d] cross ({d}
union CUST[d]))); # Set of arcs between a DC d and its customers and
between thoses customers

And data for those sets are:
set NP := P1 P2 ;
set ND := DC1 DC2 ;
set NC := C1 C2 C3 C4 ;
set STL[P1] := DC1 ;
set STL[P2] := DC2 ;
set CUST[DC1] := C1 C2 ;
set CUST[DC2] := C3 C4 ;

I would like to read the set A1 {p in NP} and also param T_LINKS_F1 {d in
ND, A1[d]} from spreadsheet. I am not very sure how to write it.
I'am writing to you to request your help.

Thanks in advance

Best regards.
On Fri, Jan 22, 2021 at 7:52 AM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Dear Mr Robert,

I'm writing to you for the following issue I have:

set NP ; # Set of the plants
set ND ; # :set of DC
set STL {NP} within ND; # :set of DC served by plant p
set NC ; # :Set of customers
set CUST {ND} within NC; # set of customers served by DC d
set A1 {p in NP} within ((NP cross STL [p]) union (STL [p] cross (NP union STL [p]))) ; # Set of arcs between Plant p and DC served by this plant and between those DC served by this plant
set A2 {d in ND} within ((ND cross CUST[d]) union (CUST[d] cross (NS union CUST[d]))); # Set of arcs between a DC d and its customers and between thoses customers
setofsets.run
setofsets.xlsx

Vivi

unread,
Jan 24, 2021, 8:59:52 PM1/24/21
to AMPL Modeling Language
Dear Mr Robert,

Once again thanks so much for your very clear explanation!

Viviane
Reply all
Reply to author
Forward
0 new messages