Commit 32722ee9 authored by larsesselink's avatar larsesselink
Browse files

-backup

parent 2cd5d780
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
import java.util.stream.Collectors;
/*
......@@ -43,48 +44,73 @@ 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");
}
// 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());
}
visited = visited.stream().distinct().collect(Collectors.toList());
// for(Pillar pillar: distance.keySet()){
// System.out.println(pillar.getID() + " : " + pillar.getCost());
// }
// for(Pillar pillar: visited){
// System.out.println(pillar.getID());
// }
calculateCost();
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());
for(int i = 0; i < visited.size()-1; i++){
Pillar pillar1 = visited.get(i);
Pillar pillar2 = visited.get(i+1);
Disk disk1;
Disk disk2;
for(int k = 0; k < disks.size(); k++){
for(int l = k; l < disks.size(); l++){
disk1 = disks.get(k);
disk2 = disks.get(l);
long distanceDisk = (disk1.getRadius()+disk2.getRadius());
long distancePillars = (long) distancePoints(pillar1.getX(),pillar1.getY(),pillar2.getX(),pillar2.getY());
if((distancePillars <= distanceDisk) && (pillar1.getDisk().getRadius() < disk1.getRadius()) && checkIfSoT(pillar1,pillar2)){
System.out.println("Pillar " + pillar1.getID() + " gets disk with radius: " + disk1.getRadius());
// System.out.println("Pillar " + pillar2.getID() + " gets disk with radius: " + disk2.getRadius());
pillar1.setDisk(disk1);
pillar2.setDisk(disk2);
}else if ((distancePointToLine(pillar1,pillar2) >= disk1.getRadius()) && pillar1.getDisk().getRadius() < disk1.getRadius() && pillar2.getID() == -1){
System.out.println("Pillar " + pillar1.getID() + " gets disk with radius: " + disk1.getRadius());
pillar1.setDisk(disk1);
} else if ((distancePointToLine(pillar2,pillar1) >= disk2.getRadius()) && pillar1.getDisk().getRadius() < disk1.getRadius() && pillar1.getID() == 0){
System.out.println("Pillar " + pillar2.getID() + " gets disk with radius: " + disk2.getRadius());
pillar2.setDisk(disk2);
}
}
}
}
long cost = 0;
pillars.get(0).setDisk(new Disk(0,0));
pillars.get(pillars.size()-1).setDisk(new Disk(0,0));
for(Pillar pillar: visited){
System.out.println(pillar.getID() + " : " + pillar.getDisk().getCost());
cost += pillar.getDisk().getCost();
}
System.out.println(cost);
}
......
......@@ -5,7 +5,7 @@ public class Pillar implements Comparable<Pillar> {
private final int Y;
private Long Cost = Long.MAX_VALUE;
private final int ID;
private Disk disk;
private Disk disk = new Disk(0, Long.MAX_VALUE);
private HashMap<Pillar, Long> adj = new HashMap<>();
......
4 4 100
4 3 100
0 10
0 30
0 55
0 80
5 4
10 4
15 6
20 10
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