-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecisionEngine.java
More file actions
92 lines (72 loc) · 2.95 KB
/
DecisionEngine.java
File metadata and controls
92 lines (72 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import java.util.*;
public class DecisionEngine {
public static void decide(Problem problem) {
String type = detectProblemType(problem.description);
List<Algorithm> algorithms = AlgorithmDB.getAlgorithms();
Map<String, Integer> scoreMap = new HashMap<>();
Map<String, String> reasonMap = new HashMap<>();
for (Algorithm algo : algorithms) {
if (!algo.category.equals(type)) continue;
int score = 0;
StringBuilder reason = new StringBuilder();
// Input size rule
if (problem.n > 10000 && algo.timeComplexity.contains("n^3")) {
score -= 60;
reason.append("Large input, O(n³) slow. ");
}
// Weighted graph rule
if (problem.weighted && algo.name.contains("Dijkstra")) {
score += 40;
reason.append("Weighted graph supported. ");
}
// Negative weight rule
if (problem.negativeWeight && algo.supportsNegative) {
score += 50;
reason.append("Handles negative weights. ");
}
if (problem.negativeWeight && !algo.supportsNegative) {
score -= 50;
reason.append("Does NOT support negative weights. ");
}
// Small input optimization
if (problem.n < 50 && algo.name.contains("Insertion")) {
score += 30;
reason.append("Small input optimized. ");
}
// BFS rule
if (!problem.weighted && algo.name.equals("BFS")) {
score += 40;
reason.append("Unweighted graph best for BFS. ");
}
scoreMap.put(algo.name, score);
reasonMap.put(algo.name, reason.toString());
}
printResult(scoreMap, reasonMap);
}
private static String detectProblemType(String desc) {
if (desc.contains("shortest") || desc.contains("distance") || desc.contains("path"))
return "shortest_path";
if (desc.contains("sort"))
return "sorting";
return "unknown";
}
private static void printResult(Map<String, Integer> scoreMap, Map<String, String> reasonMap) {
String bestAlgo = null;
int bestScore = Integer.MIN_VALUE;
for (String algo : scoreMap.keySet()) {
if (scoreMap.get(algo) > bestScore) {
bestScore = scoreMap.get(algo);
bestAlgo = algo;
}
}
System.out.println("\n✅ Best Algorithm: " + bestAlgo);
System.out.println("📊 Confidence: " + Math.min(100, bestScore + 60) + "%");
System.out.println("📌 Reason: " + reasonMap.get(bestAlgo));
System.out.println("\n❌ Avoid:");
for (String algo : scoreMap.keySet()) {
if (!algo.equals(bestAlgo)) {
System.out.println("- " + algo);
}
}
}
}