I wrote the model that makes the daily life of the turtle and every the specific ticks that I assigned, the model will reset ticks to 0 again and I have set in global have day and every time my model reset, the number of days with + 1 in every loop. However, I want to make it like Monday, Tuesday, ..., Sunday and back again to Monday again.
Does anyone have any suggestions for the code?
If you don't need to know the actual date, because you are simply simulating time, you can use the "mod" function as JenB mentions above in a comment.
Here's an example that prints out a value of "day" that cycles each week. The example also has an offset in case you don't want to start on "Monday", and it shows how you could also get the name of the day ( such as "Monday") at the same time.
Enjoy!
;; IMPORTANT NOTE -- This doesn't look at the real world calendar,
;; You have to tell it what day is day zero.
;;
;; ticks start and zero and simply increment. You don't need to reset-ticks each week.
;; use the variable "day" for a value that starts at "offset" and increases by one each
;; day but also wraps back to zero automatically after it reaches 6
globals [
day ;; a numeric value from 0 to 6 representing day of the week
day-names ;; a list of names of the days you'd like to use
day-name ;; name of the current day based on the day-names list
offset ]
to setup
clear-all
set day-names ["Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"]
print day-names
set offset 0 ;; 0 starts the week on Sunday, offset 1 starts on Monday, etc.
reset-ticks
end
to go
if (ticks > 11 ) [stop] ;; don't consume the computer for this example
set day (offset + ticks) mod 7 ;; sets day from 0 to 6
set day-name item day day-names ;; picks up the name for that day if you want that
;; and let's print them out and confirm this is what we want
type "For offset " type offset
type ",Tick # " type ticks type " -> day # " type day type " which is " print day-name
tick
end
The Time extension is exactly for this. There is an old version here:
https://github.com/colinsheppard/time
(Click on "Clone or download", then "Download zip".)
You can set one tick to equal one day, one week, etc., then label your results by date.
This extension is supposed to be in preparation to be packaged with future versions of NetLogo.
Related
As the following test illustrates, if a turtle is running a while when it dies, this breaks out of the while (without any error). Is this behavior guaranteed by NetLogo?
to test
ca
let age 0
crt 1
ask turtle 0 [
while [true] [
set age (1 + age)
print (word "age is " age)
if (random-float 1 < 0.1) [die] ;death ends the while
]
]
end
Yes- whenever a turtle executes "die" it immediately stops execution of any commands. In your case, the while loop (and "ask turtle 0") is terminated. The turtle is also automatically removed from all agentsets.
If you used "[die show "I'm dead!"]" instead of just "[die]", the code would never show "I'm dead!" because it stops as soon as it executes "die".
(If you have ever tried to program a model that removes agents in another programming language, you should appreciate how magical NetLogo's "die" primitive is. In other languages, doing the same thing can be a complicated nightmare.)
:deadline future shows todo items with deadlines. I want to make a group with todo items due in 3 days, i.e. somewhat like:
:deadline before (today+3d)
I checked user manual and found it suggests using some string that can be processed by "org-time-string-to-absolute". I am novice to elisp and got stuck there.
This is a bit hacky too but check if it works
(-let* (((sec minute hour day month year dow dst utcoff)
(decode-time (+ (* 3 86400) (float-time)))) ;; 3 days
(target-date
(format "%d-%02d-%02d" year month day))
(org-super-agenda-groups
`((:deadline (before ,target-date))
(:discard (:anything t)))))
(org-todo-list))
I paste default timestamp and I can edit year, month, day, time with Shift-up and Shift-down
I want to use custom format
(setq-default org-display-custom-times t)
(setq org-time-stamp-custom-formats
'("<%d %b %Y %a" . "<%d %b %Y %a %H:%M>"))
But I can't edit year, month, time. Only day
What should I do to be able to edit year, month, time with Shift-up/down? I can't event select it
The Org Manual is explaining the disadvantages of using custom timestamps here:
https://orgmode.org/manual/Custom-time-format.html#Custom-time-format
The S-UP/DOWN keys can no longer be used to adjust each component of a timestamp. If the cursor is at the beginning of the stamp, S-UP/DOWN will change the stamp by one day, just like S-LEFT/RIGHT. At the end of the stamp, the time will be changed by one minute.
Does that not answer your question?
You can C-c C-x C-t to disable custom formats, edit your dates with S-UP/DOWN (or manually), and then do C-c C-x C-t to re-enable the custom format.
I’m running simulations in Netlogo, with coding to send results automatically to a spreadsheet. This occurs at the end of a simulation in order to save each individual’s variables (e.g., identity, home range size, etc.). The spreadsheet results look fine normally, but when using BehaviorSpace, occasionally data from an individual's variables are not printed correctly (e.g., data in wrong columns or missing, see screenshot below).
I’m wondering if during parallel runs in BehaviorSpace, when simulations happen to end at the same time this results in simultaneous writing to the file. Is that likely what’s happening? Should I be reasonably confident that remaining results were printed correctly to the table, aside from these noticeable issues? Most importantly, how can I avoid these misprints to the file? Sample code follows.
Bonus question [SOLVED]: I thought printing date-and-time would identify unique simulation runs, but this is not the case since each turtle's variables take more than an instant to print to the file. Is there a quick way to add a unique identifier for each simulation run?
Thanks!
to start-output-file ;; Observer procedure, called from setup.
set-current-directory "C:\\...
file-open "Table_results.csv"
;; Define the names of the variables:
file-type "Run,"
file-type "Landscape,"
file-type "Individual,"
file-type "Home range size,"
;; ... and so on, ~60 results saved for each individual
file-print ""
file-close ]
end
to end-simulation ;; Observer procedure, called from go.
write-outputs
file-close
end
to write-outputs ;; Observer procedure, called from end-simulation.
set-current-directory "C:\\...
file-open "Table_results.csv"
ask turtles
[ file-type (word date-and-time ", ") ;;<---Would like a unique run identifier here instead if possible.
file-type (word Landscape ", ")
file-type (word Who ", ")
file-type (word Home-range-size ", ")
;; ...
file-print "" ]]
end
Update/Solution: My solution was to have each model run write to a separate CSV. This allowed me to save results of each agent's variables. Files will each have a unique identifier so won't get overwritten or added to later. All the CSVs can then easily be imported and combined using Program R.
Example Code: Define a CSV file name during setup, and ask turtles to write their results to the file:
extensions [ csv ]
globals [ filename ] ;; Will define as the date/time and BehaviorSpace run #.
to setup
clear-all
let run-ID (remove-item 6 (remove-item 7 (remove-item 8 (remove "-"(remove " "(remove "." (remove ":" date-and-time)))))))
set filename (word "Results, " run-ID ", " word behaviorspace-run-number".csv")
file-open filename
start-output-file
;; Etc.
end
to start-output-file ;; Called from setup.
file-open filename
file-type "Turtle identity,"
file-type "Home range size,"
;; Etc., rest of column headers.
file-print ""
end
to end-simulation ;; Observer procedure, called from go.
ask turtles [ write-outputs ]
file-close
end
to write-outputs ;; Called from end-simulation.
file-type (word Who ", ")
file-type (word home-range-size ", ") ;; (Turtle variable for home range size.)
;; Etc., i.e., each turtle variable you are writing to file.
file-print ""
end
Hope this helps someone else looking to do something similar, or noticing similar oddities in their CSV output from BehaviorSpace.
I want to track habits using org-mode. For example, I want to do exercise 3 times every week. Is there a way to schedule 3 times a task every week irrespective of the date in org-mode?
You should be able to more or less do that using org habit tracking (See: Org-Habits).
To load org-habits you would need to add it to org-modules
(add-to-list 'org-modules "org-habit")
Then:
Use C-c C-s to set SCHEDULED.
Use C-c C-t to set your exercise TODO.
Use C-c C-x p to have the STYLE Property habit (add in any other properties as desired as well).
Now the lines like this should have be appended after the title:
:PROPERTIES:
:STYLE: habit
:END:
A single habit should suffice, it will not be exactly 3 times per week, but over time it will average out to such. If you use a scheduled repeater that is .+2d/3d you will be prompted to perform the habit no more often than every second day, and no less often than every 3. (This averages out to 2.9 times per week if you continue it long enough. Over 6 weeks (42 days) you would complete it at least 14 times, at most 21, or 17.5 on average. 18 times in 6 weeks would be 3x per week).
Your final habit should look something like this initially, as you complete it DONE logging will be added in and the last-repeat will be kept track of as a property:
** TODO Exercise
SCHEDULED: <2012-01-06 Fri .+2d/3d>
:PROPERTIES:
:STYLE: habit
:END:
Note: If you get the error Symbol's value as variable is void: org-modules when trying to load the org-habit module, you might want to try the following instead:
(require 'org)
(require 'org-install)
(add-to-list 'org-modules "org-habit")
You can use a timestamp with repeater interval as described in the
manual.
A timestamp may contain a _repeater interval_, indicating that it
applies not only on the given date, but again and again after a
certain interval of N days (d), weeks (w), months (m), or years
(y). The following will show up in the agenda every Wednesday:
* Pick up Sam at school <2007-05-16 Wed 12:30 +1w>
I can't see any way to do this with one entry. The way I do similar things is to create a special TODO sequence for is, say (sequence ('HABIT' '|' 'CHECK')) with setq org-todo-keywords
Then simply write three entries, each on a week repeat
* HABIT Monday workout
DEADLINE: <2012-01-09 Mon +1w>
* HABIT Wednessday workout
DEADLINE: <2012-01-11 Wed +1w>
* HABIT Friday workout
DEADLINE: <2012-01-06 Fri +1w>
It's not that clean, but it works.