DagOfTasks.h
1 
10 #ifndef WRENCH_DAGOFTASKS_H
11 #define WRENCH_DAGOFTASKS_H
12 
13 #include <boost/graph/adjacency_list.hpp>
14 #include <boost/graph/breadth_first_search.hpp>
15 #include <iostream>
16 
17 #include <wrench/workflow/WorkflowTask.h>
18 
19 namespace wrench {
20 
21 /***********************/
23 /***********************/
24 
25  class WorkflowTask;
26 
28 // std::size_t index;
29 // boost::default_color_type color;
30  const WorkflowTask *task;
31  };
32 
33  typedef boost::adjacency_list<boost::listS, boost::vecS, boost::bidirectionalS, VertexProperties> DAG;
34 
35  typedef unsigned long vertex_t; // To clean up later...
36 
40  class DagOfTasks {
41 
42  public:
43 
44  void addVertex(const WorkflowTask *task);
45 
46  void removeVertex(WorkflowTask *task);
47 
48  void addEdge(WorkflowTask *src, WorkflowTask *dst);
49 
50  void removeEdge(WorkflowTask *src, WorkflowTask *dst);
51 
52  bool doesPathExist(const WorkflowTask *src, const WorkflowTask *dst);
53  bool doesEdgeExist(const WorkflowTask *src, const WorkflowTask *dst);
54 
55  long getNumberOfChildren(const WorkflowTask *task);
56 
57  std::vector<WorkflowTask *> getChildren(const WorkflowTask *task);
58 
59  long getNumberOfParents(const WorkflowTask *task);
60 
61  std::vector<WorkflowTask *> getParents(const WorkflowTask *task);
62 
63  private:
64 
68  class custom_bfs_visitor : public boost::default_bfs_visitor {
69  public:
70 
71  const WorkflowTask *target_task;
72 
73  explicit custom_bfs_visitor(const WorkflowTask *target_task) : boost::default_bfs_visitor() {
74  this->target_task = target_task;
75  }
76 
77  template<typename Vertex, typename Graph>
78  void discover_vertex(Vertex u, Graph &g) {
79  if (g[u].task == target_task) {
80  throw std::runtime_error("path found");
81  }
82  }
83  };
84 
85  std::vector<const WorkflowTask*> task_list;
86  std::unordered_map<const WorkflowTask *, unsigned long> task_map;
87 
88  DAG dag;
89 
90  };
91 
92 /***********************/
94 /***********************/
95 
96 }
97 
98 
99 #endif //WRENCH_DAGOFTASKS_H
An internal class that uses the Boost Graph Library to implement a DAG of WorkflowTask objects.
Definition: DagOfTasks.h:40
std::vector< WorkflowTask * > getChildren(const WorkflowTask *task)
Method to get the children of a task vertex.
Definition: DagOfTasks.cpp:178
void removeEdge(WorkflowTask *src, WorkflowTask *dst)
Remove an edge between two task vertices.
Definition: DagOfTasks.cpp:83
long getNumberOfParents(const WorkflowTask *task)
Method to get the number of parents of a task vertex.
Definition: DagOfTasks.cpp:198
void addEdge(WorkflowTask *src, WorkflowTask *dst)
Method to add an edge between to task vertices.
Definition: DagOfTasks.cpp:64
void addVertex(const WorkflowTask *task)
Method to add a task vertex to the DAG.
Definition: DagOfTasks.cpp:24
bool doesPathExist(const WorkflowTask *src, const WorkflowTask *dst)
Method to check whether a path exists between to task vertices.
Definition: DagOfTasks.cpp:102
Definition: Alarm.cpp:20
Definition: DagOfTasks.h:27
A computational task in a Workflow.
Definition: WorkflowTask.h:27
std::vector< WorkflowTask * > getParents(const WorkflowTask *task)
Method to get the parents of a task vertex.
Definition: DagOfTasks.cpp:217
long getNumberOfChildren(const WorkflowTask *task)
Method to get the number of children of a task vertex.
Definition: DagOfTasks.cpp:159
void removeVertex(WorkflowTask *task)
Method to remove a task vertex from the DAG.
Definition: DagOfTasks.cpp:39
bool doesEdgeExist(const WorkflowTask *src, const WorkflowTask *dst)
Method to check whether an edge exists between to task vertices.
Definition: DagOfTasks.cpp:137