Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cv9;
- import java.util.PriorityQueue;
- import java.util.Vector;
- public class Cesta {
- private Graf graf;
- private Uzel lastNode = null;
- private Vector<Uzel> nodes = new Vector<Uzel>();
- private int cost;
- public Cesta(Graf graf) {
- super();
- this.graf = graf;
- }
- public void addNode(String nazevuzlu) {
- Uzel u = graf.getUzel(nazevuzlu);
- if (lastNode == null) {
- cost = 0;
- } else {
- cost += lastNode.getCost(u);
- }
- lastNode = u;
- nodes.add(u);
- }
- public int getCost() {
- return cost;
- }
- public void setCost(int cost) {
- this.cost = cost;
- }
- public boolean jeVCieli(String ciel) {
- if (lastNode == null){
- return false;
- } else {
- return ciel.equals(lastNode.getData());
- }
- }
- public Cesta kopirujCestuPridajUzel(String nazevuzlu) {
- Cesta kopia = new Cesta(graf);
- kopia.lastNode = lastNode;
- kopia.nodes.addAll(nodes);
- kopia.addNode(nazevuzlu);
- return kopia;
- }
- public Cesta getCesta(String odkial, String kam) {
- PriorityQueue<Cesta> prioFronta = new PriorityQueue<Cesta>();
- Cesta c = new Cesta(graf);
- c.addNode(odkial);
- prioFronta.add(c);
- while (!prioFronta.isEmpty()) {
- Cesta tmp = prioFronta.remove();
- if (tmp.jeVCieli(kam)) {
- return tmp;
- }
- for (Uzel u : tmp.getLast().getSousede()) {
- Cesta kopia = tmp.kopirujCestuPridajUzel(u.getData());
- String nazevuzlu = kopia.getLast().getData();
- System.out.println("Kopia: A-E-B" + nazevuzlu + " cost=" + kopia.getCost());
- prioFronta.add(kopia);
- }
- }
- return null;
- }
- /*public Uzel getLast() {
- // TODO Auto-generated method stub
- return null;
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement