Manipulate GamaDate in milliseconds level

51 views
Skip to first unread message
Assigned to sto...@gmail.com by me

saad touhbi

unread,
Apr 20, 2017, 12:09:13 PM4/20/17
to GAMA

Is it possible to manipulate GamaDate to milliseconds level?

  • create a new date with milliseconds value
  • compare two dates considering milliseconds value.
  • get current simulation date with milliseconds.
I am trying to generating  agents depending on a schedule that would be up to milliseconds. however the current date of the simulation that i get does not give me access to milliseconds in order for me to do so.
Thanks

Alexis Drogoul (IRD)

unread,
Apr 20, 2017, 9:49:14 PM4/20/17
to GAMA
Hi,

Yes this is possible. But, before answering, let me put one thing straight: milliseconds can be (1) a measure of duration, not something used to define a date; (2) the number of milliseconds present in one date as a field (like the number of seconds, minutes, hours, etc. in that date). 

All models come with two default variables: starting_date and current_date. Yo can redefine the first one, for example if you want to start a simulation at a given date. Various operators allow you to handle their modification (adding durations, etc.), incl. arithmetic operators (i.e. you can write date2 <- date1 + 1 #month + 23 #ms).

Some pseudo-constants also exist, like #now (which gives the current « machine » date) or #epoch (which gives the default starting date of models when none is defined, and which can be changed in the preferences — by default it is the 1st of January 1970, like in Java). 

Now, to answer your questions: 

1)  • create a new date with milliseconds value : I dont really understand what this means. You cannot create a date from a duration, unless you have some sort of starting point (in which, your date would be x milliseconds after the starting point, maybe, if this is what you intend to obtain ?). For instance, date d1 <- starting_date plus_ms 100; could give you a date after 100ms of the starting date of the model; or date d2 <- #now plus_ms 1000; would give you a date ahead of 1s after the current machine date.

2)  • compare two dates considering milliseconds value: again, you have to make it clearer. Do you want to obtain the difference (i.e. duration) of two dates in milliseconds (in which case, milliseconds_between(d1,d2) is your friend) or do you want to compare the values of the milliseconds field of each date ? 

3)  • get current simulation date with milliseconds. Again, it does not mean anything by itself, unless you mean the duration in milliseconds from a given starting date (for instance, milliseconds_between(d1, starting_date) will give you the amount of milliseconds between your date and the starting_date of the model). 

Please tell me if I answered your questions or not — and in that case, please precise them (maybe with examples).

Cheers
Alexis



Representative of IRD in Vietnam and Philippines 
http://en.vietnam.ird.fr  
Senior Researcher, co-director, UMI UMMISCO 209, IRD & UPMC, France. http://ummisco.fr 
Director, ICTLab, USTH, Hanoi, Vietnam http://ictlab.usth.edu.vn 

--
You received this message because you are subscribed to the Google Groups "GAMA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gama-platfor...@googlegroups.com.
To post to this group, send email to gama-p...@googlegroups.com.
Visit this group at https://groups.google.com/group/gama-platform.
For more options, visit https://groups.google.com/d/optout.

saad touhbi

unread,
Apr 21, 2017, 11:07:36 AM4/21/17
to GAMA, alexis....@ird.fr
Hi,
Thanks for the info on how to use milliseconds in models. I am actually talking about manipulating the class GamaDate while developping a plugin. 
I have many agents that I want to schedule to appear according to a timeTable. First thing is that i couldn't assign a date to a level of milliseconds to each agent arrival. I suppose this could be done by this taking a date x and using the method plus like this :

x.plus(Duration.ofMillis(( 100));


Now that I have a timeTable, I try to use it on an actions that would be called in a reflex. So I try to get the current_date in the simulation

GamaDate now = scope.getExperiment().getSimulation().getCurrentDate();


comparing the current date (now) with a date in my timeTable is a bit difficult. I used 

now.equals(mydate) and it seems like it only compares the two on a second level.

 Would you suggest a way to compare the two dates according to my criteria?

saad touhbi

unread,
Apr 25, 2017, 8:19:12 PM4/25/17
to GAMA, alexis....@ird.fr
No solution here ?
Could you at least tell me how to convert a date to milliseconds in the GamaDate Class.
Reply all
Reply to author
Forward
0 new messages