130 lines
4.0 KiB
C
130 lines
4.0 KiB
C
|
|
/*
|
|||
|
|
* UnrelateWorkFlowFileHelper.h
|
|||
|
|
*
|
|||
|
|
* Created on: Mar 5, 2015
|
|||
|
|
* Author: dev
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
#ifndef PAI_FRAME_WORKFLOWENGINE_UNRELATEWORKFLOWFILEHELPER_H
|
|||
|
|
#define PAI_FRAME_WORKFLOWENGINE_UNRELATEWORKFLOWFILEHELPER_H
|
|||
|
|
|
|||
|
|
#include <set>
|
|||
|
|
#include <vector>
|
|||
|
|
|
|||
|
|
#include "WorkFlowFile.h"
|
|||
|
|
|
|||
|
|
class CUnrelateWorkFlowFileHelperTest;
|
|||
|
|
namespace pai{
|
|||
|
|
namespace workflow{
|
|||
|
|
|
|||
|
|
struct UnrelateRoot2LeafPair
|
|||
|
|
{
|
|||
|
|
std::set<int> roots;
|
|||
|
|
std::set<int> leafs;
|
|||
|
|
bool HasRoots(const int root)
|
|||
|
|
{
|
|||
|
|
if(roots.count(root) > 0)
|
|||
|
|
{
|
|||
|
|
return true;
|
|||
|
|
}else
|
|||
|
|
{
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
void InsertPair(int root, std::set<int>& leaf)
|
|||
|
|
{
|
|||
|
|
roots.insert(root);
|
|||
|
|
for(std::set<int>::iterator iter = leaf.begin(); iter != leaf.end(); iter++)
|
|||
|
|
{
|
|||
|
|
leafs.insert(*iter);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
class CUnrelateWorkFlowFileHelper
|
|||
|
|
{
|
|||
|
|
private:
|
|||
|
|
std::vector<CWorkFlowFile*>* unrelatedWorkflowFileList;
|
|||
|
|
|
|||
|
|
friend class ::CUnrelateWorkFlowFileHelperTest; //for test
|
|||
|
|
|
|||
|
|
private:
|
|||
|
|
/**
|
|||
|
|
* @brief 获取workflowfile中的所有输出
|
|||
|
|
* @param[in] workflowFile
|
|||
|
|
* @param[in/out] leafList 存储输出模块的moduleid
|
|||
|
|
*/
|
|||
|
|
void GetLeafList(CWorkFlowFile* workflowFile, std::set<int>& leafList);
|
|||
|
|
/**
|
|||
|
|
* @brief 获取workflowfile中的所有输入
|
|||
|
|
* @param[in] workflowFile
|
|||
|
|
* @param[in/out] rootList 存储输入模块的moduleid
|
|||
|
|
*/
|
|||
|
|
void GetRootList(CWorkFlowFile* workflowFile, std::set<int>& rootList);
|
|||
|
|
/**
|
|||
|
|
* @brief 获取从输入可以到达的输出的映射
|
|||
|
|
* @param[in] connections
|
|||
|
|
* @param[in] rootList 所有的根节点
|
|||
|
|
* @param[in] leafList 所有的叶子节点
|
|||
|
|
* @param[in/out] root2LeafList 存储输入模块的moduleid 与输出模块id的映射
|
|||
|
|
*/
|
|||
|
|
void GetRoot2LeafList(std::vector<CModuleConnection*>* connections, std::set<int>& rootList,
|
|||
|
|
std::set<int>& leafList, std::map<int, std::set<int> >& root2LeafList);
|
|||
|
|
/**
|
|||
|
|
* @brief 递归获取从输入可以到达的输出的映射
|
|||
|
|
* @param[in] connections
|
|||
|
|
* @param[in] leafList 所有的叶子节点
|
|||
|
|
* @param[in] moduleID 模块id
|
|||
|
|
* @param[in/out] findLeafs
|
|||
|
|
*/
|
|||
|
|
void InternalGetRoot2LeafList(std::vector<CModuleConnection*>* connections,
|
|||
|
|
std::set<int>& leafList, int moduleID, std::set<int>& findLeafs);
|
|||
|
|
/**
|
|||
|
|
* @brief 获取不相关的的输入和输出对
|
|||
|
|
* @param[in] root2LeafList 储输入模块的moduleid 与输出模块id的映射
|
|||
|
|
* @param[in/out] root2LeafPairList 存储不相关的的输入和输出对
|
|||
|
|
*/
|
|||
|
|
void GetUnrelateRoot2LeafPair(std::map<int, std::set<int> >& root2LeafList,
|
|||
|
|
std::vector<UnrelateRoot2LeafPair>& root2LeafPairList);
|
|||
|
|
/**
|
|||
|
|
* @brief 通过rootlist中跟节点,获取所有下游节点
|
|||
|
|
* @param[in] rootList 存储跟节点
|
|||
|
|
* @param[in] connections
|
|||
|
|
* @param[in/out] unrelateWorkflowModuleIDs 存储moduleid
|
|||
|
|
*/
|
|||
|
|
void GetUnrelateModuleIdByRootId(std::set<int>& rootList, std::vector<CModuleConnection*>* connections,
|
|||
|
|
std::set<int>& unrelateWorkflowModuleIDs);
|
|||
|
|
/**
|
|||
|
|
* @brief 递归获取所有下游节点
|
|||
|
|
* @param[in] sourceId
|
|||
|
|
* @param[in] connections
|
|||
|
|
* @param[in/out] unrelateWorkflowModuleIDs 存储moduleid
|
|||
|
|
*/
|
|||
|
|
void InneralGetUnrelateModuleIdByRootId(const int sourceId, std::vector<CModuleConnection*>* connections,
|
|||
|
|
std::set<int>& unrelateWorkflowModuleIDs);
|
|||
|
|
/**
|
|||
|
|
* @brief 在sourceWorkflowFile的基础上创建新的workflowfile对象
|
|||
|
|
* @param[in] sourceWorkflowFile
|
|||
|
|
* @param[in] unrelateWorkflowModuleIDs 新workflowfile中包含的moduleid
|
|||
|
|
* @return 新的workflowfile对象
|
|||
|
|
*/
|
|||
|
|
CWorkFlowFile* GetNewWorkFlowFile(CWorkFlowFile* sourceWorkflowFile,
|
|||
|
|
std::set<int>& unrelateWorkflowModuleIDs);
|
|||
|
|
public:
|
|||
|
|
CUnrelateWorkFlowFileHelper(CWorkFlowFile* workflowFile);
|
|||
|
|
~CUnrelateWorkFlowFileHelper();
|
|||
|
|
/**
|
|||
|
|
* @brief 对workflowFile拆分后,在workflowFile有可能出现多个互补相干的工作流
|
|||
|
|
* @param[in] workflowFile
|
|||
|
|
* @param[in/out] unrelatedWorkflowFileList 保存结果
|
|||
|
|
*/
|
|||
|
|
std::vector<CWorkFlowFile*>* GetUnrelatedWorkFlowFile();
|
|||
|
|
|
|||
|
|
void GetTopLevelWkf(std::vector<CWorkFlowFile*>& result, std::map<int, int>& outputID2inputID);
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endif /* WORKFLOWFILEWRAPPER_H_ */
|