-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresearch_table_generator.py
More file actions
159 lines (142 loc) · 6.27 KB
/
research_table_generator.py
File metadata and controls
159 lines (142 loc) · 6.27 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import json
import pandas as pd
from pathlib import Path
def load_results(file_path):
"""Load results from JSON file if it exists."""
if Path(file_path).exists():
with open(file_path, 'r') as f:
return json.load(f)
return None
def format_violation_types(results):
"""Format primary violation types in research table format."""
hard = results["results"]["hard_constraints"]
total = hard["total_violations"]
lecturer = hard["lecturer_conflicts"]
capacity = hard["room_capacity_violations"]
groups = hard["student_group_conflicts"]
return f"{total} ({lecturer}), ({capacity}), ({groups})"
def generate_research_table():
"""Generate research comparison table."""
# Load ACO results
aco_results = load_results("aco_results.json")
# Create comparison table data
table_data = []
if aco_results:
aco_row = {
"Algorithm": "ACO",
"Hard Constraint Violations": aco_results["results"]["hard_constraints"]["total_violations"],
"Primary Violation Types": format_violation_types(aco_results),
"Soft Constraint Score": f"{aco_results['results']['soft_constraints']['overall_score']:.3f}",
"Convergence Speed (iterations)": aco_results["results"]["convergence_speed"],
"Parameters": f"α={aco_results['parameters']['alpha']}, β={aco_results['parameters']['beta']}, ρ={aco_results['parameters']['evaporation_rate']}"
}
table_data.append(aco_row)
# Placeholder for other algorithms (you would load these from your GA and RL results)
# Example template rows based on your research format:
placeholder_algorithms = [
{
"Algorithm": "NSGA-II",
"Hard Constraint Violations": "TBD",
"Primary Violation Types": "TBD",
"Soft Constraint Score": "TBD",
"Convergence Speed (iterations)": "TBD",
"Parameters": "TBD"
},
{
"Algorithm": "MOEA/D",
"Hard Constraint Violations": "TBD",
"Primary Violation Types": "TBD",
"Soft Constraint Score": "TBD",
"Convergence Speed (iterations)": "TBD",
"Parameters": "TBD"
},
{
"Algorithm": "SPEA2",
"Hard Constraint Violations": "TBD",
"Primary Violation Types": "TBD",
"Soft Constraint Score": "TBD",
"Convergence Speed (iterations)": "TBD",
"Parameters": "TBD"
},
{
"Algorithm": "Q-Learning",
"Hard Constraint Violations": "TBD",
"Primary Violation Types": "TBD",
"Soft Constraint Score": "TBD",
"Convergence Speed (iterations)": "TBD",
"Parameters": "TBD"
},
{
"Algorithm": "DQN",
"Hard Constraint Violations": "TBD",
"Primary Violation Types": "TBD",
"Soft Constraint Score": "TBD",
"Convergence Speed (iterations)": "TBD",
"Parameters": "TBD"
},
{
"Algorithm": "SARSA",
"Hard Constraint Violations": "TBD",
"Primary Violation Types": "TBD",
"Soft Constraint Score": "TBD",
"Convergence Speed (iterations)": "TBD",
"Parameters": "TBD"
},
{
"Algorithm": "BCO",
"Hard Constraint Violations": "TBD",
"Primary Violation Types": "TBD",
"Soft Constraint Score": "TBD",
"Convergence Speed (iterations)": "TBD",
"Parameters": "TBD"
}
]
# Add placeholder rows
table_data.extend(placeholder_algorithms)
# Create DataFrame
df = pd.DataFrame(table_data)
# Display table
print("="*120)
print("RESEARCH COMPARISON TABLE - TIMETABLE SCHEDULING ALGORITHMS")
print("="*120)
print(df.to_string(index=False))
print("="*120)
# Save to CSV for further editing
df.to_csv("research_comparison_table.csv", index=False)
print("Table saved to research_comparison_table.csv")
# Detailed ACO results breakdown
if aco_results:
print("\nDETAILED ACO RESULTS BREAKDOWN:")
print("-" * 50)
hard = aco_results["results"]["hard_constraints"]
soft = aco_results["results"]["soft_constraints"]
print(f"Hard Constraints:")
print(f" • Total Violations: {hard['total_violations']}")
print(f" • Vacant Rooms: {hard['vacant_rooms']}")
print(f" • Lecturer Conflicts: {hard['lecturer_conflicts']}")
print(f" • Room Capacity Violations: {hard['room_capacity_violations']}")
print(f" • Student Group Conflicts: {hard['student_group_conflicts']}")
print(f" • Unassigned Activities: {hard['unassigned_activities']}")
print(f"\nSoft Constraints (Individual Components):")
components = soft["components"]
print(f" • Student Fatigue: {components['student_fatigue']:.3f}")
print(f" • Student Idle Time: {components['student_idle']:.3f}")
print(f" • Student Lecture Spread: {components['student_spread']:.3f}")
print(f" • Lecturer Fatigue: {components['lecturer_fatigue']:.3f}")
print(f" • Lecturer Idle Time: {components['lecturer_idle']:.3f}")
print(f" • Lecturer Lecture Spread: {components['lecturer_spread']:.3f}")
print(f" • Lecturer Workload Balance: {components['lecturer_balance']:.3f}")
print(f" • Overall Score: {soft['overall_score']:.3f}")
print(f"\nAlgorithm Performance:")
print(f" • Convergence Speed: {aco_results['results']['convergence_speed']} iterations")
print(f" • Final Fitness: {aco_results['results']['final_fitness']:.3f}")
params = aco_results['parameters']
print(f"\nACO Parameters:")
print(f" • Number of Ants: {params['n_ants']}")
print(f" • Iterations: {params['n_iterations']}")
print(f" • Alpha (pheromone): {params['alpha']}")
print(f" • Beta (heuristic): {params['beta']}")
print(f" • Evaporation Rate: {params['evaporation_rate']}")
print(f" • Q0 (exploitation): {params['q0']}")
if __name__ == "__main__":
generate_research_table()