Lindo Systems

! Generic set-based LINGO Transportation model, (ParkingSparse.lng)
  applied to a parking spot to apartment assignment problem;
! This model is meant to be used with ParkingSparsex.xlsx;
! Keywords: Transportation model, Parking, Sparse representation;
SETS:
 SPOT: CAP; ! Each group of spots has a capacity;
 APT: DEM;  ! Each apartment group has a demand;
 SXA( SPOT, APT): COST, ASSIGN; ! Each combination has a cost. 
   We want to determine the number to assign to each combination,
   so as to minimize the cost (i.e., distance traveled);
ENDSETS
DATA:
 ! This is the sparse case, we supply an explicit list, SXA, of which
   combinations are possible;
 SPOT = @ole(); ! Get list of parking spots from currently open spreadsheet;
 CAP =  @ole(); ! Get capacity. Will use open spreadsheet if no name;
 APT  = @ole(); ! Get list of apartments needing parking spots;
 DEM  = @ole(); ! Get demand of each apartment block;
 SXA  = @ole(); ! Get possible combinations of Spots to Apartments;
 COST = @ole(); ! and the Cost of each combination;
ENDDATA
!---------------------------------------------------------;
! Minimize total distance traveled;
 [obj] MIN = @SUM(SXA(i,j): COST(i,j) * ASSIGN(i,j));

! Capacity constraints for each group of spots;
 @FOR( SPOT( i):
      @SUM( SXA(i,J): ASSIGN( I, J)) <= CAP( I);
     );

! Demand constraints for each group of apartments;
 @FOR( APT( J):
      @SUM( SXA( I,j): ASSIGN( I, J)) = DEM( J);
     ); 

 DATA:
! Send the results back to the spread sheet 
  to the range name matching variable name;
   @ole() = ASSIGN;
   @ole()= obj;
 ENDDATA