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

removing goals from KB #325

Open
Ogusch opened this issue Feb 15, 2023 · 1 comment
Open

removing goals from KB #325

Ogusch opened this issue Feb 15, 2023 · 1 comment

Comments

@Ogusch
Copy link

Ogusch commented Feb 15, 2023

Hello,

I have written a coordinator that checks the KB predicates. Depending on the state, the target should be changed. However, I am not able to remove the current targets. E.g.

Initial Problem.pddl

(:goal (and
    (= (n_drinks tableb1) 2)
    (= (n_drinks tableb2) 1)
))

I want followig:

(:goal (and
))

Snippet of function, which should remove goals:

    print("___main_executor___: remove_goal")
    
    sps = rospy.ServiceProxy('/rosplan_knowledge_base/state/goals', GetAttributeService)
    goals = {}
    
    gas = GetAttributeServiceRequest()
    gas.predicate_name = 'n_drinks'
    facts = sps(gas)
    for k in facts.attributes:
        table = k.ineq.LHS.tokens[0].function.typed_parameters[0].value
        amount = k.ineq.RHS.tokens[0].constant
        goals[table] = amount
        
    
    kus = KnowledgeUpdateServiceRequest()
    # REMOVE_GOAL=3 https://kcl-planning.github.io/ROSPlan//tutorials/tutorial_08
    kus.update_type = 3

    kus.knowledge.knowledge_type = 2
    kus.knowledge.attribute_name = 'n_drinks'
    
    for key,value in goals.items():
        kv = KeyValue()
        kv.key = key
        kv.value = value
        string_goal = "(= (n_drinks " + kv.key + ") " + str(int(kv.value)) +")"
        print("___main_executor___: remove_goal: remove goal " + string_goal)
        kus.knowledge.values.append(kv)
        kus.knowledge.values.append(string_goal)
        kuc = rospy.ServiceProxy('/rosplan_knowledge_base/update', KnowledgeUpdateService)

The problem instance is getting overwritten. Only the goal does not change.

@gerardcanal
Copy link
Contributor

Hi Ogusch,
I believe this is because you are not specifying the values of the kus.knowledge to be removed (that is, the parameters of n_drinks). Here:

for(size_t i=0;i<a.values.size();i++) {
it checks that the value is the same, and this is used by remove goal (which, in the case of a function, it checks as if it was a fact, so it only checks for the function name and parameters to be equal).

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

No branches or pull requests

2 participants