Lindo Systems
MODEL:
! A Simple Transportation Model TranSprsExtTxt.lng;
! The ARCS or links set may be sparse;
! Illustrate input from text file. See associate input file TranIn.txt;
! The TITLE command is optional, but can used to better label output;
TITLE Transportation;
! Keywords: @DIVERT, @READRM, CALC section, LINGO, Sourcing, Sparse set,
Submodel, Supply chain, Text file input, Text file output, Transportation;
SETS:
PLANTS: CAPACITY;
CUSTOMERS: DEMAND;
ARCS( PLANTS, CUSTOMERS): COST, VOLUME;
ENDSETS
SUBMODEL TranProb:
! Define a submodel that can be selectively solved;
! The objective;
MIN = @SUM( ARCS: COST * VOLUME);
! The demand constraints;
@FOR( CUSTOMERS( C):
@SUM( ARCS( P, C): VOLUME( P, C)) >= DEMAND( C));
! The supply constraints;
@FOR( PLANTS( P):
@SUM( ARCS( P, C): VOLUME( P, C)) <= CAPACITY( P));
ENDSUBMODEL
CALC:
! Set some solve parameters;
@SET( 'OROUTE',1);! Buffer size for routing output to window;
@SET( 'TERSEO',1);! Output level (0:verb, 1:terse, 2:only errors, 3:none);
@SET( 'IPTOLR', 0.0001);! Set IP ending relative optimality tolerance(Should be >0);
@SET( 'TIM2RL', 30); ! Time in seconds to apply IPTOLR tolerance;
@SET( 'TATSLV', 300);! Solver time limit in seconds (0:no limit) for @SOLVE's;
! Get input from a text file. Second argument is the end-of-table marker;
! Read Records with specified Marker for end of table;
PLANTS, CAPACITY = @READRM('\Temp\TranIn.txt', '~');
CUSTOMERS, DEMAND = @READRM(, '~'); ! If no file name, use previous;
ARCS, COST = @READRM();
@SOLVE( TranProb);! Solve specified model;
! Send results to a text file;
@DIVERT( '\Temp\TranArcOut.txt');
! Loop over arcs with VOLUME > 0 to write simple little report;
@FOR( ARCS( P, C) | VOLUME( P, C) #GT# 0:
@WRITE( ' ', PLANTS( P),' ', CUSTOMERS( C),' ', @FORMAT( VOLUME( P, C),'12.2f'), @NEWLINE( 1));
);
! Bring output back to screen;
@DIVERT( );
ENDCALC
END