Commit b24c0f56 authored by Lars Esselink's avatar Lars Esselink
Browse files

- backup

parent 0f61a381
import java.io.File;
import java.io.FileNotFoundException;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Vector;
import java.util.*;
/*
......@@ -26,27 +24,62 @@ public class Algorithm {
private int N;
private int M;
private int W;
private final Pillar src = new Pillar(0,0, 0,0L);
private final Pillar src = new Pillar(0,0, 0);
private Pillar target;
private PriorityQueue<Pillar> queue;
private PriorityQueue<Pillar> queue = new PriorityQueue<>();
private HashSet<Pillar> visited = new HashSet<>();
private HashMap<Pillar, Long> distance = new HashMap<Pillar,Long>();
public void main(){
src.setCost(0L);
initiateVector();
makeEdges();
for(Pillar pillar : src.getAdj()){
System.out.println(pillar.getID());
}
algorithm();
for(Pillar pillar: distance.keySet()){
System.out.println(pillar.getID() + " : " + pillar.getCost());
}
}
public void algorithm(){
distance.put(src,0L);
queue.add(src);
while(!queue.isEmpty()){
Pillar pillar = queue.remove();
System.out.println("from pillar: " + pillar.getID());
visited.add(pillar);
for(Map.Entry<Pillar,Long> entry: pillar.getAdj().entrySet()){
System.out.println("working on: " + entry.getKey().getID());
System.out.println(entry.getValue() + " >= " + pillar.getCost() + " + " + entry.getValue());
if(entry.getValue() >= pillar.getCost() + entry.getValue() && pillar.getCost() != -1 ){
long cost = (pillar.getCost() + entry.getValue());
System.out.println(entry.getKey().getID() + " " + cost);
distance.put(entry.getKey(),cost);
entry.getKey().setCost((pillar.getCost() + entry.getValue()));
}
queue.add(entry.getKey());
}
}
}
public void makeEdges(){
......@@ -56,8 +89,8 @@ public class Algorithm {
Pillar pillar2 = pillars.get(j);
for(int i = 0; i < disks.size(); i++){
if(distancePoints(pillar1.getX(),pillar1.getY(),pillar2.getX(),pillar2.getY()) != 0 && distancePoints(pillar1.getX(),pillar1.getY(),pillar2.getX(),pillar2.getY()) <= (disks.get(i).getRadius() * 2)){
edges.add(new Edge(pillar1,pillar2,disks.get(i).getCost()));
pillar1.addAdj(pillar2);
// edges.add(new Edge(pillar1,pillar2,disks.get(i).getCost()));
pillar1.addAdj(pillar2, disks.get(i).getCost());
i = disks.size();
}
}
......@@ -75,7 +108,7 @@ public class Algorithm {
N = input.get(0).get(0);
M = input.get(0).get(1);
W = input.get(0).get(2);
target = new Pillar(0,W, -1,null);
target = new Pillar(0,W, -1);
System.out.println("N: " + N + " M: " + M + " W: " + W + "\n");
Disk tempDisk = null;
......@@ -87,7 +120,7 @@ public class Algorithm {
pillars.add(src);
Pillar tempPillar = null;
for(int i = 1; i < N + 1; i++){
tempPillar = new Pillar(input.get(i).get(0),input.get(i).get(1),i,null);
tempPillar = new Pillar(input.get(i).get(0),input.get(i).get(1),i);
pillars.add(tempPillar);
}
pillars.add(target);
......
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
public class Pillar implements Comparator<Pillar> {
public class Pillar implements Comparable<Pillar> {
private final int X;
private final int Y;
private Long Cost;
private Long Cost = -1L;
private final int ID;
private List<Pillar> adj = new ArrayList<>();
private HashMap<Pillar,Long> adj = new HashMap<Pillar,Long>();
public Pillar(int X, int Y, int ID, Long Cost){
public Pillar(int X, int Y, int ID){
this.X = X;
this.Y = Y;
this.ID = ID;
this.Cost = Cost;
}
public int getY(){
......@@ -26,13 +26,13 @@ public class Pillar implements Comparator<Pillar> {
}
public void setCost(Long cost){
this.Cost = cost;
// this.Cost = cost;
}
public void addAdj(Pillar adj){
this.adj.add(adj);
public void addAdj(Pillar adj, Long cost){
this.adj.put(adj,cost);
}
public List<Pillar> getAdj(){
public HashMap<Pillar,Long> getAdj(){
return adj;
}
......@@ -44,16 +44,20 @@ public class Pillar implements Comparator<Pillar> {
return ID;
}
@Override
public int compare(Pillar pillar1, Pillar pillar2){
if (pillar1.getCost() < pillar2.getCost())
return -1;
if (pillar1.getCost() > pillar2.getCost())
return 1;
// @Override
// public int compare(Pillar pillar1, Pillar pillar2){
//
// if (pillar1.getCost() < pillar2.getCost())
// return -1;
//
// if (pillar1.getCost() > pillar2.getCost())
// return 1;
//
// return 0;
// }
return 0;
@Override
public int compareTo(Pillar pillar) {
return Long.compare(this.getCost(), pillar.getCost());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment