[Flopcpp] Question on the iteration in flopc++
Wang, Qi
Qi.Wang at gs.com
Sun Mar 26 16:13:21 EST 2006
Hi, folks,
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..
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++,
Here is the flopc++ constraint,
inventoryConstraint(loc) =
sum(flows(srcloc, loc), inventoryMove(srcloc, loc)) -
sum(flows(loc, destloc), inventoryMove(loc, destloc)) +
initialInventory(loc) >= zero;
Here is the equivalent AMPL version of constraint
subject to inventoryConstraint { loc in locations } :
InitialInventory[loc]
+ sum { srcloc in locations: ((srcloc, loc) in Flows)}
inventoryMove[srcloc,loc]
- sum { destloc in locations: ((loc,destloc) in Flows)}
inventoryMove[loc,destloc]
>= 0;
The attached is the version of flopc++ sample..
Thanks,
Qi
//----------------------
enum { a, b, numOfLocations}; // assuming 2 locations for now
MP_set locations(numOfLocations);
MP_subset<2> flows(locations, locations); /* src to dest */
/* dynamic data set */
MP_data flowCost(flows);
MP_data locationBenefit(locations);
MP_data initialInventory(locations);
flows.insert(a,b);
flows.insert(b,a);
flowCost(flows(a,b)) = 200;
flowCost(flows(b,a)) = 200;
locationBenefit(a) = 0;
locationBenefit(b) = 2500;
initialInventory(a) = 5;
initialInventory(b) = 10;
MP_variable inventoryMove(flows); // movement along defined flows..
/**
** location inventory = initial inventory + what's coming in - what's
going out >= 0
**/
MP_constraint inventoryConstraint(locations);
MP_index loc, srcloc, destloc;
Constant zero(0);
inventoryConstraint(loc) =
sum(flows(srcloc, loc), inventoryMove(srcloc, loc)) -
sum(flows(loc, destloc), inventoryMove(loc, destloc)) +
initialInventory(loc) >= zero;
MP_expression exp =
sum(locations(loc), locationBenefit(loc) * (initialInventory(loc) +
sum(flows(srcloc, loc), inventoryMove(srcloc, loc)) - sum(flows(loc,
destloc), inventoryMove(loc,destloc))))
-
sum(flows(srcloc, destloc), flowCost(srcloc, destloc) *
inventoryMove(srcloc, destloc));
maximize(exp);
inventoryMove.display("Movement");
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://list.coin-or.org/pipermail/flopcpp/attachments/20060326/a4b78c5c/attachment.html
More information about the Flopcpp
mailing list