Commit 4a7847ef authored by David Speck's avatar David Speck

raw version of bi-pot

parent ad029059
......@@ -718,6 +718,7 @@ fast_downward_plugin(
symple/sym_astar
symple/plan_reconstruction
symple/sym_enums
symple/bidirectional_potential
Meddly/operations_extension/userOperations
Meddly/operations_extension/evplus
Meddly/operations_extension/minus.
......
This diff is collapsed.
......@@ -16,46 +16,57 @@
#ifdef USE_LP
#define LP_METHOD(X) X;
#else
#define LP_METHOD(X) NO_RETURN X { \
#define LP_METHOD(X) \
NO_RETURN X \
{ \
ABORT("LP method called but the planner was compiled without LP support.\n" \
"See http://www.fast-downward.org/LPBuildInstructions\n" \
"to install an LP solver and use it in the planner."); \
}
"See http://www.fast-downward.org/LPBuildInstructions\n" \
"to install an LP solver and use it in the planner."); \
}
#endif
class CoinPackedVectorBase;
class OsiSolverInterface;
namespace options {
namespace options
{
class OptionParser;
}
namespace lp {
enum class LPSolverType {
CLP, CPLEX, GUROBI
namespace lp
{
enum class LPSolverType
{
CLP,
CPLEX,
GUROBI
};
enum class LPObjectiveSense {
MAXIMIZE, MINIMIZE
enum class LPObjectiveSense
{
MAXIMIZE,
MINIMIZE
};
void add_lp_solver_option_to_parser(options::OptionParser &parser);
class LPConstraint {
class LPConstraint
{
std::vector<int> variables;
std::vector<double> coefficients;
double lower_bound;
double upper_bound;
public:
public:
LPConstraint(double lower_bound, double upper_bound);
const std::vector<int> &get_variables() const {return variables;}
const std::vector<double> &get_coefficients() const {return coefficients;}
const std::vector<int> &get_variables() const { return variables; }
const std::vector<double> &get_coefficients() const { return coefficients; }
double get_lower_bound() const {return lower_bound;}
void set_lower_bound(double lb) {lower_bound = lb;}
double get_upper_bound() const {return upper_bound;}
void set_upper_bound(double ub) {upper_bound = ub;}
double get_lower_bound() const { return lower_bound; }
void set_lower_bound(double lb) { lower_bound = lb; }
double get_upper_bound() const { return upper_bound; }
void set_upper_bound(double ub) { upper_bound = ub; }
void clear();
bool empty() const;
......@@ -63,7 +74,8 @@ public:
void insert(int index, double coefficient);
};
struct LPVariable {
struct LPVariable
{
double lower_bound;
double upper_bound;
double objective_coefficient;
......@@ -77,7 +89,8 @@ struct LPVariable {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
class LPSolver {
class LPSolver
{
bool is_initialized;
bool is_solved;
int num_permanent_constraints;
......@@ -100,7 +113,8 @@ class LPSolver {
std::vector<double> row_ub;
std::vector<CoinPackedVectorBase *> rows;
void clear_temporary_data();
public:
public:
LP_METHOD(explicit LPSolver(LPSolverType solver_type))
/*
Note that the destructor does not use LP_METHOD because it should not
......@@ -111,9 +125,9 @@ public:
~LPSolver();
LP_METHOD(void load_problem(
LPObjectiveSense sense,
const std::vector<LPVariable> &variables,
const std::vector<LPConstraint> &constraints))
LPObjectiveSense sense,
const std::vector<LPVariable> &variables,
const std::vector<LPConstraint> &constraints))
LP_METHOD(void add_temporary_constraints(const std::vector<LPConstraint> &constraints))
LP_METHOD(void clear_temporary_constraints())
LP_METHOD(double get_infinity() const)
......@@ -151,6 +165,8 @@ public:
*/
LP_METHOD(std::vector<double> extract_solution() const)
LP_METHOD(std::vector<double> reduced_costs() const)
LP_METHOD(int get_num_variables() const)
LP_METHOD(int get_num_constraints() const)
LP_METHOD(int has_temporary_constraints() const)
......@@ -159,6 +175,6 @@ public:
#ifdef __GNUG__
#pragma GCC diagnostic pop
#endif
}
} // namespace lp
#endif
......@@ -8,11 +8,13 @@
#include <memory>
#include <vector>
namespace options {
namespace options
{
class Options;
}
namespace potentials {
namespace potentials
{
class PotentialFunction;
/*
......@@ -41,7 +43,8 @@ class PotentialFunction;
New Optimization Functions for Potential Heuristics.
ICAPS 2015.
*/
class PotentialOptimizer {
class PotentialOptimizer
{
std::shared_ptr<AbstractTask> task;
TaskProxy task_proxy;
lp::LPSolver lp_solver;
......@@ -56,7 +59,7 @@ class PotentialOptimizer {
void solve_and_extract();
void extract_lp_solution();
public:
public:
explicit PotentialOptimizer(const options::Options &opts);
~PotentialOptimizer() = default;
......@@ -71,6 +74,6 @@ public:
std::unique_ptr<PotentialFunction> get_potential_function() const;
};
}
} // namespace potentials
#endif
This diff is collapsed.
#ifndef SYMPLE_BIDIRECTIONAL_POTENTIAL_H
#define SYMPLE_BIDIRECTIONAL_POTENTIAL_H
#include "../lp/lp_solver.h"
#include "../abstract_task.h"
#include <vector>
#include <map>
//class MEDDLY::forest;
//class MEDDLY::expert_forest;
namespace symple
{
class BidirectionalPotential
{
public:
BidirectionalPotential(MEDDLY::forest *forest);
void test();
void dump_lp() const;
void reset_lp();
MEDDLY::dd_edge get_min_f(const MEDDLY::dd_edge &fwd, const MEDDLY::dd_edge &bwd, std::shared_ptr<AbstractTask> task);
protected:
void dump_lp_vars() const;
void dump_lp_const() const;
void init_lp(std::shared_ptr<AbstractTask> task);
void add_to_lp(const MEDDLY::dd_edge &dd, bool fwd);
std::vector<int> quasi_reduce(int cur_level, bool fwd);
MEDDLY::expert_forest *exp_forest;
lp::LPSolver lp_solver;
std::vector<lp::LPVariable> lp_vars;
std::vector<lp::LPConstraint> lp_const;
std::map<std::pair<int, int>, int> fwd_node_edge_to_lp_var;
std::map<std::pair<int, int>, int> bwd_node_edge_to_lp_var;
int quasi_nodes;
std::map<int, int> node_to_const; // For generating flow constraints (B)
std::vector<std::vector<int>> fact_to_const; // For generating consumer constraints (C)
};
} // namespace symple
#endif
\ No newline at end of file
......@@ -207,6 +207,11 @@ MEDDLY::dd_edge SymVariables::rename(const MEDDLY::dd_edge &from, int var_id, bo
return res;
}
MEDDLY::forest *SymVariables::get_forest() const
{
return forest;
}
template <typename T>
std::string to_string_with_precision(const T a_value, const int n = 20)
{
......
......@@ -24,6 +24,8 @@ class SymVariables
MEDDLY::dd_edge min_abstract(const MEDDLY::dd_edge &from, bool primed = false) const;
MEDDLY::dd_edge rename(const MEDDLY::dd_edge &from, int var_id, bool primed = false) const;
MEDDLY::forest *get_forest() const;
protected:
const std::shared_ptr<AbstractTask> task;
MEDDLY::domain *domain;
......
......@@ -3,6 +3,9 @@
#include "transition_relation.h"
#include "sym_astar.h"
#include "../Meddly/operations_extension/userOperations.h"
#include "bidirectional_potential.h"
#include "open_list.h"
#include "closed_list.h"
#include "../option_parser.h"
#include "../plugin.h"
......@@ -32,21 +35,39 @@ void SympleSearch::print_statistics() const
void SympleSearch::initialize()
{
sym_vars = std::make_shared<SymVariables>(task);
std::cout << "init symbolic variables..." << std::flush;
sym_vars->init();
std::cout << "done!" << std::endl;
std::cout << "init initial state..." << std::flush;
initialize_intial_state();
std::cout << "done!" << std::endl;
std::cout << "init goal states..." << std::flush;
initialize_goal_states();
std::cout << "done!" << std::endl;
std::cout << "init transition relations..." << std::flush;
initialize_trs();
std::cout << "done!" << std::endl;
std::cout << "merge transition relations..." << std::flush;
merge_trs(params.max_tr_size);
std::cout << "done!" << std::endl;
fwd_astar = std::make_shared<SymAstar>(sym_vars, task, true);
bwd_astar = std::make_shared<SymAstar>(sym_vars, task, false);
fwd_astar->init(init_state, bwd_astar);
bwd_astar->init(goal_states, fwd_astar);
// bi_pot.dump_lp();
/*bi_pot.test();
bi_pot.dump_lp();
bi_pot.reset_lp();
bi_pot.to_lp(init_state);
bi_pot.to_lp(goal_states);
bi_pot.dump_lp();*/
}
void SympleSearch::initialize_intial_state()
{
init_state = sym_vars->get_state_edge(task->get_initial_state_values());
// sym_vars->to_dot(init_state, "init.dot");
sym_vars->to_dot(init_state, "init.dot");
}
void SympleSearch::initialize_goal_states()
......@@ -58,7 +79,7 @@ void SympleSearch::initialize_goal_states()
goal_values[fact.var] = fact.value;
}
goal_states = sym_vars->get_state_edge(goal_values);
// sym_vars->to_dot(goal_states, "goal.dot");
sym_vars->to_dot(goal_states, "goal.dot");
}
void SympleSearch::initialize_trs()
{
......@@ -130,11 +151,23 @@ SearchStatus SympleSearch::step()
std::cout << step_dir << ": " << std::flush;
if (step_dir == Dir::FWD)
{
std::cout << "compute bi_pot..." << std::flush;
BidirectionalPotential bi_pot(sym_vars->get_forest());
MEDDLY::dd_edge goal_front = sym_vars->get_constant_edge(0);
MEDDLY::apply(USER_OPS::UNIONMIN, bwd_astar->get_open()->get_open_list(), bwd_astar->get_closed()->get_closed_list(), goal_front);
bi_pot.get_min_f(fwd_astar->get_open()->get_open_list(), goal_front, task);
opt_sol = fwd_astar->step(merged_trs);
std::cout << " [" << bwd_astar->last_step_time() << "s]" << std::endl;
std::cout << " [" << fwd_astar->last_step_time() << "s]" << std::endl;
}
else if (step_dir == Dir::BWD)
{
std::cout << "compute bi_pot..." << std::flush;
BidirectionalPotential bi_pot(sym_vars->get_forest());
MEDDLY::dd_edge goal_front = sym_vars->get_constant_edge(0);
MEDDLY::apply(USER_OPS::UNIONMIN, fwd_astar->get_open()->get_open_list(), fwd_astar->get_closed()->get_closed_list(), goal_front);
bi_pot.get_min_f(goal_front, bwd_astar->get_open()->get_open_list(), task);
opt_sol = bwd_astar->step(merged_trs);
std::cout << " [" << bwd_astar->last_step_time() << "s]" << std::endl;
}
......
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