I'm trying to solve a heuristic search in Mathematica 9. I get a list of succesor nodes called open with two nodes and a heuristic value, e.g.,
open={{node1,node2,H1},...,{node2,node1,Hi},...,{noden,noden,Hn}}
I need to select only when the two first elements are the same (no matter order) but where the heuristic is lower. Following the code that I used for sort the elements by the first item
Sort[open, #1[[1]] < #2[[1]] &]
I try to select cases when the same first and second numbers and the heuristic value where lower:
Select[open, #1[[1]]==#2[[1]] && #1[[2]] == #2[[2]] && #1[[3]]< #2[[3]] &]
But, returns {}
...
My list
open = {{1, 2, 3}, {2, 1, 5}, {1, 2, 2}, {3, 4, 5}, {4, 3, 2}};
Between {1, 2, 3}
, {1, 2, 2}
, and {2, 1, 5}
then choose {1, 2, 2}
that has the lower heuristic. And, between {3, 4, 5}
and {4, 3, 2}
then {4, 3, 2}
...
{{1, 2, 2},{4, 3, 2}}
Thanks,
Select
statement, you're using#2
, but this won't do anything. The function inSelect
is a function of 1 argument only and the#2
slot will never be filled. $\endgroup$