-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added save_history and update_states
- Loading branch information
Showing
9 changed files
with
66 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#Function for changing the save_history setting | ||
function set_save_history!(agent::Agent, save_history::Bool) | ||
|
||
#Change it in the agent | ||
agent.save_history = save_history | ||
|
||
#And in its substruct | ||
set_save_history!(agent.substruct, save_history) | ||
end | ||
|
||
#If there is an empty substruct, do nothing | ||
function set_save_history!(substruct::Nothing, save_history::Bool) | ||
return nothing | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
### Function which updates a single state, and saves it history | ||
function update_states!(agent::Agent, state::String, value) | ||
#Update state | ||
agent.states[state] = value | ||
|
||
#Save to history | ||
if agent.save_history | ||
push!(agent.history[state], value) | ||
end | ||
end | ||
|
||
|
||
### Function which updates a dictionary of states to their values | ||
function update_states!(agent::Agent, states::Dict) | ||
#For each state and value | ||
for (state, value) in states | ||
#Update it | ||
update_states!(agent, state, value) | ||
end | ||
end |