{"action":"created","issue":{"url":"https://api.github.com/repos/colinsheppard/time/issues/40","labels_url":"https://api.github.com/repos/colinsheppard/time/issues/40/labels{/name}","comments_url":"https://api.github.com/repos/colinsheppard/time/issues/40/comments","events_url":"https://api.github.com/repos/colinsheppard/time/issues/40/events","html_url":"https://github.com/colinsheppard/time/issues/40","id":57582684,"number":40,"title":"Problems with scheduling several events through a list with \"foreach\"","user":{"login":"annaklabunde","id":8664997,"avatar_url":"https://avatars.githubusercontent.com/u/8664997?v=3","gravatar_id":"","url":"https://api.github.com/users/annaklabunde","html_url":"https://github.com/annaklabunde","followers_url":"https://api.github.com/users/annaklabunde/followers","following_url":"https://api.github.com/users/annaklabunde/following{/other_user}","gists_url":"https://api.github.com/users/annaklabunde/gists{/gist_id}","starred_url":"https://api.github.com/users/annaklabunde/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/annaklabunde/subscriptions","organizations_url":"https://api.github.com/users/annaklabunde/orgs","repos_url":"https://api.github.com/users/annaklabunde/repos","events_url":"https://api.github.com/users/annaklabunde/events{/privacy}","received_events_url":"https://api.github.com/users/annaklabunde/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-02-13T10:28:51Z","updated_at":"2015-02-17T10:11:10Z","closed_at":null,"body":"Hi Colin,\r\nfirst of all, thank you for this great extension; it has been very helpful so far. However, for several days now I have been stuck with an issue that I can't resolve. \r\nWhat I want to do is to read from a .csv file, which I read into Netlogo as a time-series object (this part is working fine) a schedule of which agent does what at what time. The time series-object in Netlogo looks like this: \r\n\r\nobserver: {{time:LogoTimeSeries TIMESTAMP,ID,newstate\r\n2000-02-19 01:01:53.697,79.0,1.0\r\n2000-04-06 03:00:20.023,95.0,4.0\r\n2000-09-12 00:37:29.114,29.0,5.0\r\n2001-01-22 22:05:39.811,52.0,4.0...\r\n\r\nThe first column is the time t at which an event happens, ID is an agent variable (not equal to the who number) used to identify the agent, and newstate is also an agent variable which contains the type of new state that the agent should adopt at time T.\r\n\r\nWhen I just want to schedule an event for one agent, that works fine:\r\n\r\ntime:schedule-event one-of turtles with [id = time:ts-get transitions ( time:create \"2008-10-21 21:45:41.889\") \"ID\"]  task [set newtransition time:ts-get transitions ( time:create \"2008-10-21 21:45:41.889\" ) \"newstate\" perform-transition ] time:create \"2008-10-21 21:45:41.889\" \r\n\r\nI can also run the model with time:go; the event happens to the individual at the desired time.\r\n\r\nNow, however, I want to do this for all the agents, so that it is automatically read from the time series at what time which agent does what. I tried doing this with a list in all kinds of ways.\r\nFirst I tried this: \r\nset micsimlist []\r\nset micsimlist time:ts-get-range transitions time:create \"2000-01-01 00:00:00\" time:create \"2010-12-31 23:59:00\" \"ALL\" \r\n\r\nThis is the error I get:\r\nerror (IllegalArgumentException)\r\n while observer running SET\r\n  called by procedure SCHEDULE-EVENTS\r\n  called by procedure GO\r\n  called by Button 'go'\r\n\r\nNetLogo is unable to supply you with more details about this error.  Please report the problem\r\nat https://github.com/NetLogo/NetLogo/issues, or to bugs@ccl.northwestern.edu, and paste the\r\ncontents of this window into your report.\r\n\r\njava.lang.IllegalArgumentException: fromIndex(85) > toIndex(48)\r\n at java.util.SubList.<init>(AbstractList.java:604)\r\n at java.util.RandomAccessSubList.<init>(AbstractList.java:758)\r\n at java.util.AbstractList.subList(AbstractList.java:468)\r\n at TimeExtension$LogoTimeSeries.getRangeByTime(TimeExtension.java:366)\r\n at TimeExtension$TimeSeriesGetRange.report(TimeExtension.java:1645)\r\n at org.nlogo.prim._externreport.report(_externreport.java:50)\r\n at org.nlogo.prim._asm_procedurescheduleevents_setobservervariable_1.perform()\r\n at org.nlogo.nvm.Context.stepConcurrent(Context.java:91)\r\n at org.nlogo.nvm.ConcurrentJob.step(ConcurrentJob.java:82)\r\n at org.nlogo.job.JobThread.org$nlogo$job$JobThread$$runPrimaryJobs(JobThread.scala:143)\r\n at org.nlogo.job.JobThread$$anonfun$run$1.apply$mcV$sp(JobThread.scala:78)\r\n at org.nlogo.job.JobThread$$anonfun$run$1.apply(JobThread.scala:76)\r\n at org.nlogo.job.JobThread$$anonfun$run$1.apply(JobThread.scala:76)\r\n at scala.util.control.Exception$Catch.apply(Exception.scala:88)\r\n at org.nlogo.util.Exceptions$.handling(Exceptions.scala:41)\r\n at org.nlogo.job.JobThread.run(JobThread.scala:75)\r\n\r\nNetLogo 5.0.4\r\nmain: org.nlogo.app.AppFrame\r\nthread: JobThread\r\nJava HotSpot(TM) Server VM 1.6.0_41 (Sun Microsystems Inc.; 1.6.0_41-b02)\r\noperating system: Windows 7 6.1 (x86 processor)\r\nScala version 2.9.2\r\nJOGL: (3D View not initialized)\r\nOpenGL Graphics: (3D View not initialized)\r\nmodel: MicsimKombi5\r\n\r\n10:49:21.748 JobRemovedEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) JobThread\r\n10:49:21.748 SwitchedTabsEvent (org.nlogo.app.Tabs) AWT-EventQueue-0\r\n10:49:21.748 RuntimeErrorEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0\r\n10:49:21.670 AddJobEvent (org.nlogo.window.ButtonWidget) AWT-EventQueue-0\r\n10:49:21.577 InterfaceGlobalEvent (org.nlogo.app.InterfacePanel$2 (org.nlogo.window.SliderWidget)) AWT-EventQueue-0\r\n10:49:21.577 PeriodicUpdateEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0\r\n10:49:21.561 InputBoxLoseFocusEvent (org.nlogo.window.ButtonWidget) AWT-EventQueue-0\r\n10:49:21.372 InterfaceGlobalEvent (org.nlogo.app.InterfacePanel$2 (org.nlogo.window.SliderWidget)) AWT-EventQueue-0\r\n10:49:21.372 PeriodicUpdateEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0\r\n10:49:21.169 InterfaceGlobalEvent (org.nlogo.app.InterfacePanel$2 (org.nlogo.window.SliderWidget)) AWT-EventQueue-0\r\n\r\nNext, I tried \"LOGOTIME\" instead of \"ALL\", which works fine:\r\nset micsimlist []\r\nset micsimlist time:ts-get-range transitions time:create \"2000-01-01 00:00:00\" time:create \"2010-12-31 23:59:00\" \"LOGOTIME\" \r\nThis gives me the list\r\nobserver: [{{time:logotime 2000-02-19 01:01:53.697}} {{time:logotime 2000-04-06 03:00:20.023}} {{time:logotime 2000-09-12 00:37:29.114}}...\r\n\r\nI now tried to go over this list with foreach:\r\n\r\nforeach micsimlist [time:schedule-event one-of turtles with [id = time:ts-get transitions (time:create ? ) \"ID\" ]  task [set newtransition time:ts-get transitions ( time:create ? ) \"newstate\" perform-transition ]  time:create ?]\r\n\r\nThis is the error I get:\r\nExtension exception: Expected this input to be a string but got the TimeExtension$LogoTime {{time:logotime 2000-02-19 01:01:53.697}} instead.\r\nerror while turtle 59 running TIME:CREATE\r\n  called by (command task from: procedure SCHEDULE-EVENTS)\r\n  called by procedure SCHEDULE-EVENTS\r\n  called by procedure GO\r\n  called by Button 'go'\r\n\r\nNext, I tried leaving out the \"time:create\" before the \"?\".\r\nforeach micsimlist [time:schedule-event one-of turtles with [id = time:ts-get transitions ?  \"ID\" ]  task [set newtransition time:ts-get transitions ?  \"newstate\" perform-transition ]  ?]\r\n\r\nThe scheduling seems to work, at least I do not get an error. However, when I try to run the model with time:go, the error I get is:\r\n\r\nerror (ArrayIndexOutOfBoundsException)\r\n while observer running TIME:GO\r\n  called by procedure GO\r\n  called by Button 'go'\r\n\r\nNetLogo is unable to supply you with more details about this error.  Please report the problem\r\nat https://github.com/NetLogo/NetLogo/issues, or to bugs@ccl.northwestern.edu, and paste the\r\ncontents of this window into your report.\r\n\r\njava.lang.ArrayIndexOutOfBoundsException: 0\r\n at org.nlogo.nvm.Task$class.bindArgs(Task.scala:27)\r\n at org.nlogo.nvm.CommandTask.bindArgs(Task.scala:65)\r\n at org.nlogo.nvm.CommandTask.perform(Task.scala:74)\r\n at TimeExtension$LogoSchedule.performScheduledTasks(TimeExtension.java:588)\r\n at TimeExtension$LogoSchedule.performScheduledTasks(TimeExtension.java:548)\r\n at TimeExtension$Go.perform(TimeExtension.java:1544)\r\n at org.nlogo.prim._extern.perform(_extern.java:54)\r\n at org.nlogo.nvm.Context.stepConcurrent(Context.java:91)\r\n at org.nlogo.nvm.ConcurrentJob.step(ConcurrentJob.java:82)\r\n at org.nlogo.job.JobThread.org$nlogo$job$JobThread$$runPrimaryJobs(JobThread.scala:143)\r\n at org.nlogo.job.JobThread$$anonfun$run$1.apply$mcV$sp(JobThread.scala:78)\r\n at org.nlogo.job.JobThread$$anonfun$run$1.apply(JobThread.scala:76)\r\n at org.nlogo.job.JobThread$$anonfun$run$1.apply(JobThread.scala:76)\r\n at scala.util.control.Exception$Catch.apply(Exception.scala:88)\r\n at org.nlogo.util.Exceptions$.handling(Exceptions.scala:41)\r\n at org.nlogo.job.JobThread.run(JobThread.scala:75)\r\n\r\nNetLogo 5.0.4\r\nmain: org.nlogo.app.AppFrame\r\nthread: JobThread\r\nJava HotSpot(TM) Server VM 1.6.0_41 (Sun Microsystems Inc.; 1.6.0_41-b02)\r\noperating system: Windows 7 6.1 (x86 processor)\r\nScala version 2.9.2\r\nJOGL: (3D View not initialized)\r\nOpenGL Graphics: (3D View not initialized)\r\nmodel: MicsimKombi5\r\n\r\n11:21:14.656 SwitchedTabsEvent (org.nlogo.app.Tabs) AWT-EventQueue-0\r\n11:21:14.640 RuntimeErrorEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0\r\n11:21:14.640 AddJobEvent (org.nlogo.window.ButtonWidget) AWT-EventQueue-0\r\n11:21:14.515 InputBoxLoseFocusEvent (org.nlogo.window.ButtonWidget) AWT-EventQueue-0\r\n11:21:14.515 InterfaceGlobalEvent (org.nlogo.app.InterfacePanel$2 (org.nlogo.window.SliderWidget)) AWT-EventQueue-0\r\n11:21:14.515 PeriodicUpdateEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0\r\n11:21:14.313 InterfaceGlobalEvent (org.nlogo.app.InterfacePanel$2 (org.nlogo.window.SliderWidget)) AWT-EventQueue-0\r\n11:21:14.313 PeriodicUpdateEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0\r\n11:21:14.110 InterfaceGlobalEvent (org.nlogo.app.InterfacePanel$2 (org.nlogo.window.SliderWidget)) AWT-EventQueue-0\r\n11:21:14.110 PeriodicUpdateEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0\r\n\r\nI also tried \"time:create[0,?]\" and \"[0,?]\"; both did not work, either.  \r\n\r\nI really don't know what I'm doing wrong. I would be extremely grateful for any kind of help.\r\nI have Netlogo 5.0.4. and Windows 7.\r\n\r\nBest wishes \r\nAnna \r\n\r\n\r\n "},"comment":{"url":"https://api.github.com/repos/colinsheppard/time/issues/comments/74644616","html_url":"https://github.com/colinsheppard/time/issues/40#issuecomment-74644616","issue_url":"https://api.github.com/repos/colinsheppard/time/issues/40","id":74644616,"user":{"login":"annaklabunde","id":8664997,"avatar_url":"https://avatars.githubusercontent.com/u/8664997?v=3","gravatar_id":"","url":"https://api.github.com/users/annaklabunde","html_url":"https://github.com/annaklabunde","followers_url":"https://api.github.com/users/annaklabunde/followers","following_url":"https://api.github.com/users/annaklabunde/following{/other_user}","gists_url":"https://api.github.com/users/annaklabunde/gists{/gist_id}","starred_url":"https://api.github.com/users/annaklabunde/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/annaklabunde/subscriptions","organizations_url":"https://api.github.com/users/annaklabunde/orgs","repos_url":"https://api.github.com/users/annaklabunde/repos","events_url":"https://api.github.com/users/annaklabunde/events{/privacy}","received_events_url":"https://api.github.com/users/annaklabunde/received_events","type":"User","site_admin":false},"created_at":"2015-02-17T10:11:10Z","updated_at":"2015-02-17T10:11:10Z","body":"Hi Colin,\r\nthank you for answering so quickly! I tried your code and it does indeed work :) I think I also understand now what the problem was with my solution. Thank you so much!! You saved me lots of time and worry. \r\nBy having created this extension and doing such great trouble-shooting you help immensely in bridging the gap between agent-based modeling and discrete-event microsimulation, which I think is awesome.  \r\nCheers\r\nAnna"}}