Commit 2cd5d780 authored by larsesselink's avatar larsesselink
Browse files

-backup

parent 1e6bf50f
......@@ -27,9 +27,10 @@ public class Algorithm {
private final Pillar src = new Pillar(0,0, 0);
private Pillar target;
private PriorityQueue<Pillar> queue = new PriorityQueue<>();
private HashSet<Pillar> visited = new HashSet<>();
private List<Pillar> visited = new ArrayList<>();
private HashMap<Pillar, Long> distance = new HashMap<Pillar,Long>();
private Long maxDistance;
private double maxDistance;
private double maxDistanceHalf;
......@@ -42,12 +43,49 @@ public class Algorithm {
for(Pillar pillar: pillars){
System.out.print("Pillar " + pillar.getID() + " has neighbour: ");
for(Pillar pillar2 : pillar.getAdj().keySet()){
System.out.print(pillar2.getID() + " ");
}
System.out.print("\n");
}
algorithm();
for(Pillar pillar: distance.keySet()){
System.out.println(pillar.getID() + " : " + pillar.getCost());
}
for(Pillar pillar: visited){
System.out.println(pillar.getID());
}
// calculateCost();
}
public void calculateCost(){
long cost = 0;
for(int i = 1; i < visited.size(); i++){
Pillar pillar1 = visited.get(i);
for(int j = i; j < visited.size(); j++){
Pillar pillar2 = visited.get(j);
Disk disk1;
Disk disk2;
for(int k = 0; k < disks.size(); k++){
for(int l = k; k < disks.size(); l++){
disk1 = disks.get(k);
disk2 = disks.get(l);
Long distance = (disk1.getRadius()+disk2.getRadius());
}
}
}
}
System.out.println(cost);
}
public void algorithm(){
......@@ -66,6 +104,7 @@ public class Algorithm {
Long edgeWeight = entry.getValue();
System.out.println("Cost: " + cost + " edgeweight: " + edgeWeight);
if((pillar2.getCost() > cost + edgeWeight)){
distance.put(pillar1,cost+edgeWeight);
pillar2.setCost(cost + edgeWeight);
......@@ -83,27 +122,26 @@ public class Algorithm {
Pillar pillar1 = pillars.get(k);
for(int j = k; j < pillars.size(); j++){
Pillar pillar2 = pillars.get(j);
if(itselfCheck(pillar1,pillar2) && distanceCheck(pillar1,pillar2)){
if(!itselfCheck(pillar1,pillar2) && distanceCheck(pillar1,pillar2) && checkIfSoT(pillar1,pillar2)){
pillar1.addAdj(pillar2, (long) distancePoints(pillar1.getX(), pillar1.getY(), pillar2.getX(), pillar2.getY()));
} else if (!itselfCheck(pillar1,pillar2) && pillar1.getID() == 0 && distanceCheck(pillar1,pillar2)) {
pillar1.addAdj(pillar2, distancePointToLine(pillar2, pillar1));
} else if (!itselfCheck(pillar1,pillar2) && distanceCheck(pillar1,pillar2)){
pillar1.addAdj(pillar2, distancePointToLine(pillar1,pillar2));
}
}
}
}
public boolean itselfCheck(Pillar pillar1, Pillar pillar2){
return distancePoints(pillar1.getX(),pillar1.getY(),pillar2.getX(),pillar2.getY()) != 0;
return pillar1 == pillar2;
}
public boolean distanceCheck(Pillar pillar1, Pillar pillar2){
if(pillar1.getID() != 0 && pillar2.getID() != 0 && pillar1.getID() != -1 && pillar2.getID() != -1){
return distancePoints(pillar1.getX(), pillar1.getY(), pillar2.getX(), pillar2.getY()) <= maxDistance;
} else {
if(checkIfSoT(pillar1,pillar2)){
return distancePoints(pillar1.getX(), pillar1.getY(), pillar2.getX(), pillar2.getY()) <= maxDistance;
} else{
return distancePoints(pillar1.getX(), pillar1.getY(), pillar2.getX(), pillar2.getY()) <= maxDistanceHalf;
}
}
......@@ -112,11 +150,22 @@ public class Algorithm {
return (long) Math.sqrt((y2 - y1) * (y2 - y1) + (x2 - x1) * (x2 - x1));
}
public Long distancePointToLine(Pillar pillar1, int line){
public Long distancePointToLine(Pillar pillar1, Pillar pillar2){
int x1 = pillar1.getX();
int y1 = pillar1.getY();
int x2 = pillar1.getX();
int y2;
if(pillar2.getID() == 0){
y2 = 0;
} else {
y2 = W;
}
return (long) Math.sqrt((y2 - y1) * (y2 - y1) + (x2 - x1) * (x2 - x1));
}
return 0L;
public Boolean checkIfSoT(Pillar pillar1, Pillar pillar2){
return pillar1.getID() != 0 && pillar2.getID() != 0 && pillar1.getID() != -1 && pillar2.getID() != -1 ;
}
......@@ -133,7 +182,8 @@ public class Algorithm {
tempDisk = new Disk(input.get(i).get(0),input.get(i).get(1));
disks.add(tempDisk);
}
maxDistance = disks.get(disks.size()-1).getRadius()*2;
maxDistance = (int) (disks.get(disks.size()-1).getRadius()*2);
maxDistanceHalf = (int) (disks.get(disks.size()-1).getRadius());
pillars.add(src);
Pillar tempPillar = null;
......@@ -175,14 +225,6 @@ public class Algorithm {
}
// public void printVector(Vector<Vector<Integer>> temp){
// for (Vector<Integer> tempVector : temp) {
// for (Integer integer : tempVector) {
// System.out.println(integer);
// }
// }
// }
public void printVector(Vector<Pillar> temp){
for (Pillar tempPillars : temp) {
System.out.println(tempPillars.getX() + " " + tempPillars.getY());
......
Supports Markdown
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