Commit d6c90555 authored by Sumitra Corraya's avatar Sumitra Corraya

Update aStarBwd.cc

parent 32f3f17d
......@@ -4,7 +4,10 @@
#include "aStarBwd.h"
#include "../image.h"
#include <algorithm>
#include <vector>
#include <random>
#include <iterator>
#include <chrono>
void AStarBwd::image(MEDDLY::dd_edge &stateSet, MEDDLY::dd_edge &transOp,
MEDDLY::dd_edge &res) {
MEDDLY::dd_edge primedStateSet(forest);
......@@ -63,28 +66,34 @@ int AStarBwd::selectAnyState(MEDDLY::dd_edge &targetState) {
Operator *AStarBwd::reconstructPlanStep(MEDDLY::dd_edge &targetState) {
MEDDLY::FILE_output out(stdout);
int costAfter = selectAnyState(targetState);
// targetState.show(out, 3);
for (int op_i = 0; op_i < g_operators.size(); op_i++) {
MEDDLY::dd_edge successors(forest);
imageInv(targetState, *g_operators[op_i].get_op_evmdd(), successors);
typedef std::chrono::high_resolution_clock myclock;
myclock::time_point beginning = myclock::now();
myclock::duration d = myclock::now() - beginning;
unsigned seed = d.count();
std::mt19937 g(seed);
std::vector<int> vector;
for (int op_i = 0; op_i < g_operators.size(); op_i++) {
vector.push_back(op_i);
}
std::shuffle(vector.begin(), vector.end(), g);
for (std::vector<int>::iterator it=vector.begin(); it!=vector.end(); ++it)
{
MEDDLY::dd_edge predecessors(forest);
imageInv(targetState, *g_operators[*it].get_op_evmdd(), predecessors);
/*if (minVal(predecessors) == std::numeric_limits<int>::max())
continue;*/
// predecessors.show(out, 3);
// TODO(speckd): add guard such that it only searches for states with lower
// i
// Not really necessary but if something goes wrong...
for (int c_i = 0; c_i < curClosedList; c_i++) {
MEDDLY::dd_edge tmp(forest);
MEDDLY::apply(INTERSECTIONMAX, successors, *closedLists[c_i], tmp);
// We need to add the cost to target and then check if it fits
MEDDLY::dd_edge costDummy(forest);
MEDDLY::apply(MEDDLY::PLUS, *g_operators[op_i].get_SDAC_cost(),
targetState, costDummy);
int cost_tmp = minVal(costDummy);
costDummy.set(-1, cost_tmp);
MEDDLY::apply(MEDDLY::PLUS, tmp, costDummy, costDummy);
// std::cout << minVal(costDummy) << ", " << costAfter << std::endl;
// Cost Fits
MEDDLY::apply(INTERSECTIONMAX, predecessors, *closedLists[c_i], tmp);
MEDDLY::apply(MEDDLY::PLUS, tmp, *g_operators[*it].get_SDAC_cost(), tmp);
// Fits!
// std::cout << "Cost after: " << costAfter << ", minval" << minVal(tmp)
// << std::endl;
if (minVal(costDummy) == costAfter) {
if (minVal(tmp) == costAfter) {
// tmp.show(out, 3);
MEDDLY::apply(MINSTATES, tmp, tmp);
// add cost to it
......@@ -92,12 +101,12 @@ Operator *AStarBwd::reconstructPlanStep(MEDDLY::dd_edge &targetState) {
MEDDLY::apply(INTERSECTIONMAX, tmp, *closedLists[c_i], targetState);
// create dummy op with correct cost
Operator *dummy = new Operator(g_operators[op_i].get_name(),
Operator *dummy = new Operator(g_operators[*it].get_name(),
costAfter - minVal(targetState));
dummy->set_cost_function(g_operators[op_i].get_SDAC_cost_function());
dummy->set_cost_function(g_operators[*it].get_SDAC_cost_function());
// targetState.show(out, 3);
// std::cout << "-----------------------" << std::endl;
// std::cout << "\n" << curClosedList << std::endl;
// std::cout << "----------------------"
// << std::endl;
curClosedList = c_i;
return dummy;
}
......
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