13#include <nlohmann/json.hpp>
29 std::cout << topic <<
": " << mastery <<
"%\n";
37 std::map<std::string, std::vector<std::string>> dependencies;
38 std::map<std::string, double> synergies;
42 std::map<std::string, std::vector<std::string>> dependencies,
43 std::map<std::string, double> synergies)
44 : initial_state_(
initial_state), dependencies(std::move(dependencies)), synergies(std::move(synergies)) {}
47 return initial_state_;
51 auto* study_state =
dynamic_cast<StudyState*
>(state);
52 for (
const auto& [_, mastery] : study_state->mastery_levels) {
53 if (mastery < 100.0)
return false;
58 std::vector<std::shared_ptr<Action>>
actions(std::shared_ptr<State> state)
override {
59 auto* study_state = std::dynamic_pointer_cast<StudyState>(state).get();
60 std::vector<std::shared_ptr<Action>> available_actions;
62 for (
const auto& [topic, mastery] : study_state->mastery_levels) {
63 if (mastery < 100.0 && study_state->remaining_time > 0) {
65 auto new_mastery = study_state->mastery_levels;
66 new_mastery[topic] += std::min(10.0, 100.0 - mastery);
67 double synergy_bonus = synergies.count(topic) ? synergies.at(topic) : 0.0;
68 new_mastery[topic] += synergy_bonus;
70 double time_left = study_state->remaining_time - cost;
71 auto new_state =
new StudyState(new_mastery, time_left);
72 available_actions.emplace_back( std::make_shared<Action>(topic, cost, state, std::shared_ptr<State>(new_state)) );
76 return available_actions;
80 auto* study_state =
dynamic_cast<StudyState*
>(state);
82 for (
const auto& [_, mastery] : study_state->mastery_levels) {
83 total_gap += (100.0 - mastery);
90void run(std::string &input) {
91 std::ifstream file(input);
92 std::string json_string;
94 while (std::getline(file, line)) {
98 nlohmann::json json = nlohmann::json::parse(json_string);
99 std::map<std::string, double> mastery_levels = json[
"mastery_levels"];
100 std::map<std::string, std::vector<std::string>> dependencies = json[
"dependencies"];
101 std::map<std::string, double> synergies = json[
"synergies"];
102 double time = json[
"time"];
105 auto initial_state =
new StudyState(mastery_levels, time);
106 auto problem =
new StudyProblem(initial_state, dependencies, synergies);
110 std::cout <<
"Optimal study plan:\n";
111 auto current = solution;
113 if (current->action) {
114 std::cout <<
"Study " << current->action->name <<
" for " << current->action->cost <<
" hours\n";
116 current = current->parent;
119 std::cout <<
"No solution found within the given time.\n";
Represents an abstract problem that needs to be solved.
virtual std::shared_ptr< Node > search()=0
Represents an abstract state in a problem.
State * initial_state() override
Retrieves the initial state of the problem.
std::vector< std::shared_ptr< Action > > actions(std::shared_ptr< State > state) override
Retrieves the set of actions applicable to a given state.
bool goal_test(State *state) override
Tests if a given state satisfies the goal condition.
double heuristic(State *state) override
Computes a heuristic estimate for a given state.
StudyProblem(StudyState *initial_state, std::map< std::string, std::vector< std::string > > dependencies, std::map< std::string, double > synergies)
std::map< std::string, double > mastery_levels
StudyState(std::map< std::string, double > mastery_levels, double remaining_time)
void print() override
Prints the state details.
Search * create_search(SearchAlgorithmIndex search_algorithm_index, Problem *problem)
Factory method to create a search object based on the specified search algorithm.
void run(std::string &input)