2024-09-24 10:43:10 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
#include "data_type.h"
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <QHash>
|
|
|
|
|
|
|
|
|
|
namespace dags {
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20>ڵ<EFBFBD><DAB5>ֲ㸨<D6B2><E3B8A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
class DAGLayerHelper {
|
|
|
|
|
private:
|
|
|
|
|
graph_data::Node bind_node;
|
|
|
|
|
int input_count = 0;
|
|
|
|
|
QList<std::shared_ptr<DAGLayerHelper>> next_points;
|
|
|
|
|
int layer_v = 0;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit DAGLayerHelper(const graph_data::Node& bind);
|
|
|
|
|
|
|
|
|
|
graph_data::Node bindPoint() const;
|
|
|
|
|
int& inputCount();
|
|
|
|
|
int layerValue() const;
|
|
|
|
|
void setLayerValue(int v);
|
|
|
|
|
void nextAppend(std::shared_ptr<DAGLayerHelper> inst);
|
|
|
|
|
QList<std::shared_ptr<DAGLayerHelper>> nextNodes() const;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
class DAGOrderHelper {
|
|
|
|
|
private:
|
|
|
|
|
std::shared_ptr<DAGLayerHelper> layer_bind = nullptr;
|
|
|
|
|
std::shared_ptr<DAGLayerHelper> relate_bind = nullptr;
|
|
|
|
|
std::shared_ptr<DAGLayerHelper> towards_to = nullptr;
|
|
|
|
|
int layer_number = 0;
|
2024-10-05 13:15:07 +00:00
|
|
|
|
QVariant sort_number;
|
2024-09-24 10:43:10 +00:00
|
|
|
|
QList<std::shared_ptr<DAGOrderHelper>> __prev_layer_nodes;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD>νڵ<CEBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bind">ͼ<>νڵ<CEBD></param>
|
|
|
|
|
DAGOrderHelper(std::shared_ptr<DAGLayerHelper> bind);
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD>νڵ<CEBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="f"><3E><>ʼ<EFBFBD>ڵ<EFBFBD></param>
|
|
|
|
|
/// <param name="t"><3E><>ֹ<EFBFBD>ڵ<EFBFBD></param>
|
|
|
|
|
DAGOrderHelper(std::shared_ptr<DAGLayerHelper> f, std::shared_ptr<DAGLayerHelper> t);
|
|
|
|
|
|
|
|
|
|
bool isFakeNode() const;
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<DAGLayerHelper> layerNode() const;
|
2024-10-05 02:57:49 +00:00
|
|
|
|
std::shared_ptr<DAGLayerHelper> tailsNode() const;
|
|
|
|
|
std::shared_ptr<DAGLayerHelper> headsNode() const;
|
2024-09-24 10:43:10 +00:00
|
|
|
|
|
|
|
|
|
int layerNumber() const;
|
|
|
|
|
void setLayerNumber(int v);
|
|
|
|
|
|
2024-10-05 13:15:07 +00:00
|
|
|
|
QVariant sortNumber() const;
|
2024-09-24 10:43:10 +00:00
|
|
|
|
void setSortNumber(double v);
|
|
|
|
|
|
|
|
|
|
QList<std::shared_ptr<DAGOrderHelper>> getUpstreamNodes() const;
|
|
|
|
|
|
|
|
|
|
void appendUpstreamNode(std::shared_ptr<DAGOrderHelper> inst);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class DAGGraph {
|
|
|
|
|
private:
|
|
|
|
|
QHash<QString, std::shared_ptr<DAGLayerHelper>> graph_inst;
|
|
|
|
|
QList<std::shared_ptr<DAGOrderHelper>> node_with_layout;
|
|
|
|
|
int max_layer_count = 0;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
void rebuildFromEdges(const QList<graph_data::Arrow>& arrow_list);
|
2024-10-06 03:01:32 +00:00
|
|
|
|
void primitiveGraphLayout();
|
|
|
|
|
void forwardsLayoutImpls();
|
|
|
|
|
void backwardsLayoutImpls();
|
|
|
|
|
void adjustLayoutImpls();
|
2024-10-05 13:15:07 +00:00
|
|
|
|
|
2024-09-24 10:43:10 +00:00
|
|
|
|
QList<std::shared_ptr<DAGOrderHelper>> nodeWithLayout() const;
|
|
|
|
|
int maxLayerCount() const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::shared_ptr<DAGLayerHelper> spawns_peak(QList<std::shared_ptr<DAGLayerHelper>>& ref_set);
|
2024-10-05 02:19:24 +00:00
|
|
|
|
void graph_recovery(const QList<std::shared_ptr<DAGLayerHelper>> &sort_seqs);
|
|
|
|
|
int node_layering(const std::shared_ptr<DAGLayerHelper> &inst, int layer_current);
|
2024-09-24 10:43:10 +00:00
|
|
|
|
int node_layering_adj(std::shared_ptr<DAGLayerHelper> inst);
|
|
|
|
|
QList<std::shared_ptr<DAGOrderHelper>> tidy_graph_nodes();
|
2024-10-05 09:20:41 +00:00
|
|
|
|
void graph_layer_nodes_sort_forward(int layer_index, const QList<std::shared_ptr<DAGOrderHelper>> &nodes);
|
2024-10-05 02:57:49 +00:00
|
|
|
|
void graph_adjust_after_layout(const QList<std::shared_ptr<DAGOrderHelper>>& total_nodes);
|
2024-10-05 09:20:41 +00:00
|
|
|
|
|
2024-10-06 08:03:19 +00:00
|
|
|
|
QList<std::shared_ptr<DAGOrderHelper>> layer_adjust_via_next_sibling(int curr_layer, const QList<std::shared_ptr<DAGOrderHelper>>& total_nodes);
|
2024-10-05 09:20:41 +00:00
|
|
|
|
void node_adjust_via_next_sibling(std::shared_ptr<DAGOrderHelper> curr_node, const QList<std::shared_ptr<DAGOrderHelper>>& total_nodes);
|
2024-10-06 08:03:19 +00:00
|
|
|
|
|
|
|
|
|
bool current_nodelist_filling_indi(const QList<std::shared_ptr<DAGOrderHelper>>& ordered_nodes);
|
2024-10-05 13:15:07 +00:00
|
|
|
|
void nodes_sort_with_above(int curr_layer, const QList<std::shared_ptr<DAGOrderHelper>>& total_nodes);
|
2024-10-05 09:20:41 +00:00
|
|
|
|
void nodes_sort_with_belows(int curr_layer, const QList<std::shared_ptr<DAGOrderHelper>>& total_nodes);
|
2024-10-06 00:32:04 +00:00
|
|
|
|
|
2024-10-06 03:01:32 +00:00
|
|
|
|
void node_adjust_ingraph_forward(const QList<std::shared_ptr<DAGOrderHelper>>& total_nodes);
|
|
|
|
|
bool node_adjust_inlayer_forward(int curr_layer, const QList<std::shared_ptr<DAGOrderHelper>>& total_nodes);
|
2024-10-06 12:40:47 +00:00
|
|
|
|
bool node_adjust_inlayer_partition_indi(int layer_index, const QList<std::shared_ptr<DAGOrderHelper>>& total_nodes);
|
2024-10-06 03:01:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* .
|
|
|
|
|
*
|
|
|
|
|
* \param node
|
|
|
|
|
* \param total_nodes
|
|
|
|
|
* \return <<EFBFBD><EFBFBD><EFBFBD>Σ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ>
|
|
|
|
|
*/
|
|
|
|
|
std::pair<qlonglong, qlonglong> node_evaluate_with_downstream(std::shared_ptr<DAGOrderHelper> node, const QList<std::shared_ptr<DAGOrderHelper>>& total_nodes);
|
2024-10-06 08:03:19 +00:00
|
|
|
|
std::pair<qlonglong, qlonglong> node_evaluate_with_upstream(std::shared_ptr<DAGOrderHelper> node, const QList<std::shared_ptr<DAGOrderHelper>>& total_nodes);
|
2024-10-06 03:01:32 +00:00
|
|
|
|
|
2024-09-24 10:43:10 +00:00
|
|
|
|
};
|
|
|
|
|
}
|