Commit 552e1fdc authored by David Speck's avatar David Speck

new sdac manager

parent 036ba1b5
#include "sdac_plan_manager.h"
#include "../Meddly/operations_extension/userOperations.h"
#include "../task_proxy.h"
#include "../task_utils/task_properties.h"
#include "sym_variables.h"
#include <assert.h>
#include <fstream>
#include <iostream>
#include <sstream>
namespace symple {
SdacPlanManager::SdacPlanManager(std::shared_ptr<SymVariables> sym_vars,
std::shared_ptr<AbstractTask> task)
: PlanManager(), sym_vars(sym_vars), task(task) {}
void SdacPlanManager::save_plan(const Plan &plan, const TaskProxy &task_proxy,
bool generates_multiple_plan_files) {
std::ostringstream filename;
filename << plan_filename;
int plan_number = num_previously_generated_plans + 1;
if (generates_multiple_plan_files || is_part_of_anytime_portfolio) {
filename << "." << plan_number;
} else {
assert(plan_number == 1);
}
std::ofstream outfile(filename.str());
OperatorsProxy operators = task_proxy.get_operators();
MEDDLY::dd_edge cur_state =
sym_vars->get_state_edge(task->get_initial_state_values());
State cur_exp_state = task_proxy.get_initial_state();
float plan_cost = 0;
for (OperatorID op_id : plan) {
MEDDLY::dd_edge cost = sym_vars->get_constant_edge(-1);
MEDDLY::apply(USER_OPS::INTERSECTIONMAX, cur_state,
sym_vars->get_term_evmdd(
task->get_operator_cost_function(op_id.get_index())),
cost);
float cur_cost = -1;
cost.getEdgeValue(cur_cost);
std::cout << operators[op_id].get_name() << " (" << cur_cost << ")"
<< std::endl;
outfile << "(" << operators[op_id].get_name() << ")" << std::endl;
plan_cost += cur_cost;
if (!task_properties::is_applicable(task_proxy.get_operators()[op_id],
cur_exp_state)) {
std::cout << "Operator not applicable!" << std::endl;
utils::exit_with(utils::ExitCode::SEARCH_CRITICAL_ERROR);
}
cur_exp_state =
cur_exp_state.get_successor(task_proxy.get_operators()[op_id]);
cur_state = sym_vars->get_state_edge(cur_exp_state.get_values());
}
outfile << "; cost = " << (int)plan_cost << std::endl;
outfile.close();
std::cout << "Plan length: " << plan.size() << " step(s)." << std::endl;
std::cout << "Plan cost: " << (int)plan_cost << std::endl;
++num_previously_generated_plans;
}
} // namespace symple
#ifndef SEARCH_SYMPLE_SDAC_PLAN_MANAGER_H_
#define SEARCH_SYMPLE_SDAC_PLAN_MANAGER_H_
#include <memory>
#include "../plan_manager.h"
class AbstractTask;
namespace symple {
class SymVariables;
class SdacPlanManager : public PlanManager {
public:
SdacPlanManager(std::shared_ptr<SymVariables> sym_vars,
std::shared_ptr<AbstractTask> task);
void save_plan(const Plan &plan, const TaskProxy &task_proxy,
bool generates_multiple_plan_files = false) override;
protected:
std::shared_ptr<SymVariables> sym_vars;
std::shared_ptr<AbstractTask> task;
};
} // namespace symple
#endif /* SEARCH_SYMPLE_SDAC_PLAN_MANAGER_H_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment