Initializing help system before first use

Transportation problem with piecewise linear cost expressions


Type: MIP with general constraints
Rating: 2 (easy-medium)
Description: Formulating piecewise linear cost functions via pwlin constraints.
File(s): transpl2.mos
Data file(s): transpl2.dat


transpl2.mos
(!******************************************************
   Mosel Example Problems
   ======================

   file transpl2.mos
   `````````````````
   Transportation problem with piecewise linear cost
   functions represented via 'pwlin' constraints.

   -- Based on an example presented in Chapter 20 of the book
      R.Fourer, D.M. Gay, B.W. Kerninghan: AMPL: A modeling  
      language for mathematical programming --

   (c) 2020 Fair Isaac Corporation
       author: Y.Colombani, Jun. 2020
*******************************************************!)
model Transpl2
 uses 'mmxnlp','mmxprs'
 options keepassert

 declarations
   ORIG: set of string               ! Set of origins
   DEST: set of string               ! Set of destinations
   SUPPLY: array(ORIG) of real       ! Amounts available at origins
   DEMAND: array(DEST) of real       ! Amounts required at destinations
   RATE: array(ORIG,DEST) of list of real  ! List of unit cost rates
   LIMIT: array(ORIG,DEST) of list of real ! Price change points for rates

   trans: array(ORIG,DEST) of mpvar  ! Transported quantities
 end-declarations

 initialisations from 'Data/transpl2.dat'
   SUPPLY
   DEMAND
   RATE
   LIMIT
 end-initialisations

 ! Validation of input data
 assert(sum(i in ORIG) SUPPLY(i) = sum (j in DEST) DEMAND(j))

 ! Objective function: minimize total cost, formulated via piecewise linear
 ! expressions using slopes (=cost rates)
 Total_Cost:=
   sum(i in ORIG, j in DEST) 
      pwlin(trans(i,j),LIMIT(i,j),RATE(i,j))

 ! Use all supplies
 forall(i in ORIG)
   Supply(i):= sum(j in DEST) trans(i,j) = SUPPLY(i)

 ! Satisfy all demands
 forall(j in DEST)
   Demand(j):= sum(i in ORIG) trans(i,j) = DEMAND(j)

 ! Solve the problem and report on solution
 minimise(Total_Cost)
 writeln("Total cost: ", Total_Cost.sol)
 forall(i in ORIG,j in DEST | trans(i,j).sol>0)
   writeln(i, "->", j, ":", trans(i,j).sol,
           " cost:", getsol(pwlin(trans(i,j),LIMIT(i,j),RATE(i,j))))
end-model


© 2001-2024 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.