Re: PriorityQueue Enquiries
Would contains and remove do what you want?
Re: PriorityQueue Enquiries
Quote:
Originally Posted by
Norm
Would contains and remove do what you want?
I would like to get the Object N from the priority Queue and do a comparison with current object .. if current object contains lesser cost-path, it will replace the object N..
2 Object would have same attribute different path cost ...
Is it more like a travel using UCS ..
Re: PriorityQueue Enquiries
Can you write a small simple program that compiles and executes to show what you want to do?
Re: PriorityQueue Enquiries
Quote:
Originally Posted by
Norm
Can you write a small simple program that compiles and executes to show what you want to do?
My program is something like this.
I have an input files as follow
5 5
1 1
5 5
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
5 5 = indicates Grid Size
1 1 = indicates Start Location
5 5 = indicates Goal Location
The travel path will be replaced by *
The real answer should be
* 1 1 1 1
* 1 1 2 1
* 1 3 1 1
* 1 1 1 1
* * * * *
It would use priority queue to compare if terrain level is higher or same level using the following formula.
If Node(c,d) - Node(a,b) > 0 then
Path Cost = 1 + Node(c,d)[Terrain Level] - Node(a,b)[Terrain Level] + Parent Path Cost
The start goal will have 0 path cost.
It should travel by 4 direction in sequence, Up - Down - Left - Right
My output files as follow:-
* * * * *
1 1 1 2 *
1 1 3 1 *
1 1 1 1 *
1 1 1 1 *
So, what i suspect my program wrong is because i do not compare the path cost which contain the node.
Re: PriorityQueue Enquiries
sorry I meant a java program that compiles and executes to show what you want to do. You know, with classes and methods that execute.
Re: PriorityQueue Enquiries
Quote:
Originally Posted by
keat84
I would like to get the Object N from the priority Queue
A queue is a queue - get(int) works on a list. If you want to get the nth item based on a 'cost' you'll have to use Collections.sort on a list (or Arrays.sort on an array) and pass it a Comparator that uses your cost calculation (if it's not already your object's natural order).