Initial commit
This commit is contained in:
Executable
+53
@@ -0,0 +1,53 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
|
||||
|
||||
namespace wfr {
|
||||
namespace wep {
|
||||
|
||||
// Forward declarations
|
||||
class WorkflowExecutionPlan;
|
||||
class AbstractWepNode;
|
||||
|
||||
// main namespace
|
||||
namespace utils {
|
||||
|
||||
|
||||
class WepDotFileWriter {
|
||||
|
||||
// Invariant properties that can be accessed directly.
|
||||
public:
|
||||
typedef std::set<AbstractWepNode*> visitedNodes_t;
|
||||
const std::shared_ptr<WorkflowExecutionPlan> wep;
|
||||
const std::string workflowName;
|
||||
|
||||
// Non-Public functions
|
||||
private:
|
||||
void writeWepNodeAndEdges(std::ofstream& outfile, AbstractWepNode* node, visitedNodes_t& visitedNodes);
|
||||
|
||||
std::string getNodeType(AbstractWepNode* node);
|
||||
std::string getNodeLabel(AbstractWepNode* node);
|
||||
std::string getNodeID(AbstractWepNode* node);
|
||||
std::string getNodeShape(AbstractWepNode* node);
|
||||
std::string getNodeStatus(AbstractWepNode* node);
|
||||
std::string getNodeVisitationCount(AbstractWepNode* node);
|
||||
|
||||
public:
|
||||
WepDotFileWriter(const std::shared_ptr<WorkflowExecutionPlan>& wep) noexcept;
|
||||
|
||||
void printToFile();
|
||||
void printToFile(const std::string fileName);
|
||||
|
||||
};
|
||||
|
||||
|
||||
} /* namespace utils */
|
||||
} /* namespace wep */
|
||||
} /* namespace wfr */
|
||||
|
||||
Executable
+94
@@ -0,0 +1,94 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace wfr {
|
||||
namespace wep {
|
||||
class AbstractWepNode;
|
||||
}
|
||||
|
||||
namespace utils {
|
||||
namespace wep {
|
||||
|
||||
|
||||
|
||||
template<typename VisitType>
|
||||
void wepDepthFirstSearch(wfr::wep::AbstractWepNode* startNode, const VisitType& visitFunction,
|
||||
std::set<wfr::wep::AbstractWepNode*>& visitedNodes = std::set<wfr::wep::AbstractWepNode*>()) {
|
||||
visitedNodes.insert(startNode);
|
||||
if (visitFunction(startNode)) {
|
||||
for (auto c : startNode->getSuccessors()) {
|
||||
if (visitedNodes.find(c) == visitedNodes.end()) {
|
||||
wepDepthFirstSearch(c, visitFunction, visitedNodes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename VisitType>
|
||||
void wepBreadthFirstSearch(wfr::wep::AbstractWepNode* startNode, const VisitType& visitFunction) {
|
||||
std::vector<wfr::wep::AbstractWepNode*> nodeQueue;
|
||||
std::set<wfr::wep::AbstractWepNode*> visitedNodes;
|
||||
nodeQueue.push_back(startNode);
|
||||
while (!nodeQueue.empty()) {
|
||||
auto cn = nodeQueue.front();
|
||||
visitedNodes.insert(cn);
|
||||
nodeQueue.erase(nodeQueue.begin());
|
||||
if (visitFunction(cn)) {
|
||||
for (auto c : cn->getSuccessors()) {
|
||||
if (visitedNodes.find(c) == visitedNodes.end()) {
|
||||
bool isInQueue = false;
|
||||
for (auto e : nodeQueue) {
|
||||
if (c == e) {
|
||||
isInQueue = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isInQueue) {
|
||||
nodeQueue.push_back(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename VisitType>
|
||||
void wepBreadthFirstReverseSearch(wfr::wep::AbstractWepNode* startNode, const VisitType& visitFunction) {
|
||||
std::vector<wfr::wep::AbstractWepNode*> nodeQueue;
|
||||
std::set<wfr::wep::AbstractWepNode*> visitedNodes;
|
||||
nodeQueue.push_back(startNode);
|
||||
while (!nodeQueue.empty()) {
|
||||
auto cn = nodeQueue.front();
|
||||
visitedNodes.insert(cn);
|
||||
nodeQueue.erase(nodeQueue.begin());
|
||||
if (visitFunction(cn)) {
|
||||
for (auto c : cn->getPredecessors()) {
|
||||
if (visitedNodes.find(c) == visitedNodes.end()) {
|
||||
bool isInQueue = false;
|
||||
for (auto e : nodeQueue) {
|
||||
if (c == e) {
|
||||
isInQueue = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isInQueue) {
|
||||
nodeQueue.push_back(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user