How to select cost function in Commonroad Search?

Hi,

I have a question regarding the cost functions: I understand that for the benchmarking, different cost functions are used (e.g. JB1, SA1, etc). When using commonroad search (specifically, the jupyter notebook tutorial_commonroad-search.ipynb), where can I see which cost function is currently in use and possibly change it?

Thanks for your reply!

Greetings
Tim

I am not sure I understand your question right, Maybe look at function calc_heuristic_cost in commonroad-search/GSMP/motion_automata/automata/MotionPlanner_Astar.py . You can modify your heuristic cost in there. Does that answer your question?

Hi Tim,
In tutotial_commonroad-search.ipynb, if you check out the last cell you would see CommonRoadSolutionWriter() being called, and the last attribute is accepting the cost function of your choice. In the tutorial it is cost_function=CostFunction.JB1. You should change JB1 to something else.

Ok, so for the search algorithm, only our own cost function is used, and the cost functions provided by you do the benchmarking after each solution is uploaded, depending on which cost function is specified in the solution writer. Thanks for clarification!

Yes, exactly. The performance of your solution is evaluated based on the cost function that you select.

So wait, please tell me, why I can’t I just take the Costfunction from [1], implement it, use it as my heuristics function for GFB-Search and be done with it? As that heuristic would essentially be the “perfect” heuristic if it is the true cost function…? Is my reasoning wrong?

  1. https://gitlab.lrz.de/tum-cps/commonroad-cost-functions/blob/master/costFunctions_commonRoad.pdf
1 Like

Hi Country roads,

Yes, your reasoning is right. If you implement the cost function as your heuristic function, you should get better performance in the evaluation process. However, the implemented heuristic function does not guarantee that you find the solution in a reasonable time.
For example, if you use cost function JB1 (which only considers the time duration of the trajectory) as your heuristic function, the other components of the goal state (position, velocity, orientation, …) would then be ignored. In such a case, it might take hours to find a solution that reaches the goal state.
In general, your heuristic function should take the metrics of the selected cost function into consideration, as well as steer the search process towards the goal state.

I have a similar question as well. In the lecture, at each node it is always “total cost = real cost (e.g. SM1) + heuristic (our implementation)”. But here in the code, the total cost is always our own heuristic, and CostFunction.XX in CommonRoadSolutionWriter is just an enum. Did I do something wrong?

Hi, the cost function in the solution write is only used to evaluate your solution, it is not related to your search algorithm. You only specify the ID of cost function so that your solution will be evaluated accordingly on the server.

Are these cost functions somewhere implemented?

You can check the definitions of the functions here: https://gitlab.lrz.de/tum-cps/commonroad-cost-functions/-/blob/master/costFunctions_commonRoad.pdf

So there isn’t an already existing code for them. Would it be sufficient to write one of them as heuristic to pass 340 scenarios?

No, the evaluation code snippet is on our server and executed only to evaluate the cost of your solution trajectory. Simply writing them out does not help much, as you can’t really steer the search towards the goal with those cost functions.

I have been struggling about the heuristic function and no matter what I do, I can’t “steer the search towards the goal”. My functions have either an negative effect or no effect at all. The student example you gave is only solving circa 40 out of 500 scenarios. Can you share a good example that actually works? At this point I am out of ideas and don’t know how to continue. Would it help more to improve the search method instead of the heuristic? Because with heuristic I can’t get any results.

The provided astar/gbfs planner could already solve 320+ scenarios. Maybe you can take that as the start. I would suggest taking help from the route/reference path planned by the route planner, as it already tells you which route/path you should take to reach the goal.