5#ifndef LINE_API_WF_WF_AUTO_INTEGRATION_H
6#define LINE_API_WF_WF_AUTO_INTEGRATION_H
74 default:
return "AUTO";
137 const std::vector<double> N =
sn.njobs();
138 for (std::size_t i = 0; i < N.size(); ++i)
139 if (!std::isinf(N[i]) && !std::isnan(N[i])) f.
totalJobs +=
static_cast<long>(N[i]);
141 (
sn.nchains > 0) ?
static_cast<double>(f.
totalJobs) /
static_cast<double>(
sn.nchains) : 0.0;
177 for (std::size_t i = 0; i < p.
sequences.size(); ++i) {
179 mx = std::max(mx, p.
sequences[i].size());
187 for (std::size_t i = 0; i < p.
parallels.size(); ++i) {
189 mx = std::max(mx, p.
parallels[i].size());
202 for (std::size_t i = 0; i < p.
branches.size(); ++i)
212inline void push_alternative(std::vector<WfSolver>* alt,
WfSolver rec,
WfSolver s) {
213 if (s == rec)
return;
214 for (std::size_t i = 0; i < alt->size(); ++i)
215 if ((*alt)[i] == s)
return;
233 double confidence = 0.7;
236 r.
reasoning.push_back(
"Detected sequence patterns - suitable for analytical methods");
239 r.
reasoning.push_back(
"Long sequences detected - consider FLUID approximation");
244 r.
reasoning.push_back(
"Detected parallel patterns - fork-join structures present");
247 "High parallelism detected - exact methods may be computationally expensive");
250 r.
reasoning.push_back(
"Switching to SSA for high-parallelism workflow");
260 r.
reasoning.push_back(
"Detected loop patterns with avg probability " +
261 std::to_string(avgLoop));
264 "High loop probability detected - may cause numerical instability");
270 }
else if (maxLoop > 0.5) {
271 r.
reasoning.push_back(
"Moderate loop probability - analytical methods suitable");
277 r.
reasoning.push_back(
"Detected branch patterns with avg entropy " +
278 std::to_string(avgEntropy));
279 if (avgEntropy > 1.5) {
280 r.
reasoning.push_back(
"High branching entropy - complex decision structure");
282 r.
reasoning.push_back(
"Many branches detected - consider simulation methods");
287 if (avgEntropy < 0.5) {
288 r.
reasoning.push_back(
"Low branching entropy - deterministic-like behavior");
296 r.
reasoning.push_back(
"Workflow complexity reduced by " +
297 std::to_string(
static_cast<int>(reduction * 100)) +
298 "% through pattern optimization");
302 r.
reasoning.push_back(
"Large optimized workflow - consider approximation methods");
305 r.
reasoning.push_back(
"Switching from NC to MVA for large workflow");
311 confidence = std::min(1.0, std::max(0.1, confidence));
317 for (std::size_t i = 0; i < 6; ++i) detail::push_alternative(&r.
alternativeSolvers, rec, standard[i]);
351 std::vector<std::string> out;
353 out.push_back(
"Consider merging sequential services to reduce overhead");
355 out.push_back(
"Parallel patterns can benefit from resource pooling strategies");
356 if (!p.
loops.empty())
357 out.push_back(
"High-probability loops may benefit from caching or memoization");
360 for (std::size_t i = 0; i < p.
branches.size(); ++i)
361 total +=
static_cast<double>(p.
branches[i].branchNodes.size());
362 if (total /
static_cast<double>(p.
branches.size()) > 3.0)
363 out.push_back(
"Complex branching patterns - consider load balancing strategies");
371 std::vector<std::string> out;
374 out.push_back(
"Expected " + std::to_string(
static_cast<int>(ratio * 100)) +
375 "% reduction in solve time");
377 out.push_back(
"High potential for parallel execution optimization");
379 out.push_back(
"Loop patterns may affect solver convergence rates");
A network plus its refreshed NetworkStruct.
Dense matrix and non-owning view.
WorkflowAnalysis< T > analyze_workflow(const WorkflowRepresentation< T > &w)
Detect, collapse, and report.
WfSolver wf_base_recommendation(const WfModelFacts< T > &f)
The AUTO heuristic before the workflow features amend it.
ExtendedSolverRecommendation< T > recommend_solver_with_workflow_analysis(const qn::NetworkStruct< T > &sn)
The entry point: analyse the workflow, then let it amend the base choice.
bool validate_workflow_enhancement(const qn::NetworkStruct< T > &sn)
The reference's self-check: a usable recommendation over a valid analysis.
std::string wf_solver_name(WfSolver s)
The reference's own spelling of each choice.
bool validate_analysis(const WorkflowAnalysis< T > &a)
The collapsed workflow is consistent and every detected pattern validates.
std::vector< std::string > get_optimization_recommendations(const WorkflowAnalysis< T > &a)
The reference's recommendation strings, in its order.
WfSolver
The solvers the reference chooses among.
WfModelFacts< T > wf_model_facts(const qn::NetworkStruct< T > &sn)
Read the base facts off a NetworkStruct.
ExtendedSolverRecommendation< T > enhance_recommendation_with_workflow(WfSolver base, const WorkflowFeatures< T > &f, const WorkflowAnalysis< T > &a)
Amend the base recommendation with what the workflow analysis found.
WorkflowFeatures< T > extract_workflow_features(const WorkflowAnalysis< T > &a)
Flatten the analysis into the feature vector the heuristic reads.
WfSolver create_optimal_solver(const qn::NetworkStruct< T > &sn)
The chosen solver alone, i.e.
BranchDiversity< T > calculate_branch_diversity(const BranchPattern< T > &pattern)
Shannon entropy of the branch probabilities, the same entropy normalized by log(n),...
std::vector< std::string > generate_pattern_insights(const DetectedPatterns< T > &p)
Pattern-level advice; the strings are the reference's, verbatim.
OptimizationInsights get_optimization_insights(const qn::NetworkStruct< T > &sn)
All three advisory blocks for one model.
std::vector< std::string > generate_performance_predictions(const WorkflowAnalysis< T > &a)
Solve-time advice keyed off the collapse ratio and the pattern mix.
WorkflowRepresentation< T > wf_from_struct(const qn::NetworkStruct< T > &sn)
Build a workflow representation from a NetworkStruct.
A queueing network and its refreshed NetworkStruct.
Number-type abstraction for the templated API port.
Everything the four detectors found.
std::vector< std::vector< int > > sequences
std::vector< BranchPattern< T > > branches
std::vector< std::vector< int > > parallels
What the recommendation returns: the choice and why.
std::vector< std::string > reasoning
WorkflowFeatures< T > workflowFeatures
WfSolver recommendedSolver
std::vector< WfSolver > alternativeSolvers
at most three, the reference's cap
The advisory text the reference's getOptimizationInsights assembles.
std::vector< std::string > recommendations
std::vector< std::string > performancePredictions
std::vector< std::string > patternInsights
The four model facts the base recommendation reads, i.e.
What analyze_workflow returns.
WorkflowStatistics< T > statistics
DetectedPatterns< T > detectedPatterns
The flat feature vector the recommendation reads.
std::size_t originalNodeCount
std::size_t originalLinkCount
std::size_t optimizedNodeCount
std::size_t maxSequenceLength
std::size_t maxParallelism
std::size_t optimizedLinkCount
The workflow in matrix form: the reference's WorkflowRepresentation.
The workflow analyzer: detect every pattern, collapse them, report the two complexities and the recom...