euba / BacArena

agent based modelling
GNU General Public License v3.0
26 stars 11 forks source link

plotShadowCost error #123

Closed thh32 closed 6 years ago

thh32 commented 6 years ago

The following code;

library(BacArena)
data("Ec_core")
bac <- Bac(Ec_core, limit_growth=FALSE) # here is a change
arena <- Arena(n=20, m=20)
arena <- addOrg(arena,bac,amount=20)
arena <- addSubs(arena, smax=0.5, mediac="EX_glc(e)", unit="mM")
arena <- addSubs(arena, smax=1, mediac=c("EX_pi(e)", "EX_h2o(e)", "EX_o2(e)", "EX_nh4(e)"), unit="mM")
eval <- simEnv(arena,time=12)
p <- plotShadowCost(eval, 6)
p[[2]]

Produces the following error;

> p <- plotShadowCost(eval, 6)
Error in object@shadowlist[[1]][[spec_nr]] : subscript out of bounds

Is this the correct way to call shadowcost or has it been updated as the current introduction produces '##NULL' as output for E.coli instead of original cobalt but it does state something instead of an error.

Thanks for the help.

jotech commented 6 years ago

sorry took me some time to figure it out! By default, the shadow costs are not stored anymore because there were problems with different solvers. In case you want to use it, you can enable it by with_shadow=TRUE when calling sinEnv() Following your example this would be:

library(BacArena)
data("Ec_core")
bac <- Bac(Ec_core, limit_growth=FALSE) 
arena <- Arena(n=20, m=20)
arena <- addOrg(arena,bac,amount=20)
arena <- addSubs(arena, smax=0.5, mediac="EX_glc(e)", unit="mM")
arena <- addSubs(arena, smax=1, mediac=c("EX_pi(e)", "EX_h2o(e)", "EX_o2(e)", "EX_nh4(e)"), unit="mM")
eval <- simEnv(arena,time=12, , with_shadow = T) # here is a change

plotShadowCost(eval, spec_nr = 1)

image

thh32 commented 6 years ago

Thanks for finding a solution for this