0% found this document useful (0 votes)
1 views2 pages

Lingo Model

The document outlines a purchasing plan problem implemented using LINGO, focusing on minimizing costs associated with purchasing quantities over a specified number of months. It includes an integer programming model to manage demand satisfaction and order placement, as well as a shortest path model to calculate costs and flow. The final section reports the optimal purchasing plan and total costs based on the chosen model.

Uploaded by

houtarou28042000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views2 pages

Lingo Model

The document outlines a purchasing plan problem implemented using LINGO, focusing on minimizing costs associated with purchasing quantities over a specified number of months. It includes an integer programming model to manage demand satisfaction and order placement, as well as a shortest path model to calculate costs and flow. The final section reports the optimal purchasing plan and total costs based on the chosen model.

Uploaded by

houtarou28042000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

MODEL:

! Purchasing Plan Problem - LINGO Implementation;

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);

! Example data - replace with actual values;


DEMAND = 100 120 80 140 110 90; ! Monthly demands;
PRICE = 10 12 9 11 13 8; ! Unit purchase prices;
s = 500; ! Setup cost;
h = 2; ! Holding cost per unit per month;
END

! IP Model;
SUBMODEL IP_MODEL:
SETS:
MONTH: Y; ! Y(i) = 1 if purchase is made in month i, 0 otherwise;
END

! Objective function: minimize total cost;


MIN = @SUM(MONTH(i): s * Y(i)) +
@SUM(PAIR(i,j): PRICE(i) * X(i,j)) +
@SUM(PAIR(i,j) | i #LT# j: h * (j - i) * X(i,j));

! Demand satisfaction constraints;


@FOR(MONTH(j):
@SUM(PAIR(i,j): X(i,j)) = DEMAND(j)
);

! Order placement constraints;


@FOR(MONTH(i):
@SUM(PAIR(i,j): X(i,j)) <= (@SUM(MONTH(k) | k #GE# i: DEMAND(k))) * Y(i)
);

! Binary constraints;
@FOR(MONTH(i): @BIN(Y(i)));

! Non-negativity constraints;
@FOR(PAIR(i,j): X(i,j) >= 0);
ENDSUBMODEL

! Shortest Path Model;


SUBMODEL SHORTEST_PATH:
SETS:
NODE /0..n/: ; ! Nodes representing end of months (0 = start);
ARC_SP(NODE, NODE) | &1 #LT# &2: FLOW, ARC_COST; ! Arcs for the network;
END

! Calculate arc costs;


@FOR(ARC_SP(i,j) | i #GT# 0:
ARC_COST(i,j) = s + PRICE(i) *
@SUM(MONTH(t) | t #GE# i #AND# t #LE# j: DEMAND(t)) +
h * @SUM(MONTH(t) | t #GT# i #AND# t #LE# j: (t - i) * DEMAND(t))
);

@FOR(ARC_SP(0,j):
ARC_COST(0,j) = s + PRICE(j) * DEMAND(j)
);

! Objective: minimize total cost;


MIN = @SUM(ARC_SP(i,j): ARC_COST(i,j) * FLOW(i,j));

! Flow conservation constraints;


! Node 0 (start) has net outflow of 1;
@SUM(ARC_SP(0,j): FLOW(0,j)) = 1;

! Node n (end) has net inflow of 1;


@SUM(ARC_SP(i,n): FLOW(i,n)) = 1;

! All other nodes have balanced flow;


@FOR(NODE(k) | k #GT# 0 #AND# k #LT# n:
@SUM(ARC_SP(i,k): FLOW(i,k)) = @SUM(ARC_SP(k,j): FLOW(k,j))
);

! Binary flow variables;


@FOR(ARC_SP(i,j): @BIN(FLOW(i,j)));
ENDSUBMODEL

! Select which model to solve;


!@SOLVE(IP_MODEL);
@SOLVE(SHORTEST_PATH);

! Reporting section;
CALC:
@WRITE('Optimal Purchasing Plan:', @NEWLINE(1));
@WRITE('Month | Purchase Quantity | Total Cost', @NEWLINE(1));
@WRITE('------------------------------------------', @NEWLINE(1));

@IF(@POINTERS(IP_MODEL) #GT# 0) THEN


@FOR(MONTH(i) | Y(i) #GT# 0.5:
@FORMAT('Month %2d: %10.2f units, Cost = $%10.2f', i,
@SUM(PAIR(i,j): X(i,j)),
s + @SUM(PAIR(i,j): PRICE(i) * X(i,j)));
@WRITE(@FORMAT, @NEWLINE(1));
);
@ELSE
@FOR(ARC_SP(i,j) | FLOW(i,j) #GT# 0.5 #AND# i #GT# 0:
@FORMAT('Month %2d: Purchase for months %d to %d, Cost = $%10.2f',
i, i, j, ARC_COST(i,j));
@WRITE(@FORMAT, @NEWLINE(1));
);
@ENDIF

@WRITE('------------------------------------------', @NEWLINE(1));
@WRITE('Total cost: $', @GET(OBJECTIVE));
ENDCALC

END

You might also like