<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>