1
1
# Copyright (C) 2014-2015 Bart Smeets
2
2
# Copyright (C) 2015-2016 Bart Smeets and Iñaki Ucar
3
- # Copyright (C) 2016-2022 Iñaki Ucar
3
+ # Copyright (C) 2016-2024 Iñaki Ucar
4
4
#
5
5
# This file is part of simmer.
6
6
#
93
93
trajectory <- function (name = " anonymous" , verbose = FALSE ) {
94
94
check_args(name = " character" , verbose = " flag" )
95
95
96
- env <- list2env(list (
97
- name = name , verbose = verbose , n_activities = 0 , names = NULL , ptrs = NULL ))
96
+ env <- list2env(list (name = name , verbose = verbose , n_activities = 0 ,
97
+ names = NULL , tags = NULL , ptrs = NULL ))
98
98
env $ head <- function () env $ ptrs [[1 ]]
99
99
env $ tail <- function () env $ ptrs [[length(env )]]
100
100
env $ clone <- function () subset.trajectory(env )
@@ -114,7 +114,7 @@ print.trajectory <- function(x, indent=0, verbose=x$verbose, ...) {
114
114
115
115
add_activity <- function (x , activity , env. = parent.frame()) {
116
116
tag <- env. $ tag
117
- if (! missing(tag )) {
117
+ if (missing(tag )) tag <- NA else {
118
118
if (! is.character(tag ))
119
119
stop(get_caller(), " : 'tag' is not a valid character" , call. = FALSE )
120
120
activity_set_tag_(activity , tag )
@@ -123,6 +123,7 @@ add_activity <- function(x, activity, env.=parent.frame()) {
123
123
activity_chain_(x $ tail(), activity )
124
124
x $ ptrs <- c(x $ ptrs , activity )
125
125
x $ names <- c(x $ names , get_caller())
126
+ x $ tags <- c(x $ tags , tag )
126
127
x $ n_activities <- x $ n_activities + activity_get_count_(activity )
127
128
x
128
129
}
@@ -136,7 +137,7 @@ get_parts <- function(x, i, double=FALSE) {
136
137
if (is.logical(i )) {
137
138
parts <- which(rep_len(i , length(x )))
138
139
} else if (is.character(i )) {
139
- parts <- which(x $ names %in% i )
140
+ parts <- sort(unique(c( which(x $ names %in% i ), which( x $ tags %in% i ))) )
140
141
if (double ) parts <- parts [[1 ]]
141
142
} else if (is.numeric(i )) {
142
143
i <- i [! is.na(i )]
@@ -163,6 +164,7 @@ subset.trajectory <- function(x, i, double=FALSE) {
163
164
})
164
165
mapply(activity_chain_ , new $ ptrs [- length(new $ ptrs )], new $ ptrs [- 1 ])
165
166
new $ names <- x $ names [parts ]
167
+ new $ tags <- x $ tags [parts ]
166
168
}
167
169
new
168
170
}
@@ -195,8 +197,8 @@ replace.trajectory <- function(x, i, value, double=FALSE) {
195
197
# ' hence truncated towards zero). Negative integers indicate elements/slices to
196
198
# ' leave out the selection.
197
199
# '
198
- # ' Character vectors will be matched to the names of the activities in the
199
- # ' trajectory as by \code{\link{\%in\%}}.
200
+ # ' Character vectors will be matched to the names and tags of the activities
201
+ # ' in the trajectory as by \code{\link{\%in\%}}.
200
202
# '
201
203
# ' Logical vectors indicate elements/slices to select. Such vectors are recycled
202
204
# ' if necessary to match the corresponding extent.
@@ -328,6 +330,7 @@ join.trajectory <- function(...) {
328
330
329
331
new $ ptrs <- c(new $ ptrs , i $ ptrs )
330
332
new $ names <- c(new $ names , i $ names )
333
+ new $ tags <- c(new $ tags , i $ tags )
331
334
new $ n_activities <- new $ n_activities + i $ n_activities
332
335
}
333
336
new
0 commit comments