Commit 57feac48 authored by Sumitra Corraya's avatar Sumitra Corraya

Update aStarFwd.cc

parent f7bb0341
......@@ -4,7 +4,10 @@
#include "aStarFwd.h"
#include "../image.h"
#include <algorithm>
#include <vector>
#include <random>
#include <iterator>
#include <chrono>
void AStarFwd::image(MEDDLY::dd_edge &stateSet, MEDDLY::dd_edge &transOp,
MEDDLY::dd_edge &res) {
MEDDLY::apply(MEDDLY::PLUS, stateSet, transOp, res);
......@@ -47,12 +50,22 @@ int AStarFwd::selectAnyState(MEDDLY::dd_edge &targetState) {
}
Operator *AStarFwd::reconstructPlanStep(MEDDLY::dd_edge &targetState) {
MEDDLY::FILE_output out(stdout);
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++) {
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[op_i].get_op_evmdd(), predecessors);
imageInv(targetState, *g_operators[*it].get_op_evmdd(), predecessors);
/*if (minVal(predecessors) == std::numeric_limits<int>::max())
continue;*/
// predecessors.show(out, 3);
......@@ -62,10 +75,8 @@ Operator *AStarFwd::reconstructPlanStep(MEDDLY::dd_edge &targetState) {
for (int c_i = 0; c_i < curClosedList; c_i++) {
MEDDLY::dd_edge tmp(forest);
MEDDLY::apply(INTERSECTIONMAX, predecessors, *closedLists[c_i], tmp);
MEDDLY::apply(MEDDLY::PLUS, tmp, *g_operators[op_i].get_SDAC_cost(), 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(tmp) == costAfter) {
// tmp.show(out, 3);
MEDDLY::apply(MINSTATES, tmp, tmp);
......@@ -74,11 +85,11 @@ Operator *AStarFwd::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::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