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 
31 // std::size_t index;
32 // boost::default_color_type color;
33  const WorkflowTask *task;
34  };
35 
39  typedef boost::adjacency_list<boost::listS, boost::vecS, boost::bidirectionalS, VertexProperties> DAG;
40 
44  typedef unsigned long vertex_t; // To clean up some day...
45 
49  class DagOfTasks {
50 
51  public:
52 
53  void addVertex(const WorkflowTask *task);
54 
55  void removeVertex(WorkflowTask *task);
56 
57  void addEdge(WorkflowTask *src, WorkflowTask *dst);
58 
59  void removeEdge(WorkflowTask *src, WorkflowTask *dst);
60 
61  bool doesPathExist(const WorkflowTask *src, const WorkflowTask *dst);
62  bool doesEdgeExist(const WorkflowTask *src, const WorkflowTask *dst);
63 
64  long getNumberOfChildren(const WorkflowTask *task);
65 
66  std::vector<WorkflowTask *> getChildren(const WorkflowTask *task);
67 
68  long getNumberOfParents(const WorkflowTask *task);
69 
70  std::vector<WorkflowTask *> getParents(const WorkflowTask *task);
71 
72  private:
73 
77  class custom_bfs_visitor : public boost::default_bfs_visitor {
78  public:
79 
80  const WorkflowTask *target_task;
81 
82  explicit custom_bfs_visitor(const WorkflowTask *target_task) : boost::default_bfs_visitor() {
83  this->target_task = target_task;
84  }
85 
86  template<typename Vertex, typename Graph>
87  void discover_vertex(Vertex u, Graph &g) {
88  if (g[u].task == target_task) {
89  throw std::runtime_error("path found");
90  }
91  }
92  };
93 
94  std::vector<const WorkflowTask*> task_list;
95  std::unordered_map<const WorkflowTask *, unsigned long> task_map;
96 
97  DAG dag;
98 
99  };
100 
101 /***********************/
103 /***********************/
104 
105 }
106 
107 
108 #endif //WRENCH_DAGOFTASKS_H
An internal class that uses the Boost Graph Library to implement a DAG of WorkflowTask objects.
Definition: DagOfTasks.h:49
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
unsigned long vertex_t
Convenient vertext_t typedef.
Definition: DagOfTasks.h:44
Definition: Alarm.cpp:20
Data structure to store vertex properties.
Definition: DagOfTasks.h:30
A computational task in a Workflow.
Definition: WorkflowTask.h:31
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
boost::adjacency_list< boost::listS, boost::vecS, boost::bidirectionalS, VertexProperties > DAG
Convenient DAG typedef.
Definition: DagOfTasks.h:39
bool doesEdgeExist(const WorkflowTask *src, const WorkflowTask *dst)
Method to check whether an edge exists between to task vertices.
Definition: DagOfTasks.cpp:137