<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2658.24">
<TITLE>Question on the iteration in flopc++</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=2 FACE="Century Gothic">Hi, folks,</FONT>
</P>

<P><FONT SIZE=2 FACE="Century Gothic">I converted an ampl model to flopc++, encountered some behavior I could not quite figured out. I trimmed the model to the attached below sample to explain the problem I am seeing..</FONT></P>

<P><FONT SIZE=2 FACE="Century Gothic">In the constraint definiation, I am trying to iterate all the locations and caculate the location inventory (initial + what's in - what's out) where they should be non-negative.. For some reason, the iteration does not sees to work in flopc++,</FONT></P>

<P><FONT SIZE=2 FACE="Century Gothic">Here is the flopc++ constraint, </FONT>
<BR><FONT SIZE=2 FACE="Century Gothic">&nbsp; inventoryConstraint(loc) = </FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Century Gothic">sum(flows(srcloc, loc), inventoryMove(srcloc, loc)) - </FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Century Gothic">sum(flows(loc, destloc), inventoryMove(loc, destloc)) + initialInventory(loc) &gt;= zero;</FONT>
</P>

<P><FONT SIZE=2 FACE="Century Gothic">Here is the equivalent AMPL version of constraint</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic">subject to inventoryConstraint { loc in locations } :</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InitialInventory[loc]</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + sum { srcloc in locations: ((srcloc, loc) in Flows)} inventoryMove[srcloc,loc]</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - sum { destloc in locations: ((loc,destloc) in Flows)} inventoryMove[loc,destloc]</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &gt;= 0;</FONT>
</P>

<P><FONT SIZE=2 FACE="Century Gothic">The attached is the version of flopc++ sample..</FONT>
</P>

<P><FONT SIZE=2 FACE="Century Gothic">Thanks,</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic">Qi</FONT>
</P>

<P><FONT SIZE=2 FACE="Century Gothic">//----------------------</FONT>
</P>

<P><FONT SIZE=2 FACE="Century Gothic">&nbsp; enum { a, b, numOfLocations}; // assuming 2 locations for now</FONT>
</P>

<P><FONT SIZE=2 FACE="Century Gothic">&nbsp; MP_set locations(numOfLocations); </FONT>
</P>

<P><FONT SIZE=2 FACE="Century Gothic">&nbsp; MP_subset&lt;2&gt; flows(locations, locations); /* src to dest */</FONT>
</P>

<P><FONT SIZE=2 FACE="Century Gothic">&nbsp; /* dynamic data set */</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic">&nbsp; MP_data flowCost(flows);</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic">&nbsp; MP_data locationBenefit(locations);</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic">&nbsp; MP_data initialInventory(locations); </FONT>
</P>

<P><FONT SIZE=2 FACE="Century Gothic">&nbsp; flows.insert(a,b);</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic">&nbsp; flows.insert(b,a);</FONT>
</P>

<P><FONT SIZE=2 FACE="Century Gothic">&nbsp; flowCost(flows(a,b)) = 200;</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic">&nbsp; flowCost(flows(b,a)) = 200;</FONT>
</P>

<P><FONT SIZE=2 FACE="Century Gothic">&nbsp; locationBenefit(a) = 0;</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic">&nbsp; locationBenefit(b) = 2500;</FONT>
</P>

<P><FONT SIZE=2 FACE="Century Gothic">&nbsp; initialInventory(a) = 5;</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic">&nbsp; initialInventory(b) = 10;</FONT>
</P>

<P><FONT SIZE=2 FACE="Century Gothic">&nbsp; MP_variable inventoryMove(flows); // movement along defined flows..</FONT>
</P>

<P><FONT SIZE=2 FACE="Century Gothic">&nbsp; /**</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic">&nbsp;&nbsp; ** location inventory = initial inventory + what's coming in - what's going out&nbsp; &gt;= 0</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic">&nbsp;&nbsp; **/</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic">&nbsp; MP_constraint inventoryConstraint(locations);</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic">&nbsp; MP_index loc, srcloc, destloc;</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic">&nbsp; Constant zero(0);</FONT>
</P>

<P><FONT SIZE=2 FACE="Century Gothic">&nbsp; inventoryConstraint(loc) = </FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Century Gothic">sum(flows(srcloc, loc), inventoryMove(srcloc, loc)) - </FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Century Gothic">sum(flows(loc, destloc), inventoryMove(loc, destloc)) + initialInventory(loc) &gt;= zero;</FONT>
</P>

<P><FONT SIZE=2 FACE="Century Gothic">&nbsp; MP_expression exp =</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Century Gothic">sum(locations(loc), locationBenefit(loc) * (initialInventory(loc) + sum(flows(srcloc, loc), inventoryMove(srcloc, loc)) - sum(flows(loc, destloc), inventoryMove(loc,destloc)))) </FONT></P>

<P><FONT SIZE=2 FACE="Century Gothic">&nbsp;&nbsp;&nbsp; - </FONT>
<BR><FONT SIZE=2 FACE="Century Gothic">&nbsp;&nbsp;&nbsp; sum(flows(srcloc, destloc), flowCost(srcloc, destloc) * inventoryMove(srcloc, destloc));</FONT>
</P>

<P><FONT SIZE=2 FACE="Century Gothic">&nbsp; maximize(exp);</FONT>
</P>

<P><FONT SIZE=2 FACE="Century Gothic">&nbsp; inventoryMove.display(&quot;Movement&quot;);</FONT>
</P>

</BODY>
</HTML>