All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.kit.ifv.mobitopp.routing.util.SimplePQ Maven / Gradle / Ivy

Go to download

mobiTopp (http://mobitopp.ifv.kit.edu/) is an agent-based travel demand model developed at the Institute for transport studies at the Karlsruhe Institute of Technology (http://www.ifv.kit.edu/english/index.php). Publications about mobiTopp can be found on the project site (http://mobitopp.ifv.kit.edu/28.php).

The newest version!
package edu.kit.ifv.mobitopp.routing.util;

import java.util.HashMap;

public class SimplePQ
	implements PriorityQueue {

	private HashMap data = new HashMap();


	public SimplePQ createNew() {
		return new SimplePQ();
	}


	public void clear() {

		data = new HashMap();
	}


	public void add(T object, Float priority) {

		data.put(object, priority);
	}

	public T minElement() {


		Float min_prio = Float.MAX_VALUE;
		T min = null;

		for (T tmp : data.keySet()) {

			Float prio = data.get(tmp);

			if (prio < min_prio) {

				min_prio = prio;
				min = tmp;
			}
		}

		return min;
	}
	
	public Float minPriority() {

		return data.get(minElement());
	}

	public void decreaseKey(T object, Float priority) {

		data.put(object, priority);
	}


	public T deleteMin() {

		T object = minElement();

		data.remove(object);

		return object;
	}

	public boolean isEmpty() {
		return data.isEmpty();
	}

	public boolean contains(T object) {
		return data.containsKey(object);
	}

	public Float priority(T object) {
		return data.get(object);
	}

	public int size() {
		return data.size();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy