[Flopcpp] Question on the iteration in flopc++

Tim Hultberg Tim.Hultberg at eumetsat.int
Mon Mar 27 01:43:14 EST 2006


Hi Qi,

You will have to write the constraint like this:

  inventoryConstraint(loc) = 
	sum(flows(srcloc, loc), inventoryMove(flows(srcloc, loc))) - 
	sum(flows(loc, destloc), inventoryMove(flows(loc, destloc))) +
initialInventory(loc) >= zero;

Since the variable
   MP_variable inventoryMove(flows); // movement along defined flows..

was declared over the subset flows, flopc++ needs this little extra
help.

Best regards, Tim



Tim Hultberg


>>> "Wang, Qi" <Qi.Wang at gs.com> 26/03/2006 23:13 >>>
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");



More information about the Flopcpp mailing list