[R] Discrete Event Simulation problem
jism7690
james.jism.carey at gmail.com
Fri Feb 10 20:17:38 CET 2012
Hi All,
I am attempting to simulation an inventory model on R and I am having some
problems. I believe the problem is when I define my demand rate is stays
constant throughout so when I do need to reorder the model does not
recognise it as I have the initial supply arrival time set to infinity at
the start as no order has been played but I have an if statement saying, if
the level falls below a certain point then an order should be placed, I have
the expected time to order arrival set to be before the the sale but this is
not working.
Any Help would be appreciated. Thanks
maxStock = 100
minStock = 20
t.max=1100.0
LAST = t.max
START = 0
GetDemand<-function() START + runif(1,min=0,max=2)
main <- function(t.max,maxStock,minStock)
{
index = 0
t.current = START #### Starting Conditions
t.demand = START
t.supply = START
inventory = 50
order_costs = 0
storage_costs = 0
sales = 0
sum = list(inventory = 50,order_costs = 0,storage_costs = 0,sales =0)
while(index < LAST){
index = index + 1
t.demand = GetDemand() ### expected time to next sale
t.supply = Inf ### expected time to arrival of order, Infinity as order
has not been placed
t.next =min(t.demand,t.supply) ###next event either sale or supply is
the one with imminent arrival
k = maxStock - inventory
if(inventory > minStock)
{
t.supply = Inf ### expected time to arrival of order, Infinity as
order has not been placed
}
if(inventory > 0)
storage_costs = (t.next-t.current)*0.10*inventory
t.current = t.next
if (inventory < minStock)
{ ###Need to Order
k = maxStock - inventory
order_costs = 50 + 0.02*k
sum$order_costs = sum$order_costs + order_costs
t.supply = t.current + 1.0
}
if(t.current ==t.demand)
{
sum$inventory = sum$inventory - 1.0
####Sale made
sum$sales = sum$sales + 1.0
t.demand = runif(1,min=0,max=2)
}
if(t.current == t.supply)
{ ####Order Arrives
sum$inventory = sum$inventory + k
k = 0
t.supply = Inf
}
if(inventory < maxStock)
{
k = maxStock - inventory
sum$storage_costs = sum$storage_costs + storage_costs
sum$order_costs = sum$order_costs + order_costs
sum$inventory = sum$invneotry + k - sum$sales
sum$sales = sum$sales + sales
sum$sales = sum$sales + sales
}
}
sis = list(Time = index,StorageCosts =sum$storage_costs,OrderCosts=
sum$order_costs, FinalInventoryLevel=sum$inventory,sales=sum$sales ,
AverageCosts =((sum$order_costs + sum$storage_costs)/index))
return(sis)
}
main()
--
View this message in context: http://r.789695.n4.nabble.com/Discrete-Event-Simulation-problem-tp4377276p4377276.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list