<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">You have a wrong semicolon in your
nested loop.<br>
<br>
You must consider the difference between expressions and
statements, as common in programming languages. "sum { i in
export_ports: route_tonnage[[i, m], j,k] }" is an expression, so a
semicolon before the closing curly bracket would be wrong. But
"import_tonnage[m,j,k]=sum { i in export_ports: route_tonnage[[i,
m], j,k] };" is a statement, so the semicolon at the end of it is
correct.<br>
<br>
Thomas Schleiff<br>
<br>
<br>
Am 11.10.2017 um 17:44 schrieb Richard Males:<br>
</div>
<blockquote type="cite"
cite="mid:CAGwArwYFnmeOdknB2nhRsRPgDTbE9pZ7Ysk4dLbCCEPM8etLnA@mail.gmail.com">
<div dir="ltr">
<p>I am currently interested in the syntax for assigning a sum
within a loop, in effect a nested loop. I have sets of import
and export ports and routes defined on them (thanks to Thomas
Schlieff for help on specifying the routes):<br>
</p>
export_ports := set("Santos","NewOrleans","Seattle");<br>
import_ports:= set("ChinaIP", "EuropeIP", "MexicoIP", "JapanIP",
"SoutheastAsiaIP","FSU-MiddleEastIP","KoreaIP");<br>
routes := [export_ports, import_ports];<br>
and variables<br>
route_tonnage[routes,seasons,grains]:real[0..];
<p style="margin:0px;text-indent:0px">export_tonnage[export_ports,seasons,grains]:real[0..];</p>
<p style="margin:0px;text-indent:0px">import_tonnage[import_ports,seasons,grains]:real[0..];</p>
<br>
Using this framework, I want to be able to determine the total
quantity coming in from all routes to an import port as an
intermediate variable. I also have indices of seasons (1 to 4)
and grains (currently only "Soybeans"). I am able to do this by
enumerating for each import port, season, and grain, as follows,
but if I try to generalize to loop over the set of import ports
so that I don't need to repeat my lines, I get syntax errors.<br>
<p style="margin:0px;text-indent:0px">import_tonnage["ChinaIP",1,"Soybeans"]=sum
{ i in export_ports: route_tonnage[[i, "ChinaIP"],
1,"Soybeans"] };</p>
<p style="margin:0px;text-indent:0px">import_tonnage["ChinaIP",2,"Soybeans"]=sum
{ i in export_ports: route_tonnage[[i, "ChinaIP"],
2,"Soybeans"] };</p>
<p style="margin:0px;text-indent:0px">import_tonnage["ChinaIP",3,"Soybeans"]=sum
{ i in export_ports: route_tonnage[[i, "ChinaIP"],
3,"Soybeans"] };</p>
<p style="margin:0px;text-indent:0px">import_tonnage["ChinaIP",4,"Soybeans"]=sum
{ i in export_ports: route_tonnage[[i, "ChinaIP"],
4,"Soybeans"] };</p>
<p style="margin:0px;text-indent:0px">import_tonnage["EuropeIP",1,"Soybeans"]=sum
{ i in export_ports: route_tonnage[[i, "EuropeIP"],
1,"Soybeans"] };</p>
<p style="margin:0px;text-indent:0px">import_tonnage["EuropeIP",2,"Soybeans"]=sum
{ i in export_ports: route_tonnage[[i, "EuropeIP"],
2,"Soybeans"] };</p>
<p style="margin:0px;text-indent:0px">import_tonnage["EuropeIP",3,"Soybeans"]=sum
{ i in export_ports: route_tonnage[[i, "EuropeIP"],
3,"Soybeans"] };</p>
<p style="margin:0px;text-indent:0px">import_tonnage["EuropeIP",4,"Soybeans"]=sum
{ i in export_ports: route_tonnage[[i, "EuropeIP"],
4,"Soybeans"] };</p>
<p>I want to do something like:</p>
<p style="margin:0px;text-indent:0px">{m in import_ports,j in
seasons, k in grains: import_tonnage[m,j,k]=sum { i in
export_ports: route_tonnage[[i, m], j,k];};}</p>
<p style="margin:0px;text-indent:0px"><br>
</p>
but this yields error messages relating to the double-nested
curly braces.<br>
<br>
Any suggestions as to a simplifying approach would be
appreciated. Thanks in advance.<br>
<br>
Dick Males</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
Cmpl mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Cmpl@list.coin-or.org">Cmpl@list.coin-or.org</a>
<a class="moz-txt-link-freetext" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__list.coin-2Dor.org_mailman_listinfo_cmpl&d=DwICAg&c=Ngd-ta5yRYsqeUsEDgxhcqsYYY1Xs5ogLxWPA_2Wlc4&r=bC-ot6cnDq3NJprIa2U54ZW0PXGvQSMdgN_s4GhXuu8&m=5Orel3YhSGsQGudTLGB0FmEPcgSfhnHERZy3COuRlvA&s=nW_9_NLdBPlp0daEmQoOrFCykcKoLtw52gnAlvKu_Yc&e=">https://urldefense.proofpoint.com/v2/url?u=https-3A__list.coin-2Dor.org_mailman_listinfo_cmpl&d=DwICAg&c=Ngd-ta5yRYsqeUsEDgxhcqsYYY1Xs5ogLxWPA_2Wlc4&r=bC-ot6cnDq3NJprIa2U54ZW0PXGvQSMdgN_s4GhXuu8&m=5Orel3YhSGsQGudTLGB0FmEPcgSfhnHERZy3COuRlvA&s=nW_9_NLdBPlp0daEmQoOrFCykcKoLtw52gnAlvKu_Yc&e=</a> </pre>
</blockquote>
<p><br>
</p>
</body>
</html>