[R] rpanel / list error

2012-03-08 Thread jism7690
Hi All,

I have created a simulation that works perfect and I have the results been
returned in a list as I have multiple values. I then decided to include some
user interaction by using the package rpanel, I now get the error:

object of type 'builtin' is not subsettable

when I attempted to have the return my list with the results . 

Any help needed. I can also upload code if needs be. 

--
View this message in context: 
http://r.789695.n4.nabble.com/rpanel-list-error-tp4457308p4457308.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] rpanel / list error

2012-03-09 Thread jism7690
Hi Michael,

Thank you for your reply. I have uploaded the minimum, I have left out the
formulas for calculating the amounts as they are not important to the loop.
Basically I have a while loop running that adds to the list of values and
then outside this loop I have a list called sis, this is the list that is
causing the error. I would like this list to return the values with panel,
before I used rpanel it was returning values perfectly.

Thanks

main <- function(panel)
{
with(panel,{

LAST = 1100
START = 0
index = 0    Starting Conditions
revenue = 0
minStock = panel$minStock
maxStock = 100
inventory = 100
order_costs = 0
storage_costs = 0
orderlevel =panel$k
sum = list(ninventory=inventory,order_costs=0,storage_costs=0,revenue = 
0)
# initial list containing values

while(index < LAST && inventory >0) {

sum$order_costs = sum$order_costs + order_costs
sum$storage_costs = sum$storage_costs + storage_costs
sum$ninventory = sum$ninvenotry + inventory


  index = index + 1

}
})
sis = list(Time = index,StorageCosts=sum$storage_costs,OrderCosts=
sum$order_cost,fInventory = sum$ninventory)
return(sis)
 }


panel <- rp.control(title="Stochastic Case", size=panel.size)
rp.button(panel,action=main,title="Calculate",pos=pos.go.button)
rp.slider(panel,k,from=10,to=90,resolution=10,showvalue=TRUE,title="Select
Order Size",pos=pos.order.slider,initval=70)
rp.slider(panel,minStock,from=10,to=90,resolution=10,pos=pos.minstock.slider,initval
= 50,title="Minimum Stock Level",showvalue=TRUE)



--
View this message in context: 
http://r.789695.n4.nabble.com/rpanel-list-error-tp4457308p4459254.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Discrete Event Simulation problem

2012-02-10 Thread jism7690
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.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Discrete Event Simulation problem

2012-02-13 Thread jism7690
I have made some chances and I believe now the only problem  is making the
system reorder. Please any help would be great


test <- function(seed = 123456789, maxStock= 100, minStock =
20,t.max=1100,inventory =50)
{

LAST = t.max
START = 0
t.demand = START
t.supply = START
t.current = START

GetDemand<-function()
{
t.demand <<- t.demand + runif(1,min=0,max=5)
return(t.demand)
}
GetSupply <-function(){
if (inventory < minStock)
{
t.supply <<- t.supply + 1.0
}
else
t.supply <<- Inf
return(t.supply)
 }
 
main <- function(seed)
{
  if(seed > 0)
set.seed(seed)
index = 0
  t.current = START   Starting
Conditions
t.demand = START
t.supply = START
minStock = 20
maxStock = 100
inventory = 50
order_costs = 0
storage_costs = 0
sum = list(inventory = 50,order_costs = 0,storage_costs = 0)


while(index < LAST){
index = index + 1
t.demand = GetDemand()  ### expected time to next sale
t.supply = GetSupply()  ### 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
t.current = t.next -min(t.demand,t.max)
  if(inventory > 0) {
  storage_costs = (t.next-t.current)*0.10*inventory
  }

 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 =  GetSupply()
}
if(t.next ==t.demand)
  { 
inventory <<- inventory - 1 
Sale made
sum$inventory = sum$inventory - 1.0
t.demand = GetDemand()
}

if(t.next == t.supply)
  { 
Order Arrives
sum$inventory = sum$inventory + k
k = 0
t.supply = GetSupply()
}

  if(inventory < maxStock)
  {
  k = maxStock - inventory
  sum$storage_costs = sum$storage_costs + storage_costs
  sum$order_costs = sum$order_costs + order_costs
  }

}
  options(digits = 5)
sis = list(Time = index,StorageCosts =sum$storage_costs,OrderCosts=
sum$order_costs,AverageCosts =((sum$order_costs +
sum$storage_costs)/index),Inventory = sum$inventory)
return(sis)
}
return(main(seed))
}


--
View this message in context: 
http://r.789695.n4.nabble.com/Discrete-Event-Simulation-problem-tp4377276p4383464.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.