Is there any library in matlab that provides the functionality of min priorityqueue
import java.util.PriorityQueue;
import java.util.*;
public class MyQueue {
  Comparator<Double> c;
  PriorityQueue<Double> PQ;
  public MyQueue() {
    c = new Comparator<Double>(){
            public int compare(Double o1, Double o2){
              if(o2 > o1) {
                return -1;
              } else if(o1 > o2) {
                return 1;
              } else {
                return 0;
              }
            }
        };
    PQ = new PriorityQueue<Double>(1000,c);
  }
  public void addElement(double d) {
    PQ.add(d);
  }
  public double removeElement() {
    return(PQ.remove());
  }
}
I have implemented this priorty queue in java. I can call it from matlab. However, I need to associate each cost with an index. I mean it's not only cost of the node that i need to store but also its index. How can I accomplish this. I need to pass the index from matlab
You can use Java's default PriorityQueue like so: 
>> q=java.util.PriorityQueue;
>> q.add({value,index});
This is available since Java ≥ 1.5, which is pre-bundled in all MATLAB releases since 7.0.4 (R14).
Otherwise, you can use the one from the file exchange, which you'll have to compile.
There's also a Simulink block for it, but I doubt that's what you're after.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With