Re: [Fwd: Ceil in minimize function -- invalid type error (mod file in attachment)]

Andrew Makhorin <[email protected]>
Newsgroups gmane.comp.gnu.glpk
Message-ID <1484730529.6359.1.camel@corvax>
> I'm using stand-alone solver, version 4.54. Running by 
> glpsol -m supp.mod
> In attachment the whole file with model and data.
> 
> 
> I'm trying to solve problem to pick suppliers for articles with minimum
> global order value. 
> Each article can be bought from different suppliers with different
> price. When supplier don't have some article - the price is set to -1,
> but there is constraint s.t. CorrectSupplier, which blocked order that
> article from that supplier.
> Each supplier have some maximum value (we can't order from him more than
> the value).
> Till here I have done it, and it works OK by the goal function:
> 
> minimize goal: sum{a in Art,s in Supp} OrdQty[a,s] * Prices[a,s];
> 
> 
> 
> 
> The problem I have when I'm trying to add a delivery cost.
> Delivery cost is defined by article package quantity (for example from
> supplier X delivery cost for article A is 3$ for each 10 peaces). When I
> define package quantity for each article (same for all suppliers), and
> when I define delivery cost for each article package for each supplier
> (different for each supplier), I have problem with calculating the goal
> function.
> 
> 
> When I define it like:
> 
> minimize goal: sum{a in Art,s in Supp} ((OrdQty[a,s] * Prices[a,s]) +
> (ceil(OrdQty[a,s]/ArtPackQty[a])*DeliveryCost[a,s]);
> 
> 
> 
> the solver gives me error:
> supp.mod:18: argument for ceil has invalid type
> Context: ...[ a , s ] ) + ( ceil ( OrdQty [ a , s ] / ArtPackQty [ a ] )
> MathProg model processing error
> 
> 
> I'm not sure, if I can use function (ceil) with my var (OrdQty), but I
> don't know, how to calculate it in another way.
> I'd be very greatful for any help.
> 

In constraints you cannot use variables as arguments to ceil function,
because this leads to non-linear constraints not allowed by glpk.

There are two ways to model fixed costs:

1. Use approximate delivery cost, i.e. use just y rather than ceil(y).
   If y is expected to be quite large in the optimal solution, the
   approximation error will be insignificant.

2. Introduce auxiliary *integer* variables. For example,

      z >= y;

   allows modeling z = ceil(y), where z >= 0 is an auxiliary integer
   variable (assuming that you minimize the overall delivery cost).
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.