main content

create multiperiod inventory model in problem-凯发k8网页登录

this example shows how to create a multiperiod inventory model in the problem-based framework. the problem is to schedule production of fertilizer blends over a period of time using a variety of ingredients whose costs depend on time in a predictable way. assume that you know in advance the demand for the fertilizers. the objective is to maximize profits while meeting demand, where the costs are for purchasing raw ingredients and for storing fertilizer over time. you can determine costs in advance by using futures or other contracts.

fertilizers and ingredients

granular fertilizers have nutrients nitrogen (n), phosphorous (p), and potassium (k). you can blend the following raw materials to obtain fertilizer blends with the requisite nutrients.

load fertilizer
blends = blenddemand.properties.variablenames % fertilizers to produce
blends = 1x2 cell
    {'balanced'}    {'highn'}
nutrients = rawnutrients.properties.rownames
nutrients = 3x1 cell
    {'n'}
    {'p'}
    {'k'}
raws = rawnutrients.properties.variablenames % raw materials
raws = 1x6 cell
    {'map'}    {'potash'}    {'an'}    {'as'}    {'tsp'}    {'sand'}

the two fertilizer blends have the same nutrient requirements (10% n, 10% p, and 10% k by weight), except the "highn" blend has an additional 10% n for a total of 20% n.

disp(blendnutrients) % table is in percentage
         balanced    highn
         ________    _____
    n       10        20  
    p       10        10  
    k       10        10  

the raw materials have the following names and nutrient percentages by weight.

disp(rawnutrients) % table is in percentage
         map    potash    an    as    tsp    sand
         ___    ______    __    __    ___    ____
    n    11        0      35    21     0      0  
    p    48        0       0     0    46      0  
    k     0       60       0     0     0      0  

the raw material sand has no nutrient content. sand dilutes other ingredients, if necessary, to obtain the requisite percentages of nutrients by weight.

store the numbers of each of these quantities in variables.

nblends = length(blends);
nraws = length(raws);
nnutrients = length(nutrients);

forecast demand and revenue

assume that you know in advance the demand in weight (tons) for the two fertilizer blends for the time periods in the problem.

disp(blenddemand)
                 balanced    highn
                 ________    _____
    january        750        300 
    february       800        310 
    march          900        600 
    april          850        400 
    may            700        350 
    june           700        300 
    july           700        200 
    august         600        200 
    september      600        200 
    october        550        200 
    november       550        200 
    december       550        200 

you know the prices per ton at which you sell the fertilizer blends. these prices per ton do not depend on time.

disp(blendprice)
    balanced    highn
    ________    _____
      400        550 

prices of raw materials

assume that you know in advance the prices in tons for the raw materials. these prices per ton depend on time according to the following table.

disp(rawcost)
                 map    potash    an     as     tsp    sand
                 ___    ______    ___    ___    ___    ____
    january      350     610      300    135    250     80 
    february     360     630      300    140    275     80 
    march        350     630      300    135    275     80 
    april        350     610      300    125    250     80 
    may          320     600      300    125    250     80 
    june         320     600      300    125    250     80 
    july         320     600      300    125    250     80 
    august       320     600      300    125    240     80 
    september    320     600      300    125    240     80 
    october      310     600      300    125    240     80 
    november     310     600      300    125    240     80 
    december     340     600      300    125    240     80 

storage cost

the cost for storing blended fertilizer applies per ton and per time period.

disp(inventorycost)
    10

capacity constraints

you can store no more than inventorycapacity tons of total fertilizer blends at any time period.

disp(inventorycapacity)
        1000

you can produce a total of no more than productioncapacity tons in any time period.

disp(productioncapacity)
        1200

connection among production, sales, and inventory

you start the schedule with a certain amount, or inventory, of fertilizer blends available. you have a certain target for this inventory at the final period. at each time period, the amount of fertilizer blend is the amount at the end of the previous time period, plus the amount produced, minus the amount sold. in other words, for times greater than 1:

inventory(time,product) = inventory(time-1,product) production(time,product) - sales(time,product)

this equation implies that the inventory is counted at the end of the time period. the time periods in the problem are as follows.

months = blenddemand.properties.rownames;
nmonths = length(months);

the initial inventory affects the inventory at time 1 as follows.

inventory(1,product) = initialinventory(product) production(1,product) - sales(1,product)

the initial inventory is in the data blendinventory{'initial',:}. the final inventory is in the data blendinventory{'final',:}.

assume that unmet demand is lost. in other words, if you cannot fill all the orders in a time period, the excess orders do not carry over into the next time period.

optimization problem formulation

the objective function for this problem is profit, which you want to maximize. therefore, create a maximization problem in the problem-based framework.

inventoryproblem = optimproblem('objectivesense','maximize');

the variables for the problem are the quantities of fertilizer blends that you make and sell each month, and the raw ingredients that you use to make those blends. the upper bound on sell is the demand, blenddemand, for each time period and each fertilizer blend.

make = optimvar('make',months,blends,'lowerbound',0);
sell = optimvar('sell',months,blends,'lowerbound',0,'upperbound',blenddemand{months,blends});
use  = optimvar('use',months,raws,blends,'lowerbound',0);

additionally, create a variable that represents the inventory at each time.

inventory = optimvar('inventory',months,blends,'lowerbound',0,'upperbound',inventorycapacity);

to calculate the objective function in terms of the problem variables, calculate the revenue and costs. the revenue is the amount you sell of each fertilizer blend times the price, added over all time periods and blends.

revenue = sum(blendprice{1,:}.*sum(sell(months,blends),1));

the cost of ingredients is the cost for each ingredient used at each time, added over all time periods. because the amount used at each time is separated into the amount used for each blend, also add over the blends.

blendsused = sum(use(months,raws,blends),3);
ingredientcost = sum(sum(rawcost{months,raws}.*blendsused));

the storage cost is the cost for storing the inventory over each time period, added over time and blends.

storagecost = inventorycost*sum(inventory(:));

now place the objective function into the objective property of the problem by using dot notation.

inventoryproblem.objective = revenue - ingredientcost - storagecost;

problem constraints

the problem has several constraints. first, express the inventory equation as a set of constraints on the problem variables.

materialbalance = optimconstr(months,blends);
timeabove1 = months(2:end);
previoustime = months(1:end-1);
materialbalance(timeabove1,:) = inventory(timeabove1,:) == inventory(previoustime,:)  ...
    make(timeabove1,:) - sell(timeabove1,:);
materialbalance(1,:) = inventory(1,:) == blendinventory{'initial',:}  ...
    make(1,:) - sell(1,:);

express the constraint that the final inventory is fixed as well.

finalc = inventory(end,:) == blendinventory{'final',:};

the total inventory at each time is bounded.

boundedinv = sum(inventory,2) <= inventorycapacity;

you can produce a limited amount in each time period.

processlimit = sum(make,2) <= productioncapacity;

the amount that you produce each month of each blend is the amount of raw materials that you use. the squeeze function converts the sum from a nmonths-by-1-by- nblends array to a nmonths-by- nblends array.

rawmaterialuse = squeeze(sum(use(months,raws,blends),2)) == make(months,blends);

the nutrients in each blend must have the requisite values. in the following inner statement, the multiplication rawnutrients{n,raws}*use(m,raws,b)' adds the nutrient values at each time over the raw materials used.

blendnutrientsquality = optimconstr(months,nutrients,blends);
for m = 1:nmonths
    for b = 1:nblends
        for n = 1:nnutrients
            blendnutrientsquality(m,n,b) = rawnutrients{n,raws}*use(m,raws,b)' == blendnutrients{n,b}*make(m,b);
        end
    end
end

place the constraints into the problem.

inventoryproblem.constraints.materialbalance = materialbalance;
inventoryproblem.constraints.finalc = finalc;
inventoryproblem.constraints.boundedinv = boundedinv;
inventoryproblem.constraints.processlimit = processlimit;
inventoryproblem.constraints.rawmaterialuse = rawmaterialuse;
inventoryproblem.constraints.blendnutrientsquality = blendnutrientsquality;

solve problem

the problem formulation is complete. solve the problem.

[sol,fval,exitflag,output] = solve(inventoryproblem)
solving problem using linprog.
optimal solution found.
sol = struct with fields:
    inventory: [12x2 double]
         make: [12x2 double]
         sell: [12x2 double]
          use: [12x6x2 double]
fval = 2.2474e 06
exitflag = 
    optimalsolution
output = struct with fields:
         iterations: 135
    constrviolation: 9.0949e-13
            message: 'optimal solution found.'
          algorithm: 'dual-simplex'
      firstorderopt: 2.2737e-13
             solver: 'linprog'

display the results in tabular and graphical form.

if exitflag > 0
    fprintf('profit: %g\n',fval);
    maket = array2table(sol.make,'rownames',months,'variablenames',strcat('make',blends));
    sellt = array2table(sol.sell,'rownames',months,'variablenames',strcat('sell',blends));
    storet = array2table(sol.inventory,'rownames',months,'variablenames',strcat('store',blends));
    productionplant = [maket sellt storet]
    figure
    subplot(3,1,1)
    bar(sol.make)
    legend('balanced','highn','location','eastoutside')
    title('amount made')
    subplot(3,1,2)
    bar(sol.sell)
    legend('balanced','highn','location','eastoutside')
    title('amount sold')
    subplot(3,1,3)
    bar(sol.inventory)
    legend('balanced','highn','location','eastoutside')
    title('amount stored')
    xlabel('time')
end
profit: 2.24739e 06
productionplant=12×6 table
                 makebalanced    makehighn    sellbalanced    sellhighn    storebalanced    storehighn
                 ____________    _________    ____________    _________    _____________    __________
    january          1100           100           750            300            550              0    
    february          600           310           800            310            350              0    
    march             550           650           900            600              0             50    
    april             850           350           850            400              0              0    
    may               700           350           700            350              0              0    
    june              700           300           700            300              0              0    
    july              700           200           700            200              0              0    
    august            600           200           600            200              0              0    
    september         600           200           600            200              0              0    
    october           550           200           550            200              0              0    
    november          550           200           550            200              0              0    
    december          750           400           550            200            200            200    

figure contains 3 axes objects. axes object 1 with title amount made contains 2 objects of type bar. these objects represent balanced, highn. axes object 2 with title amount sold contains 2 objects of type bar. these objects represent balanced, highn. axes object 3 with title amount stored, xlabel time contains 2 objects of type bar. these objects represent balanced, highn.

related topics

    网站地图