Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue992 #246

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft

issue992 #246

wants to merge 6 commits into from

Conversation

ClemensBuechner
Copy link
Contributor

No description provided.

@remochristen remochristen force-pushed the issue992 branch 3 times, most recently from a088dc1 to 4982fc3 Compare February 7, 2025 14:47
@ClemensBuechner ClemensBuechner force-pushed the issue992 branch 2 times, most recently from d0f3880 to a5ea42f Compare February 11, 2025 13:32
Copy link
Contributor

@SimonDold SimonDold left a comment

Choose a reason for hiding this comment

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

I left a few comments, nothing big.
The biggest surprise to me was that the landmarkgraph is now treated as an iterable with the begin and end function (which is an indirection to the begin and end function of the nodes filed).

LGTM overall.

And it got a lot more pleasant to read, especially the parts that used single letter variable names :-)

using const_iterator =
std::vector<std::unique_ptr<LandmarkNode>>::const_iterator;
const const_iterator begin() const {
return nodes.cbegin();
Copy link
Contributor

@SimonDold SimonDold Feb 11, 2025

Choose a reason for hiding this comment

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

On use for cbegin is to communicate that a functor receiving the iterator does not change it.
With the function name LandmarkGraph::begin() this is not communicated anymore.

You are not using it this way and
LandmarkGraph::begin() is more readable than LandmarkGraph::cbegin() though.
So I am fine with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I understood Remo correctly, naming the iterator cbegin didn't work with the range-based for loops as intended, but naming it begin did. Do you think it would make sense to write a comment about this or is it fine as is?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is fine as is.

for (const auto &parent_and_edge : node->parents) {
const LandmarkNode *parent = parent_and_edge.first;
open.reserve(node->parents.size());
for (const auto &[parent, type] : node->parents) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
for (const auto &[parent, type] : node->parents) {
for (const auto &[parent, _] : node->parents) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you find the suggested option more readable? I know doing this is common practice in languages like Python because the symbol _ is actually interpreted differently than a variable name. However, in C++ both type and _ are (as of today) valid variable names and for the compiler it doesn't make a difference which one is used.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it communicates "we don't care about this part of the tuple".
I agree that it is a very pythonic suggestion and I am also fine to keep it as is.

const LandmarkNode *parent = parent_and_edge.first;
FactPair ancestor_atom = get_atom(ancestor->get_landmark());
groups[ancestor_atom.var].push_back(ancestor_atom.value);
for (const auto &[parent, type] : ancestor->parents) {
Copy link
Contributor

Choose a reason for hiding this comment

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

as above

}
unary_operators.reserve(num_unary_ops);
unary_operators.reserve(
compute_number_of_unary_operators(operators, axioms));

// Build unary operators for operators and axioms.
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment should be removed.

[precondition_fact.value]);

vector<Proposition *> precondition_propositions =
get_sorted_precondition_propositions(preconditions, effect);
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems a bit wasteful to sort the combination of preconditions+effectcondition for each effect.
Instead one could sort the preconditions outside the for loop and then sort the effectconditions for each effect and combine the two like mergesort does.

const FactPair pre_fact(pre.first, pre.second);
if (!lm_graph->contains_simple_landmark(pre_fact)) {
preconditions[disj_class].push_back(pre_fact);
const FactPair atom(pre.first, pre.second);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const FactPair atom(pre.first, pre.second);
const FactPair precondition(pre.first, pre.second);

}

LandmarkNode &LandmarkGraph::add_landmark(Landmark &&landmark_to_add) {
assert(landmark_to_add.is_conjunctive || all_of(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assert(landmark_to_add.is_conjunctive || all_of(
assert(landmark_to_add.is_conjunctive ||
all_of(landmark_to_add.atoms.begin(), landmark_to_add.atoms.end(),
 [&](const FactPair &atom) {return !contains_landmark(atom);}));

LandmarkNode &parent_node = *(parent.first);
parent_node.children.erase(node);
assert(parent_node.children.find(node) == parent_node.children.end());
for (const auto &[parent, type] : node->parents) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
for (const auto &[parent, type] : node->parents) {
for (const auto &[parent, _] : node->parents) {

LandmarkNode &child_node = *(child.first);
child_node.parents.erase(node);
assert(child_node.parents.find(node) == child_node.parents.end());
for (const auto &[child, type] : node->children) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
for (const auto &[child, type] : node->children) {
for (const auto &[child, _] : node->children) {

return n.get() == node;
});
const auto it =
find_if(nodes.begin(), nodes.end(),
Copy link
Contributor

Choose a reason for hiding this comment

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

In the header you introduce cbegin and cend.
Should this be used here too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants