diff --git a/README.md b/README.md index ea8903f..a119503 100755 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ Follow the steps below to install the SOFAI Tool locally: 4. **Verify installation**: ```bash - python -c "import sofai; print('SOFAI Tool installed successfully!')" + python -c 'import sofai_tool; print("SOFAI Tool installed successfully!")' ``` ### Optional: Installing in Development Mode diff --git a/sofai_tool/metacognition/metacognition_module.py b/sofai_tool/metacognition/metacognition_module.py index 7c879b8..d43c402 100644 --- a/sofai_tool/metacognition/metacognition_module.py +++ b/sofai_tool/metacognition/metacognition_module.py @@ -18,23 +18,19 @@ tested_s1 = False tested_s2 = False -def try_s1(problemId,system1_solver,correctness_threshold,timerSOFAI, run_type): +def try_s1(problemId,system1_solver,correctness_threshold,timerSOFAI): global tested_s1 if not tested_s1: tested_s1 = True system1_solver.calculate_correctness(problemId) if (system1_solver.correctness >= correctness_threshold): - if run_type=='sofai': - model_of_self.memorize_solution(system1_solver,systemALL, problemId, timerSOFAI, 0) - #print(f"Solution found by System 1: {system1_solver.solution} with correctness {system1_solver.correctness}") - else: - model_of_self.memorize_solution(system1_solver,systemONE, problemId, timerSOFAI, 0) + model_of_self.memorize_solution(system1_solver,systemONE, problemId, timerSOFAI, 0) return True return False else: return False -def try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_context,difficulty, run_type): +def try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_context,difficulty): global tested_s2 if not tested_s2: tested_s2 = True @@ -45,10 +41,7 @@ def try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_ system2_solver.solve(problemId,time_limit_context - (time.time() - timerSOFAI)) system2_solver.calculate_correctness(problemId) if (system2_solver.correctness >= correctness_threshold): - if run_type=='sofai': - model_of_self.memorize_solution(system2_solver,systemALL, problemId, timerSOFAI, difficulty) - else: - model_of_self.memorize_solution(system2_solver,systemTWO, problemId, timerSOFAI, difficulty) + model_of_self.memorize_solution(system2_solver,systemTWO, problemId, timerSOFAI, difficulty) return True return False else: @@ -72,12 +65,12 @@ def metacognition(problemId, system1_solver, system2_solver, context_file, thres if run_type == "s1": timerSOFAI = time.time() system1_solver.solve(problemId) - if not try_s1(problemId,system1_solver,correctness_threshold,timerSOFAI,run_type): + if not try_s1(problemId,system1_solver,correctness_threshold,timerSOFAI): utilities.end_computation(problemId, timerSOFAI) return if run_type == "s2": timerSOFAI = time.time() - if not try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_context, -1, run_type): + if not try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_context, -1): utilities.end_computation(problemId, timerSOFAI) return @@ -99,8 +92,8 @@ def metacognition(problemId, system1_solver, system2_solver, context_file, thres M = 0 if (system1_solver.confidence * (1-M) >= T3): # print("---------------HERE 1") - if not try_s1(problemId,system1_solver,correctness_threshold,timerSOFAI,run_type): - if not try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_context,-1, run_type): + if not try_s1(problemId,system1_solver,correctness_threshold,timerSOFAI): + if not try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_context,-1): utilities.end_computation(problemId, timerSOFAI) return @@ -117,8 +110,8 @@ def metacognition(problemId, system1_solver, system2_solver, context_file, thres ## If we think that there is not enough time to employ System-2, we check System-1 solution even if it has low confidence value if (estimated_cost_s2 > 1): # print("---------------HERE 2") - if not try_s1(problemId,system1_solver,correctness_threshold,timerSOFAI,run_type): - if not try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_context,estimated_difficulty_s2,run_type): + if not try_s1(problemId,system1_solver,correctness_threshold,timerSOFAI): + if not try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_context,estimated_difficulty_s2): utilities.end_computation(problemId, timerSOFAI) return @@ -131,8 +124,8 @@ def metacognition(problemId, system1_solver, system2_solver, context_file, thres r_value = random.random() if (probability_s1 > r_value): # print("---------------HERE 3") - if not try_s1(problemId,system1_solver,correctness_threshold,timerSOFAI,run_type): - if not try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_context,estimated_difficulty_s2,run_type): + if not try_s1(problemId,system1_solver,correctness_threshold,timerSOFAI): + if not try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_context,estimated_difficulty_s2): utilities.end_computation(problemId, timerSOFAI) return @@ -144,18 +137,18 @@ def metacognition(problemId, system1_solver, system2_solver, context_file, thres if (system1_solver.correctness >= correctness_threshold): # print("---------------HERE 4") if((1-(estimated_cost_s2 * (1-T3))) > (system1_solver.correctness*(1-M))): - if try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_context,estimated_difficulty_s2,run_type): + if try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_context,estimated_difficulty_s2): return #If we exit from try_s2 then no solution is found - model_of_self.memorize_solution(system1_solver,systemALL, problemId, timerSOFAI, estimated_difficulty_s2) + model_of_self.memorize_solution(system1_solver,systemONE, problemId, timerSOFAI, estimated_difficulty_s2) return ### Finally we run System-2 only if the available time is within reasonable distance w.r.t. the time we think that the System-2 is goin to take ## We arbitrary set the extra time to be 50% flexibility_perc = 50 if ((time.time() - timerSOFAI) >= (estimated_time_s2 - (float(estimated_time_s2)/100.0 * float(flexibility_perc)))): # print("---------------HERE 5") - if try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_context,estimated_difficulty_s2,run_type): + if try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_context,estimated_difficulty_s2): return utilities.end_computation(problemId, timerSOFAI) # it is going to this one at the end, means it is not going inside any if loop above!, not directly, none of the if loop conditions are getting true! diff --git a/sofai_tool/metacognition/mos.py b/sofai_tool/metacognition/mos.py index a115d07..02bc0fe 100644 --- a/sofai_tool/metacognition/mos.py +++ b/sofai_tool/metacognition/mos.py @@ -55,7 +55,7 @@ def memorize_solution(solver, system, name, timerComputation, difficulty, contin try: memory_file = open(experience_file) except: - createFolders() + createFolders("experience.json", False) memory_file = open(experience_file) totalTIME = time.time()-timerComputation diff --git a/sofai_tool/solvers/solver.py b/sofai_tool/solvers/solver.py index 79ac962..3a4cf6d 100644 --- a/sofai_tool/solvers/solver.py +++ b/sofai_tool/solvers/solver.py @@ -1,6 +1,6 @@ class Solver: def __init__(self): - self.correctness = 0 + self.correctness = None self.confidence = None self.solution = "noSolution" self.running_time = None