Lingo Model
Lingo Model
SETS:
MONTH /1..n/: DEMAND, PRICE; ! Months, demand and price for each month;
PAIR(MONTH, MONTH) | &1 #LE# &2: X; ! Define purchase quantity variables X(i,j);
ARC(MONTH, MONTH) | &1 #LE# &2: COST; ! Arcs for the network model;
END
DATA:
n = 6; ! Number of months (example value);
! IP Model;
SUBMODEL IP_MODEL:
SETS:
MONTH: Y; ! Y(i) = 1 if purchase is made in month i, 0 otherwise;
END
! Binary constraints;
@FOR(MONTH(i): @BIN(Y(i)));
! Non-negativity constraints;
@FOR(PAIR(i,j): X(i,j) >= 0);
ENDSUBMODEL
@FOR(ARC_SP(0,j):
ARC_COST(0,j) = s + PRICE(j) * DEMAND(j)
);
! Reporting section;
CALC:
@WRITE('Optimal Purchasing Plan:', @NEWLINE(1));
@WRITE('Month | Purchase Quantity | Total Cost', @NEWLINE(1));
@WRITE('------------------------------------------', @NEWLINE(1));
@WRITE('------------------------------------------', @NEWLINE(1));
@WRITE('Total cost: $', @GET(OBJECTIVE));
ENDCALC
END