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

- backup

parent 9bbce4fa
import java.io.File;
import java.io.FileNotFoundException;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Vector;
......@@ -25,8 +26,9 @@ public class Algorithm {
private int N;
private int M;
private int W;
private Pillar src = new Pillar(0,0,null);
private Pillar target = new Pillar(0,W, null);
private final Pillar src = new Pillar(0,0, 0,0L);
private Pillar target;
private PriorityQueue<Pillar> queue;
......@@ -35,19 +37,27 @@ public class Algorithm {
initiateVector();
makeEdges();
for(Edge edge : edges){
System.out.println(edge.toString()+ " = " + edge.getCost());
for(Pillar pillar : src.getAdj()){
System.out.println(pillar.getID());
}
}
public void algorithm(){
queue.add(src);
}
public void makeEdges(){
for(Pillar pillar1 : pillars){
for(Pillar pillar2: pillars){
for(int k = 0; k < pillars.size(); k++){
Pillar pillar1 = pillars.get(k);
for(int j = k; j < pillars.size(); j++){
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);
i = disks.size();
}
}
......@@ -65,6 +75,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);
System.out.println("N: " + N + " M: " + M + " W: " + W + "\n");
Disk tempDisk = null;
......@@ -73,11 +84,13 @@ public class Algorithm {
disks.add(tempDisk);
}
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),null);
tempPillar = new Pillar(input.get(i).get(0),input.get(i).get(1),i,null);
pillars.add(tempPillar);
}
pillars.add(target);
}
......
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
public class Pillar implements Comparator<Pillar> {
private final int X;
private final int Y;
private final Long Cost;
private Long Cost;
private final int ID;
private List<Pillar> adj = new ArrayList<>();
public Pillar(int X, int Y, Long Cost){
public Pillar(int X, int Y, int ID, Long Cost){
this.X = X;
this.Y = Y;
this.ID = ID;
this.Cost = Cost;
}
......@@ -20,10 +25,25 @@ public class Pillar implements Comparator<Pillar> {
return X;
}
public long getCost(){
public void setCost(Long cost){
this.Cost = cost;
}
public void addAdj(Pillar adj){
this.adj.add(adj);
}
public List<Pillar> getAdj(){
return adj;
}
public Long getCost(){
return Cost;
}
public int getID(){
return ID;
}
@Override
public int compare(Pillar pillar1, Pillar pillar2){
......
......@@ -4,11 +4,11 @@ public class main {
public static void main(String[] args){
long start = System.nanoTime();
double start = System.nanoTime();
alg.main();
long end = System.nanoTime();
long total = end - start;
System.out.println("runtime in ns: " + total);
double end = System.nanoTime();
double total = end - start;
System.out.println("runtime in seconds: " + (total/1000000000));
}
......
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