Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 104 additions & 1 deletion include/warthog/search/uds_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "search_metrics.h"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No header, no description of what is being implemented.

#include <warthog/io/log.h>
#include <warthog/util/template.h>

namespace warthog::search
{
Expand Down Expand Up @@ -133,7 +134,7 @@ enum class reopen_policy

// decide whether to renopen nodes already expanded (when their g-value
// can be improved). we handle the positive case via specialisation.
template<reopen_policy RO>
template<reopen_policy RP>
inline bool
reopen()
{
Expand All @@ -147,6 +148,108 @@ reopen<reopen_policy::yes>()
return true;
}

struct uds_default_traits
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No description of what the traits do?

{
// using node = std::tuple<>;
// using observer = std::tuple<>;
static constexpr admissibility_criteria ac = admissibility_criteria::any;
static constexpr feasibility_criteria fc
= feasibility_criteria::until_exhaustion;
static constexpr reopen_policy rp = reopen_policy::no;
};

template<
typename N = search_node, typename L = std::tuple<>,
admissibility_criteria AC = admissibility_criteria::any,
feasibility_criteria FC = feasibility_criteria::until_exhaustion,
reopen_policy RP = reopen_policy::no>
struct uds_traits
{
using node = N;
using observer = L;
static constexpr admissibility_criteria ac = AC;
static constexpr feasibility_criteria fc = FC;
static constexpr reopen_policy rp = RP;
};

namespace details
{

template<typename Traits>
struct uds_trait_node
{
using type = search_node;
};
template<typename Traits>
requires requires { typename Traits::node; }
struct uds_trait_node<Traits>
{
using type = typename Traits::node;
};

template<typename Traits>
struct uds_trait_observer
{
using type = search_node;
};
template<typename Traits>
requires requires { typename Traits::observer; }
struct uds_trait_observer<Traits>
{
using type = typename Traits::observer;
};

} // namespace details

template<typename Traits>
using uds_trait_node = typename details::uds_trait_node<Traits>::type;

template<typename Traits>
using uds_trait_observer = typename details::uds_trait_observer<Traits>::type;

template<typename Traits>
inline consteval admissibility_criteria
uds_trait_ac() noexcept
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a description. what does this do? (please add comments similar to reopen policy)

{
if constexpr(requires {
{
Traits::ac
} -> util::same_as_rmref<admissibility_criteria>;
})
{
return Traits::ac;
}
else { return admissibility_criteria::any; }
}

template<typename Traits>
inline consteval feasibility_criteria
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add comments to describe what this does

uds_trait_fc() noexcept
{
if constexpr(requires {
{
Traits::fc
} -> util::same_as_rmref<feasibility_criteria>;
})
{
return Traits::fc;
}
else { return feasibility_criteria::until_exhaustion; }
}

template<typename Traits>
inline consteval reopen_policy
uds_trait_rp() noexcept
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add comments to describe what this does

{
if constexpr(requires {
{ Traits::rp } -> util::same_as_rmref<reopen_policy>;
})
{
return Traits::rp;
}
else { return reopen_policy::no; }
}

} // namespace warthog::search

#endif // WARTHOG_SEARCH_UDS_TRAITS_H
51 changes: 36 additions & 15 deletions include/warthog/search/unidirectional_search.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,30 @@ namespace warthog::search
// (default: search for any solution, until OPEN is exhausted)
template<
typename H, typename E, typename Q = util::pqueue_min,
typename L = std::tuple<>,
admissibility_criteria AC = admissibility_criteria::any,
feasibility_criteria FC = feasibility_criteria::until_exhaustion,
reopen_policy RP = reopen_policy::no>
class unidirectional_search
typename Traits = uds_default_traits>
class unidirectional_search_full
{
public:
unidirectional_search(
using traits = Traits;
using search_node = uds_trait_node<Traits>;
using L = uds_trait_observer<Traits>;

static constexpr admissibility_criteria AC = uds_trait_ac<Traits>();
static constexpr feasibility_criteria FC = uds_trait_fc<Traits>();
static constexpr reopen_policy RP = uds_trait_rp<Traits>();

unidirectional_search_full(
H* heuristic, E* expander, Q* queue, L listeners = L{})
: heuristic_(heuristic), expander_(expander), open_(queue),
listeners_(listeners)
{ }
unidirectional_search_full(const unidirectional_search_full& other)
= delete;
~unidirectional_search_full() = default;

~unidirectional_search() { }
unidirectional_search_full&
operator=(const unidirectional_search_full& other)
= delete;

void
get_pathcost(problem_instance* pi, search_parameters* par, solution* sol)
Expand Down Expand Up @@ -138,14 +148,6 @@ class unidirectional_search
Q* open_;
[[no_unique_address]] L listeners_;

// no copy ctor
unidirectional_search(const unidirectional_search& other) { }
unidirectional_search&
operator=(const unidirectional_search& other)
{
return *this;
}

/**
* Initialise a new 'search_node' for the ongoing search given the parent
* node (@param current).
Expand Down Expand Up @@ -315,6 +317,25 @@ class unidirectional_search
}
};

// Keep for backward compatibility.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's not much point to backwards compatibility at this point. The only affected project is warthog-jps, which we maintain. Might as well fix both.

// Done as class instead of using to support user-defined deduction
template<
typename H, typename E, typename Q = util::pqueue_min,
typename L = std::tuple<>,
admissibility_criteria AC = admissibility_criteria::any,
feasibility_criteria FC = feasibility_criteria::until_exhaustion,
reopen_policy RP = reopen_policy::no>
class unidirectional_search
: public unidirectional_search_full<
H, E, Q, uds_traits<search_node, L, AC, FC, RP>>
{
public:
using unidirectional_search_full = unidirectional_search_full<
H, E, Q, uds_traits<search_node, L, AC, FC, RP>>;

using unidirectional_search_full::unidirectional_search_full;
};

template<
typename H, typename E, typename Q = util::pqueue_min,
typename L = std::tuple<>>
Expand Down
7 changes: 7 additions & 0 deletions include/warthog/util/template.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ choose_integer_sequence(auto value, TemplateFunc&& tfunc)
value, std::forward<TemplateFunc>(tfunc));
}

template<typename T, typename T2>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not clear what we're doing here. please add some comments

concept same_as_rmref
= std::same_as<std::remove_reference_t<T>, std::remove_reference_t<T2>>;
template<typename T, typename T2>
concept same_as_rmcvref
= std::same_as<std::remove_cvref_t<T>, std::remove_cvref_t<T2>>;

} // namespace warthog::util

#endif // WARTHOG_UTIL_CAST_H