Commit f89bfb28 authored by larsesselink's avatar larsesselink
Browse files

-backup

parent 052c7ac0
......@@ -15,8 +15,8 @@ C_i = Cost of the i'th disk
public class Algorithm {
// private final String fileName = "A:\\Documents\\Computing Science\\AD\\Project1\\testcases\\02-sample.in";
private final String fileName = "/home/ldesselink/Documents/CS/AD/project1/rep/testcases/02-sample.in";
private final String fileName = "A:\\Documents\\Computing Science\\AD\\Project1\\testcases\\02-sample.in";
// private final String fileName = "/home/ldesselink/Documents/CS/AD/project1/rep/testcases/02-sample.in";
private final Vector<Vector<Integer>> input = new Vector<>();
private final Vector<Pillar> pillars = new Vector<>();
private final Vector<Disk> disks = new Vector<>();
......@@ -27,8 +27,8 @@ public class Algorithm {
private final Pillar src = new Pillar(0,0, 0);
private Pillar target;
private final PriorityQueue<Pillar> queue = new PriorityQueue<>();
private final List<Pillar> visited = new ArrayList<>();
private final HashMap<Pair<Pillar,Disk>, Long> distance = new HashMap<>();
private final LinkedHashSet<Pillar> visited = new LinkedHashSet<>();
private final HashMap<Pillar, Pair<Disk,Long>> distance = new HashMap<>();
private final List<Pair<Pillar, Disk>> pairs = new ArrayList<Pair<Pillar, Disk>>();
......@@ -40,10 +40,11 @@ public class Algorithm {
initiateVector();
makePairs();
for(Pair<Pillar, Disk> pair : getAdj(src,new Disk(0,0))){
Pillar pillar = pair.getKey();
System.out.println(pillar.getID());
}
// for(Pair<Pillar, Disk> pair : getAdj(src,new Disk(0,0))){
// Pillar pillar = pair.getKey();
// System.out.println(pillar.getID() + " : " + pair.getValue().getRadius());
// }
// for(Pillar pillar: pillars){
// System.out.print("Pillar " + pillar.getID() + " has neighbour: ");
// for(Pillar pillar2 : pillar.getAdj().keySet()){
......@@ -61,7 +62,7 @@ public class Algorithm {
//// }
//
for(Pillar pillar: visited){
System.out.println(pillar.getID());
System.out.println(pillar.getID()+ " = " + distance.get(pillar).getValue());
}
......@@ -72,18 +73,18 @@ public class Algorithm {
public void algorithm(){
distance.put(new Pair<>(src,new Disk(0,0)),0L);
distance.put(src,new Pair<>(new Disk(0,0),0L));
queue.add(src);
for(Pair<Pillar, Disk> pair:pairs){
distance.put(new Pair<>(pair.getKey(),pair.getValue()), Long.MAX_VALUE);
distance.put(pair.getKey(),new Pair<>(pair.getValue(),Long.MAX_VALUE));
}
src.setDisk(new Disk(0,0));
while(!queue.isEmpty()){
System.out.println(queue.size());
// System.out.println(queue.size());
Pillar pillar1 = queue.remove();
Disk disk1 = pillar1.getDisk();
......@@ -93,12 +94,21 @@ public class Algorithm {
Pillar pillar2 = pair.getKey();
Disk disk2 = pair.getValue();
long tempCost = distance.get(new Pair<>(pillar1,disk1)) + disk2.getCost();
long tempCost = distance.get(pillar1).getKey().getCost() + disk2.getCost();
if((distance.get(new Pair<>(pillar2,disk2)) > tempCost)){
distance.put(new Pair<>(pillar1, disk1),tempCost);
// System.out.println("From pillar " + pillar1.getID() + " = " + pillar2.getID() + " : " + distance.get(pillar2).getValue() + " > " + tempCost);
if((distance.get(pillar2).getValue() > tempCost)){
distance.put(pillar2, new Pair<>(disk2,tempCost+distance.get(pillar1).getValue()));
pillar1.setDisk(disk1);
pillar2.setDisk(disk2);
}
if(!visited.contains(pillar2))
{
queue.add(pillar2);
}
}
......@@ -112,7 +122,10 @@ public class Algorithm {
Pillar pillarPair = entry.getKey();
Disk diskPair = entry.getValue();
if(distancePoints(pillar, pillarPair) < diskPair.getRadius() + disk.getRadius() && pillar != pillarPair){
// System.out.println("Checking " + pillar.getID() + " With " + pillarPair.getID());
// System.out.println("Doing: " + distancePoints(pillar, pillarPair) + " < " + diskPair.getRadius() + " + " + disk.getRadius() + " and " + (pillar != pillarPair));
if(distancePoints(pillar, pillarPair) <= diskPair.getRadius() + disk.getRadius() && pillar != pillarPair){
temp.add(new Pair<>(pillarPair,diskPair));
}
......@@ -121,9 +134,9 @@ public class Algorithm {
}
public void makePairs (){
for (Pillar pillar : pillars) {
for (int i = 1; i < pillars.size()-1; i++) {
for (Disk disk : disks) {
pairs.add(new Pair<>(pillar, disk));
pairs.add(new Pair<>(pillars.get(i), disk));
}
}
}
......@@ -219,11 +232,6 @@ public class Algorithm {
}
public void printVector(Vector<Pillar> temp){
for (Pillar tempPillars : temp) {
System.out.println(tempPillars.getX() + " " + tempPillars.getY());
}
}
}
public class Pair<X, Y> {
private final Pillar key;
private final Disk value;
private final X key;
private final Y value;
public Pair(Pillar key, Disk value){
public Pair(X key, Y value){
this.key = key;
this.value = value;
}
public Pillar getKey() {
public X getKey() {
return key;
}
public Disk getValue() {
public Y getValue() {
return value;
}
public int hashCode() {
return (int) ((key.getID() << 16) + value.getRadius());
}
}
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