<!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"> inventoryConstraint(loc) = </FONT>
<BR> <FONT SIZE=2 FACE="Century Gothic">sum(flows(srcloc, loc), inventoryMove(srcloc, loc)) - </FONT>
<BR> <FONT SIZE=2 FACE="Century Gothic">sum(flows(loc, destloc), inventoryMove(loc, destloc)) + initialInventory(loc) >= 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"> InitialInventory[loc]</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic"> + sum { srcloc in locations: ((srcloc, loc) in Flows)} inventoryMove[srcloc,loc]</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic"> - sum { destloc in locations: ((loc,destloc) in Flows)} inventoryMove[loc,destloc]</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic"> >= 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"> enum { a, b, numOfLocations}; // assuming 2 locations for now</FONT>
</P>
<P><FONT SIZE=2 FACE="Century Gothic"> MP_set locations(numOfLocations); </FONT>
</P>
<P><FONT SIZE=2 FACE="Century Gothic"> MP_subset<2> flows(locations, locations); /* src to dest */</FONT>
</P>
<P><FONT SIZE=2 FACE="Century Gothic"> /* dynamic data set */</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic"> MP_data flowCost(flows);</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic"> MP_data locationBenefit(locations);</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic"> MP_data initialInventory(locations); </FONT>
</P>
<P><FONT SIZE=2 FACE="Century Gothic"> flows.insert(a,b);</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic"> flows.insert(b,a);</FONT>
</P>
<P><FONT SIZE=2 FACE="Century Gothic"> flowCost(flows(a,b)) = 200;</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic"> flowCost(flows(b,a)) = 200;</FONT>
</P>
<P><FONT SIZE=2 FACE="Century Gothic"> locationBenefit(a) = 0;</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic"> locationBenefit(b) = 2500;</FONT>
</P>
<P><FONT SIZE=2 FACE="Century Gothic"> initialInventory(a) = 5;</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic"> initialInventory(b) = 10;</FONT>
</P>
<P><FONT SIZE=2 FACE="Century Gothic"> MP_variable inventoryMove(flows); // movement along defined flows..</FONT>
</P>
<P><FONT SIZE=2 FACE="Century Gothic"> /**</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic"> ** location inventory = initial inventory + what's coming in - what's going out >= 0</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic"> **/</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic"> MP_constraint inventoryConstraint(locations);</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic"> MP_index loc, srcloc, destloc;</FONT>
<BR><FONT SIZE=2 FACE="Century Gothic"> Constant zero(0);</FONT>
</P>
<P><FONT SIZE=2 FACE="Century Gothic"> inventoryConstraint(loc) = </FONT>
<BR> <FONT SIZE=2 FACE="Century Gothic">sum(flows(srcloc, loc), inventoryMove(srcloc, loc)) - </FONT>
<BR> <FONT SIZE=2 FACE="Century Gothic">sum(flows(loc, destloc), inventoryMove(loc, destloc)) + initialInventory(loc) >= zero;</FONT>
</P>
<P><FONT SIZE=2 FACE="Century Gothic"> MP_expression exp =</FONT>
<BR> <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"> - </FONT>
<BR><FONT SIZE=2 FACE="Century Gothic"> sum(flows(srcloc, destloc), flowCost(srcloc, destloc) * inventoryMove(srcloc, destloc));</FONT>
</P>
<P><FONT SIZE=2 FACE="Century Gothic"> maximize(exp);</FONT>
</P>
<P><FONT SIZE=2 FACE="Century Gothic"> inventoryMove.display("Movement");</FONT>
</P>
</BODY>
</HTML>