inventory

Capsim Block Documentation

Short Description

This star models an inventory system.

Top
Parameters
Num Description Type Name Default Value
0 Initial inventory level int initialInventoryLevel 60
1 number of months int numberMonths 120
2 set up cost float setupCost 32.0
3 incremental cost float incrementalCost 3.0
4 holding cost float holdingCost 1.0
5 shortage cost float shortageCost 5.0
6 minimum lag float minLag 0.5
7 maximum lag float maxLag 1.0
8 Order threshold (s) float smalls 20.0
9 Inventory Level (S) float bigs 60.0
10 Expression file expression any expresssion
11 Output Request:0=Inventory Level,1=Demand Size int outputRequest 0
Top
States
Num Type Name Initial Value Description
0 int ibufs
1 int obufs
2 long seed1
3 long seed2
4 int nextEventType
5 int numberEvents
6 int inventoryStatus
7 float areaHolding
8 float areaShortage
9 float time
10 float timeLastEvent
11 float timeNextEvent_A[5]
12 float totalOrderingCost
13 int inventoryLevel
14 int amount
15 int first 1
Top

Declarations


 

	int 	i,j;
	int 	samples;
	float 	sampleOut;
	float	x;
	float	arrivalInterval;
	float	minTimeNextEvent;
	float	timeSinceLastEvent;
	float	averageOrderingCost;
	float	averageHoldingCost;
	float	averageShortageCost;
	float 	delay;
	float	demandSize;
	complex sampIn;



Top

Initialization Code



 

	/* 
	 * store as state the number of input/output buffers 
	 */
	if((ibufs = NO_INPUT_BUFFERS()) < 1) {
		fprintf(stderr,"inventory: no input buffers\n");
		return(2);
	}
        for (i=0; i
    
Top

Main Code



 


/* 
 * read one sample from each input buffer 
 */
for(samples = MIN_AVAIL(); samples >0; --samples) {

	/*
 	 * get a customer and arrival interval
	 * from input buffer 
	 */
	for(i=0; i 0)
		areaHolding += inventoryLevel* timeSinceLastEvent;
	

	/*
 	 * End 
 	 *********************************************************/
	
	/*
	 * Invoke the appropriate event function
	 */

	switch (nextEventType) {
		case 1:
			/*
			 * Ordere Arrival
			 */
			/*
			 * Increment the inventory level by the amount ordered 
			 */
			inventoryLevel += amount;
			/*
			 * Since no order is now outstanding, eliminate the 
			 * order arrival from consideration
			 */
			timeNextEvent_A[1] = INFINITY;
			break;
		case 2:
			/*
			 * Demand
			 */

			/*
			 * Decrement the inventory level by the demand size 
			 */
			inventoryLevel -= demandSize;
			/*
			 * Schedule the time of the next demand
			 */
			timeNextEvent_A[2] = time +arrivalInterval;
			break;
		case 3:
			/*
			 * report
			 */
			return(0);
			break;
		case 4:
			/*
			 * Evaluate
			 */
			/*
			 * Check whether the inventory level is less than 
			 * smalls.
			 */
			if(inventoryLevel < smalls) {
				/*
				 * The inventory level is less than smalls
				 * So place an order for the appropriate 
				 * amount.
				 */
				amount = bigs -inventoryLevel;
				totalOrderingCost += setupCost + 
						incrementalCost*amount;
				/*
				 * Schedule the arrival of the order
				 */
				timeNextEvent_A[1] = time +
						genunf(minLag,maxLag);
			}
			/*
			 * Regardless of the place-order decision, schedule
			 * the next inventory evaluation
			 */
			timeNextEvent_A[4]= time +1.0;
			break;
	}
	switch(outputRequest) {
		case REQUEST_INVENTORY_LEVEL:
			sampleOut = inventoryLevel;
			break;
		case REQUEST_INVENTORY_ORDER:
			sampleOut = demandSize;
			break;
	}
	if(obufs==1 ) {
		if(IT_OUT(0)) {
			fprintf(stderr,"inventory: Buffer %d is full\n",0);;
			return(99);
		}
		OUTF(0,0) = sampleOut;
	}
	else if( obufs ==2) {
		if(IT_OUT(0)) {
			fprintf(stderr,"inventory: Buffer %d is full\n",0);;
			return(99);
		}
		OUTF(0,0) = time;
		if(IT_OUT(1)) {
			fprintf(stderr,"inventory: Buffer %d is full\n",1);;
			return(99);
		}
		OUTF(1,0) = sampleOut;


	}
}

return(0);	/* at least one input buffer empty */





Top

Wrapup Code



 

/*
 * Report results
 */
fprintf(stderr,"\n\nSingle product inventory system. \n");
fprintf(stderr,"Initial inventory level %d items \n", initialInventoryLevel);
fprintf(stderr,"Delivery lag ranges %f %f  \n", minLag,maxLag);
fprintf(stderr,"Length of the simulation %d months  \n", numberMonths);
fprintf(stderr,"Setup Cost: %f Incremental Cost: %f Holding Cost : %f Shortage Cost: %f\n", 
			setupCost,incrementalCost, holdingCost,shortageCost);
averageOrderingCost = totalOrderingCost/numberMonths;
averageHoldingCost = holdingCost*areaHolding/numberMonths;
averageShortageCost = shortageCost *areaShortage/numberMonths;
fprintf(stderr,"\n\n(S,s) (%f,%f)  \n", bigs,smalls);
fprintf(stderr,"Total Average Cost: %f\n", averageOrderingCost+averageHoldingCost+averageShortageCost);
fprintf(stderr,"Average Ordering Cost: %f\n", averageOrderingCost);
fprintf(stderr,"Average Holding Cost: %f\n", averageHoldingCost);
fprintf(stderr,"Average Shortage Cost: %f\n", averageShortageCost);




Top

License



/*  Capsim (r) Text Mode Kernel (TMK) Star Library (Blocks)
    Copyright (C) 1989-2017  Silicon DSP Corporation

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    http://www.silicondsp.com
    Silicon DSP  Corporation
    Las Vegas, Nevada
*/


Top

Description



 

/* inventory.s */
/**********************************************************************
			inventory()
***********************************************************************
This star models an inventory system. 
The input buffer is the customer inter arrival times and
product demand. 
The input are complex with the real part equal to the inter arrival time
and the imaginary part equal to the product demand.
The inventory does not need to output anything but we have chosen to output
the inventory level.  Thus by connecting the output of
the inventory star to the plot star, you can observe the inventory level
over time. 
Many other output combinations are possible but this star is used to serve
as an example.
The inventory star implements the C code in "Simulation Modeling and Analysis"
by Averill M. Law and W. David Kelton, Second Edition 1991.
We have included original comments.
The parameters are:
     (1) 	Initial inventory level
     (2) 	Number of months
     (3) 	Set up cost
     (4) 	Incremental  cost
     (5) 	Holding  cost
     (6) 	Shortage  cost
     (7) 	Minimum lag
     (8) 	Maximum lag
     (9) 	Order threshold (s)
     (10) 	Inventory Level  (S)
     (11) 	Expression for random number generator
     (12)	Output Request:0=Inventory Level,1=Demand Size
Notes:
   (1) The simulation will end when there are no more customers.
   However, the simulation can end using parameter 2 as a condition.
The input buffers are arbitrary so that in the future multiple customer 
sources may be modeled with a single inventory.
The number of input buffers is arbitrary and determined at run time.
The number of output buffers is also arbitrary (auto-fanout).

inventory


This star models an inventory system. 
The input buffer is the customer inter arrival times and
product demand. 
The input are complex with the real part equal to the inter arrival time
and the imaginary part equal to the product demand.
The inventory does not need to output anything but we have chosen to output
the inventory level.  Thus by connecting the output of
the inventory star to the plot star, you can observe the inventory level
over time. 
Many other output combinations are possible but this star is used to serve
as an example.
The inventory star implements the C code in "Simulation Modeling and Analysis"
by Averill M. Law and W. David Kelton, Second Edition 1991.
We have included original comments.
The parameters are:
     (1) 	Initial inventory level
     (2) 	Number of months
     (3) 	Set up cost
     (4) 	Incremental  cost
     (5) 	Holding  cost
     (6) 	Shortage  cost
     (7) 	Minimum lag
     (8) 	Maximum lag
     (9) 	Order threshold (s)
     (10) 	Inventory Level  (S)
     (11) 	Expression for random number generator
     (12)	Output Request:0=Inventory Level,1=Demand Size
Notes:
   (1) The simulation will end when there are no more customers.
   However, the simulation can end using parameter 2 as a condition.
The input buffers are arbitrary so that in the future multiple customer 
sources may be modeled with a single inventory.
The number of input buffers is arbitrary and determined at run time.
The number of output buffers is also arbitrary (auto-fanout).


Programmer: Sasan Ardalan 
Date:	November 6, 1993

*/