248 static constexpr std::size_t
npos =
static_cast<std::size_t
>(-1);
252 const std::string&
name()
const {
return name_; }
256 if (activity_map_.find(
name) != activity_map_.end())
257 throw InputError(
"Workflow: activity '" +
name +
"' is already declared");
259 const std::size_t idx = activities_.size() - 1;
260 activity_map_[
name] = idx;
271 precedences_.push_back(prec);
276 const std::vector<WorkflowActivity<T>>&
activities()
const {
return activities_; }
277 const std::vector<Precedence<T>>&
precedences()
const {
return precedences_; }
280 auto it = activity_map_.find(
name);
281 return it == activity_map_.end() ?
npos : it->second;
287 return activities_[i];
292 if (i >= activities_.size())
throw InputError(
"Workflow: activity index out of range");
293 return activities_[i];
302 if (activities_.empty())
303 throw InputError(
"Workflow must have at least one activity.");
306 for (
const std::string& nm : prec.pre_acts)
309 "' referenced in precedence not found in workflow.");
310 for (
const std::string& nm : prec.post_acts)
313 "' referenced in precedence not found in workflow.");
317 if (prec.post_type == PrecedenceType::POST_OR) {
318 if (prec.post_params.empty())
319 throw InputError(
"OR-fork must have probabilities specified.");
321 for (
const T& p : prec.post_params) total += p;
325 throw InputError(
"OR-fork probabilities must sum to 1.");
327 if (prec.post_type == PrecedenceType::POST_LOOP) {
328 if (prec.post_params.size() != 1)
329 throw InputError(
"Loop count must be a single positive number.");
331 throw InputError(
"Loop count must be a positive number.");
333 if (prec.pre_type == PrecedenceType::PRE_AND && !prec.pre_params.empty()) {
335 const double nb =
static_cast<double>(prec.pre_acts.size());
336 if (quorum > 0.0 && quorum < nb)
338 "AND-join with quorum " + std::to_string(
static_cast<long>(quorum)) +
339 " of " + std::to_string(
static_cast<long>(nb)) +
340 " is not supported by Workflow: a partial join is not the maximum of the "
341 "branches. Use a full join, or SolverLN with method='default', which "
342 "routes the join explicitly.");
355 if (cached_valid_)
return cached_ph_;
359 if (!compose_series_parallel(law)) {
365 cached_valid_ =
true;
406 activities_[i].set_host_demand(host_demand);
418 throw InputError(
"The activity mean must be a positive finite scalar.");
422 const Distrib<T>& d = activities_[i].host_demand();
423 const T old_mean = d.
mean;
424 if (d.
type == ProcessType::IMMEDIATE ||
431 const T factor = T(old_mean / mean_value);
439 cached_valid_ =
false;
440 sp_tree_.nodes.clear();
441 sp_tree_.root =
npos;
442 sp_tree_.leaf_of.clear();
443 sp_tree_.execs.clear();
450 cached_valid_ =
false;
451 if (!sp_built_)
return;
452 if (act_idx >= sp_tree_.leaf_of.size() || sp_tree_.leaf_of[act_idx] ==
npos) {
457 invalidate_branch(sp_tree_, sp_tree_.leaf_of[act_idx]);
467 cached_valid_ =
false;
468 if (!sp_built_)
return;
469 if (act_idx >= sp_tree_.leaf_of.size() || sp_tree_.leaf_of[act_idx] ==
npos) {
473 const std::size_t k = sp_tree_.leaf_of[act_idx];
474 invalidate_branch(sp_tree_, k);
476 if (node.
law.S.rows() > 0) {
477 for (std::size_t i = 0; i < node.
law.S.rows(); ++i)
478 for (std::size_t j = 0; j < node.
law.S.cols(); ++j)
479 node.
law.S(i, j) = T(node.
law.S(i, j) * factor);
489 if (!sp_built_ && !sp_failed_) build_sp_tree();
490 return sp_built_ ? &sp_tree_ :
nullptr;
507 const std::size_t n1 = a.
S.rows(), n2 = b.
S.rows();
511 for (std::size_t i = 0; i < n1; ++i)
512 for (std::size_t j = 0; j < n1; ++j) out.
S(i, j) = a.
S(i, j);
513 for (std::size_t i = 0; i < n2; ++i)
514 for (std::size_t j = 0; j < n2; ++j) out.
S(n1 + i, n1 + j) = b.
S(i, j);
516 for (std::size_t i = 0; i < n1; ++i) {
518 for (std::size_t j = 0; j < n1; ++j) rate += a.
S(i, j);
520 for (std::size_t j = 0; j < n2; ++j) out.
S(i, n1 + j) = T(rate * b.
alpha[j]);
524 for (
const T& v : a.
alpha) defect -= v;
525 out.
alpha.assign(n1 + n2, zero);
526 for (std::size_t i = 0; i < n1; ++i) out.
alpha[i] = a.
alpha[i];
527 for (std::size_t j = 0; j < n2; ++j) out.
alpha[n1 + j] = T(defect * b.
alpha[j]);
540 const std::size_t n1 = a.
S.rows(), n2 = b.
S.rows();
541 const std::size_t nboth = n1 * n2;
542 const std::size_t ntot = nboth + n1 + n2;
544 std::vector<T> abs1(n1, zero), abs2(n2, zero);
545 for (std::size_t i = 0; i < n1; ++i) {
547 for (std::size_t j = 0; j < n1; ++j) r += a.
S(i, j);
550 for (std::size_t i = 0; i < n2; ++i) {
552 for (std::size_t j = 0; j < n2; ++j) r += b.
S(i, j);
560 for (std::size_t i = 0; i < n1; ++i)
561 for (std::size_t j = 0; j < n2; ++j) {
562 const std::size_t r = i * n2 + j;
563 for (std::size_t ii = 0; ii < n1; ++ii)
564 out.
S(r, ii * n2 + j) += a.
S(i, ii);
565 for (std::size_t jj = 0; jj < n2; ++jj)
566 out.
S(r, i * n2 + jj) += b.
S(j, jj);
568 out.
S(r, nboth + i) += abs2[j];
569 out.
S(r, nboth + n1 + j) += abs1[i];
572 for (std::size_t i = 0; i < n1; ++i)
573 for (std::size_t j = 0; j < n1; ++j) out.
S(nboth + i, nboth + j) = a.
S(i, j);
574 for (std::size_t i = 0; i < n2; ++i)
575 for (std::size_t j = 0; j < n2; ++j)
576 out.
S(nboth + n1 + i, nboth + n1 + j) = b.
S(i, j);
578 out.
alpha.assign(ntot, zero);
579 for (std::size_t i = 0; i < n1; ++i)
580 for (std::size_t j = 0; j < n2; ++j)
591 const std::vector<T>& probs) {
593 std::size_t total = 0;
594 for (
const PhLaw<T>& l : laws) total += l.S.rows();
598 out.
alpha.assign(total, zero);
601 for (std::size_t b = 0; b < laws.size(); ++b) {
602 const std::size_t nb = laws[b].
S.rows();
603 for (std::size_t i = 0; i < nb; ++i) {
604 for (std::size_t j = 0; j < nb; ++j) out.
S(off + i, off + j) = laws[b].
S(i, j);
605 out.
alpha[off + i] = T(probs[b] * laws[b].alpha[i]);
630 const std::size_t n = body.
S.rows();
635 out.
alpha.assign(1, one);
645 out.
alpha.assign(n + 1, zero);
646 for (std::size_t i = 0; i < n; ++i) out.
alpha[i] = T(count * body.
alpha[i]);
647 out.
alpha[n] = T(one - count);
649 for (std::size_t i = 0; i < n; ++i)
650 for (std::size_t j = 0; j < n; ++j) out.
S(i, j) = body.
S(i, j);
655 const T p = T(one - one / count);
657 for (
const T& v : body.
alpha) defect -= v;
658 const T denom = T(one - p * defect);
660 out.
alpha.assign(n, zero);
661 for (std::size_t i = 0; i < n; ++i) out.
alpha[i] = T(body.
alpha[i] / denom);
664 for (std::size_t i = 0; i < n; ++i) {
666 for (std::size_t j = 0; j < n; ++j) rate += body.
S(i, j);
667 rate = T(-rate * p / denom);
668 for (std::size_t j = 0; j < n; ++j) out.
S(i, j) += T(rate * body.
alpha[j]);
700 const std::size_t n = S.
rows();
701 std::vector<std::vector<bool>> A(n, std::vector<bool>(n,
false));
702 std::vector<std::size_t> in_deg(n, 0);
703 for (std::size_t i = 0; i < n; ++i)
704 for (std::size_t j = 0; j < n; ++j) {
705 if (i == j)
continue;
712 std::vector<std::size_t> queue;
713 for (std::size_t i = 0; i < n; ++i)
714 if (in_deg[i] == 0) queue.push_back(i);
715 std::size_t visited = 0, head = 0;
716 while (head < queue.size()) {
717 const std::size_t cur = queue[head++];
719 for (std::size_t j = 0; j < n; ++j) {
720 if (!A[cur][j])
continue;
721 if (--in_deg[j] == 0) queue.push_back(j);
735 p.
pre_type = PrecedenceType::PRE_SEQ;
740 static std::vector<Precedence<T>>
SerialSequence(
const std::vector<std::string>& acts) {
741 std::vector<Precedence<T>> out;
742 for (std::size_t i = 0; i + 1 < acts.size(); ++i)
743 out.push_back(
Serial(acts[i], acts[i + 1]));
748 const std::vector<std::string>& posts) {
752 p.
pre_type = PrecedenceType::PRE_SEQ;
759 const std::string& post,
760 const std::vector<T>& quorum = std::vector<T>()) {
764 p.
pre_type = PrecedenceType::PRE_AND;
771 const std::vector<T>& probs) {
775 p.
pre_type = PrecedenceType::PRE_SEQ;
782 const std::string& post) {
786 p.
pre_type = PrecedenceType::PRE_OR;
800 p.
pre_type = PrecedenceType::PRE_SEQ;
812 enum class ParseStatus { END, STOP, JOIN, FAIL };
816 std::vector<std::size_t> out_p, in_p;
817 std::vector<bool> consumed;
820 bool compose_series_parallel(PhLaw<T>& out) {
822 if (sp_failed_)
return false;
824 if (!sp_built_)
return false;
826 out = compose_node(sp_tree_.root);
836 bool build_sp_tree() {
837 sp_tree_.nodes.clear();
838 sp_tree_.root =
npos;
839 sp_tree_.leaf_of.clear();
840 sp_tree_.execs.clear();
844 const std::size_t n = activities_.size();
845 if (n == 0)
return false;
848 S.out_p.assign(n,
npos);
849 S.in_p.assign(n,
npos);
850 S.consumed.assign(n,
false);
854 for (std::size_t p = 0; p < precedences_.size(); ++p) {
855 for (
const std::string& nm : precedences_[p].pre_acts) {
857 if (i ==
npos || S.out_p[i] !=
npos)
return false;
860 for (
const std::string& nm : precedences_[p].post_acts) {
862 if (j ==
npos || S.in_p[j] !=
npos)
return false;
867 std::vector<std::size_t> starts;
868 for (std::size_t i = 0; i < n; ++i)
869 if (S.in_p[i] ==
npos) starts.push_back(i);
870 if (starts.size() != 1)
return false;
872 std::vector<std::size_t>
kids;
873 std::size_t stop_at =
npos;
874 const ParseStatus st = sp_parse_seq(S, starts[0], std::vector<std::size_t>(), kids, stop_at);
875 if (st != ParseStatus::END)
return false;
876 for (std::size_t i = 0; i < n; ++i)
877 if (!S.consumed[i])
return false;
879 const std::size_t root = sp_serial_node(kids);
880 if (root ==
npos)
return false;
882 sp_tree_.root = root;
883 sp_tree_.leaf_of.assign(n,
npos);
884 for (std::size_t k = 0; k < sp_tree_.nodes.size(); ++k)
886 sp_tree_.leaf_of[sp_tree_.nodes[k].act] = k;
887 sp_tree_.execs = sp_execution_counts(sp_tree_);
895 ParseStatus sp_parse_seq(ParseState& S, std::size_t cur,
896 const std::vector<std::size_t>& stop_set,
897 std::vector<std::size_t>& kids, std::size_t& stop_at) {
900 if (cur ==
npos)
return ParseStatus::END;
901 if (std::find(stop_set.begin(), stop_set.end(), cur) != stop_set.end()) {
903 return ParseStatus::STOP;
905 if (S.consumed[cur])
return ParseStatus::FAIL;
906 S.consumed[cur] =
true;
908 std::vector<T>(), num_traits<T>::from_int(0)));
910 const std::size_t p = S.out_p[cur];
911 if (p ==
npos)
return ParseStatus::END;
912 const Precedence<T>& prec = precedences_[p];
913 if (prec.pre_acts.size() > 1) {
916 return ParseStatus::JOIN;
919 std::vector<std::size_t> post_inds = sp_indices_of(prec.post_acts);
920 for (std::size_t i : post_inds)
921 if (i ==
npos)
return ParseStatus::FAIL;
923 std::size_t knode =
npos, next_act =
npos;
924 switch (prec.post_type) {
925 case PrecedenceType::POST_AND:
926 if (!sp_parse_fork(S, post_inds, std::vector<T>(), stop_set,
true, knode,
928 return ParseStatus::FAIL;
929 kids.push_back(knode);
932 case PrecedenceType::POST_OR:
933 if (prec.post_params.size() != post_inds.size())
return ParseStatus::FAIL;
934 if (!sp_parse_fork(S, post_inds, prec.post_params, stop_set,
false, knode,
936 return ParseStatus::FAIL;
937 kids.push_back(knode);
940 case PrecedenceType::POST_LOOP:
941 if (!sp_parse_loop(S, post_inds, prec.post_params, stop_set, knode, next_act))
942 return ParseStatus::FAIL;
943 kids.push_back(knode);
946 case PrecedenceType::POST_SEQ:
947 if (post_inds.size() != 1)
return ParseStatus::FAIL;
953 return ParseStatus::FAIL;
959 bool sp_parse_fork(ParseState& S,
const std::vector<std::size_t>& branch_heads,
960 const std::vector<T>& probs,
const std::vector<std::size_t>& stop_set,
961 bool is_and, std::size_t& knode, std::size_t& next_act) {
962 const std::size_t nb = branch_heads.size();
963 std::vector<std::size_t> branch_nodes(nb,
npos), bstop(nb,
npos);
964 std::vector<ParseStatus> bstatus(nb, ParseStatus::FAIL);
966 for (std::size_t b = 0; b < nb; ++b) {
967 std::vector<std::size_t> bkids;
968 std::size_t sa =
npos;
969 const ParseStatus st = sp_parse_seq(S, branch_heads[b], stop_set, bkids, sa);
970 if (st == ParseStatus::FAIL)
return false;
971 const std::size_t bn = sp_serial_node(bkids);
972 if (bn ==
npos)
return false;
973 branch_nodes[b] = bn;
978 const bool all_join =
979 std::all_of(bstatus.begin(), bstatus.end(),
980 [](ParseStatus s) { return s == ParseStatus::JOIN; });
981 const bool all_end = std::all_of(bstatus.begin(), bstatus.end(),
982 [](ParseStatus s) { return s == ParseStatus::END; });
983 const bool all_stop = std::all_of(bstatus.begin(), bstatus.end(),
984 [](ParseStatus s) { return s == ParseStatus::STOP; });
985 const bool same_stop =
986 std::all_of(bstop.begin(), bstop.end(),
987 [&bstop](std::size_t x) { return x == bstop[0]; });
990 if (!same_stop)
return false;
991 const Precedence<T>& join_prec = precedences_[bstop[0]];
992 if (join_prec.pre_acts.size() != nb)
return false;
994 if (join_prec.pre_type != PrecedenceType::PRE_AND)
return false;
996 if (join_prec.pre_type != PrecedenceType::PRE_OR)
return false;
998 const std::vector<std::size_t> post_inds = sp_indices_of(join_prec.post_acts);
999 if (post_inds.size() != 1 || post_inds[0] ==
npos)
return false;
1000 next_act = post_inds[0];
1001 }
else if (all_end) {
1005 }
else if (!is_and && all_stop && same_stop) {
1006 next_act = bstop[0];
1012 num_traits<T>::from_int(0));
1020 bool sp_parse_loop(ParseState& S,
const std::vector<std::size_t>& post_inds,
1021 const std::vector<T>& counts,
const std::vector<std::size_t>& stop_set,
1022 std::size_t& knode, std::size_t& next_act) {
1023 if (counts.size() != 1)
return false;
1024 const T count = counts[0];
1026 std::vector<std::size_t> body_acts;
1027 std::size_t end_act =
npos;
1028 if (post_inds.size() >= 2) {
1029 body_acts.assign(post_inds.begin(), post_inds.end() - 1);
1030 end_act = post_inds.back();
1032 body_acts.push_back(post_inds[0]);
1035 std::vector<std::size_t> loop_stop = stop_set;
1036 loop_stop.insert(loop_stop.end(), body_acts.begin(), body_acts.end());
1037 if (end_act !=
npos) loop_stop.push_back(end_act);
1039 std::vector<std::size_t> body_kids;
1041 while (j < body_acts.size()) {
1042 const std::size_t a = body_acts[j];
1043 if (S.consumed[a]) {
1047 std::vector<std::size_t> this_stop;
1048 for (std::size_t x : loop_stop)
1049 if (x != a) this_stop.push_back(x);
1051 std::vector<std::size_t> kk;
1052 std::size_t sa =
npos;
1053 const ParseStatus st = sp_parse_seq(S, a, this_stop, kk, sa);
1054 if (st == ParseStatus::FAIL)
return false;
1055 body_kids.insert(body_kids.end(), kk.begin(), kk.end());
1057 if (st == ParseStatus::END) {
1059 }
else if (st == ParseStatus::STOP) {
1060 const auto it = std::find(body_acts.begin(), body_acts.end(), sa);
1061 if (it != body_acts.end()) {
1062 j =
static_cast<std::size_t
>(it - body_acts.begin());
1063 }
else if (end_act !=
npos && sa == end_act) {
1064 j = body_acts.size();
1075 const std::size_t body_node = sp_serial_node(body_kids);
1076 if (body_node ==
npos)
return false;
1079 std::vector<T>(), count);
1085 std::size_t sp_serial_node(
const std::vector<std::size_t>& kids) {
1087 if (
kids.size() == 1)
return kids[0];
1089 num_traits<T>::from_int(0));
1092 std::size_t sp_add_node(
SPNodeType type, std::size_t act,
1093 const std::vector<std::size_t>& kids,
const std::vector<T>& probs,
1101 sp_tree_.nodes.push_back(node);
1102 const std::size_t k = sp_tree_.nodes.size() - 1;
1103 for (std::size_t c : kids) sp_tree_.nodes[c].parent = k;
1107 std::vector<std::size_t> sp_indices_of(
const std::vector<std::string>& names)
const {
1108 std::vector<std::size_t> out(names.size(),
npos);
1109 for (std::size_t i = 0; i < names.size(); ++i) out[i] =
activity_index(names[i]);
1117 PhLaw<T> compose_node(std::size_t k) {
1118 SPNode<T>& node = sp_tree_.nodes[k];
1119 if (node.valid)
return node.law;
1122 switch (node.type) {
1124 law = activities_[node.act].ph_representation();
1127 const std::vector<std::size_t>
kids = node.kids;
1128 law = compose_node(kids[0]);
1129 for (std::size_t i = 1; i <
kids.size(); ++i)
1134 const std::vector<std::size_t>
kids = node.kids;
1135 law = compose_node(kids[0]);
1136 for (std::size_t i = 1; i <
kids.size(); ++i)
1141 const std::vector<std::size_t>
kids = node.kids;
1142 std::vector<PhLaw<T>> laws;
1143 for (std::size_t c : kids) laws.push_back(compose_node(c));
1148 const std::size_t
child = node.kids[0];
1154 sp_tree_.nodes[k].law = law;
1155 sp_tree_.nodes[k].valid =
true;
1159 static void invalidate_branch(SPTree<T>& tree, std::size_t k) {
1161 tree.nodes[k].valid =
false;
1162 k = tree.nodes[k].parent;
1172 static std::vector<T> sp_execution_counts(
const SPTree<T>& tree) {
1173 std::vector<T> execs(tree.nodes.size(), num_traits<T>::from_int(0));
1174 if (tree.root ==
npos)
return execs;
1175 execs[tree.root] = num_traits<T>::from_int(1);
1176 std::vector<std::size_t>
stack(1, tree.root);
1177 while (!
stack.empty()) {
1178 const std::size_t k =
stack.back();
1180 const SPNode<T>& node = tree.nodes[k];
1181 for (std::size_t i = 0; i < node.kids.size(); ++i) {
1182 const std::size_t c = node.kids[i];
1184 execs[c] = T(execs[k] * node.probs[i]);
1186 execs[c] = T(execs[k] * node.count);
1188 execs[c] = execs[k];
1202 std::size_t pre_act =
npos;
1203 std::vector<std::size_t> post_acts;
1204 std::vector<T> probs;
1209 std::vector<std::size_t> pre_acts;
1210 std::size_t post_act =
npos;
1214 std::size_t pre_act =
npos;
1215 std::vector<std::size_t> body_acts;
1216 std::size_t end_act =
npos;
1217 T count = num_traits<T>::from_int(1);
1221 std::vector<std::vector<std::size_t>> adj;
1222 std::vector<std::size_t> in_deg, out_deg;
1223 std::vector<ForkInfo> forks;
1224 std::vector<JoinInfo> joins;
1225 std::vector<LoopInfo> loops;
1228 Structure analyze_structure()
const {
1229 const std::size_t n = activities_.size();
1231 st.adj.assign(n, std::vector<std::size_t>());
1232 st.in_deg.assign(n, 0);
1233 st.out_deg.assign(n, 0);
1235 for (
const Precedence<T>& prec : precedences_) {
1236 const std::vector<std::size_t> pre = sp_indices_of(prec.pre_acts);
1237 const std::vector<std::size_t> post = sp_indices_of(prec.post_acts);
1238 for (std::size_t i : pre)
1239 for (std::size_t j : post) {
1240 st.adj[i].push_back(j);
1245 if (prec.post_type == PrecedenceType::POST_AND) {
1250 st.forks.push_back(f);
1251 }
else if (prec.post_type == PrecedenceType::POST_OR) {
1256 f.probs = prec.post_params;
1257 st.forks.push_back(f);
1258 }
else if (prec.post_type == PrecedenceType::POST_LOOP) {
1261 if (post.size() > 1) {
1262 l.body_acts.assign(post.begin(), post.end() - 1);
1263 l.end_act = post.back();
1267 l.count = prec.post_params.empty() ? num_traits<T>::from_int(1)
1268 : prec.post_params[0];
1269 st.loops.push_back(l);
1272 if (prec.pre_type == PrecedenceType::PRE_AND ||
1273 prec.pre_type == PrecedenceType::PRE_OR) {
1275 j.is_and = prec.pre_type == PrecedenceType::PRE_AND;
1277 j.post_act = post[0];
1278 st.joins.push_back(j);
1284 std::vector<std::size_t> topological_sort(
1285 const std::vector<std::vector<std::size_t>>& adj)
const {
1286 const std::size_t n = activities_.size();
1287 std::vector<std::size_t> in_deg(n, 0);
1288 for (
const std::vector<std::size_t>& nbrs : adj)
1289 for (std::size_t j : nbrs) ++in_deg[j];
1291 std::vector<std::size_t> queue, order;
1292 for (std::size_t i = 0; i < n; ++i)
1293 if (in_deg[i] == 0) queue.push_back(i);
1294 std::size_t head = 0;
1295 while (head < queue.size()) {
1296 const std::size_t cur = queue[head++];
1297 order.push_back(cur);
1298 for (std::size_t nx : adj[cur])
1299 if (--in_deg[nx] == 0) queue.push_back(nx);
1301 std::vector<bool> seen(n,
false);
1302 for (std::size_t i : order) seen[i] =
true;
1303 for (std::size_t i = 0; i < n; ++i)
1304 if (!seen[i]) order.push_back(i);
1316 PhLaw<T> build_ctmc() {
1317 const std::size_t n = activities_.size();
1318 if (n == 1)
return activities_[0].ph_representation();
1320 const Structure st = analyze_structure();
1322 std::vector<PhLaw<T>> block(n);
1323 std::vector<bool> absorbed(n,
false);
1324 for (std::size_t i = 0; i < n; ++i) block[i] = activities_[i].ph_representation();
1326 for (
const LoopInfo& loop : st.loops) {
1327 PhLaw<T> body = activities_[loop.body_acts[0]].ph_representation();
1328 for (std::size_t j = 1; j < loop.body_acts.size(); ++j)
1329 body =
compose_serial(body, activities_[loop.body_acts[j]].ph_representation());
1333 if (loop.end_act !=
npos) {
1334 res =
compose_serial(res, activities_[loop.end_act].ph_representation());
1335 absorbed[loop.end_act] =
true;
1337 block[loop.pre_act] = res;
1338 for (std::size_t idx : loop.body_acts) absorbed[idx] =
true;
1341 for (
const ForkInfo& fork : st.forks) {
1342 const JoinInfo*
join = find_matching_join(fork.post_acts, st.joins, fork.is_and);
1343 if (fork.is_and && join ==
nullptr)
continue;
1347 inner = block[fork.post_acts[0]];
1348 for (std::size_t i = 1; i < fork.post_acts.size(); ++i)
1351 std::vector<PhLaw<T>> laws;
1352 for (std::size_t idx : fork.post_acts) laws.push_back(block[idx]);
1357 if (join !=
nullptr && !absorbed[
join->post_act]) {
1359 absorbed[
join->post_act] =
true;
1361 block[fork.pre_act] = res;
1362 for (std::size_t idx : fork.post_acts) absorbed[idx] =
true;
1365 const std::vector<std::size_t> order = topological_sort(st.adj);
1366 bool started =
false;
1368 for (std::size_t idx : order) {
1369 if (absorbed[idx])
continue;
1377 if (!started) out = activities_[0].ph_representation();
1381 static const JoinInfo* find_matching_join(
const std::vector<std::size_t>& post_acts,
1382 const std::vector<JoinInfo>& joins,
bool is_and) {
1383 std::vector<std::size_t> want = post_acts;
1384 std::sort(want.begin(), want.end());
1385 for (
const JoinInfo& j : joins) {
1386 if (j.is_and != is_and)
continue;
1387 std::vector<std::size_t> have = j.pre_acts;
1388 std::sort(have.begin(), have.end());
1389 if (have == want)
return &j;
1395 std::vector<WorkflowActivity<T>> activities_;
1396 std::map<std::string, std::size_t> activity_map_;
1397 std::vector<Precedence<T>> precedences_;
1399 Distrib<T> cached_ph_;
1400 bool cached_valid_ =
false;
1402 bool sp_built_ =
false;
1403 bool sp_failed_ =
false;