Commit 052c7ac0 authored by Lars Esselink's avatar Lars Esselink
Browse files

- backup

parent bb839801
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
import java.util.stream.Collectors;
/*
......@@ -30,9 +29,7 @@ public class Algorithm {
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 List<Pair> pairs = new ArrayList<>();
private double maxDistance;
private double maxDistanceHalf;
private final List<Pair<Pillar, Disk>> pairs = new ArrayList<Pair<Pillar, Disk>>();
......@@ -43,8 +40,8 @@ public class Algorithm {
initiateVector();
makePairs();
for(Pair pair : getAdj(src,new Disk(0,0))){
Pillar pillar = (Pillar) pair.getKey();
for(Pair<Pillar, Disk> pair : getAdj(src,new Disk(0,0))){
Pillar pillar = pair.getKey();
System.out.println(pillar.getID());
}
// for(Pillar pillar: pillars){
......@@ -75,28 +72,31 @@ public class Algorithm {
public void algorithm(){
distance.put(new Pair<>(src,null),0L);
distance.put(new Pair<>(src,new Disk(0,0)),0L);
queue.add(src);
for(Pair pair:pairs){
for(Pair<Pillar, Disk> pair:pairs){
distance.put(new Pair<>(pair.getKey(),pair.getValue()), Long.MAX_VALUE);
}
Disk disk1 = new Disk(0,0);
src.setDisk(new Disk(0,0));
while(!queue.isEmpty()){
System.out.println(queue.size());
Pillar pillar1 = queue.remove();
Disk disk1 = pillar1.getDisk();
visited.add(pillar1);
for(Pair pair : getAdj(pillar1,disk1)){
Pillar pillar2 = (Pillar) pair.getKey();
Disk disk2 = (Disk) pair.getValue();
for(Pair<Pillar, Disk> pair : getAdj(pillar1,disk1)){
Pillar pillar2 = pair.getKey();
Disk disk2 = pair.getValue();
long tempCost = distance.get(pillar1) + disk2.getCost();
long tempCost = distance.get(new Pair<>(pillar1,disk1)) + disk2.getCost();
if((distance.get(pillar2) > tempCost)){
distance.put(pillar1,tempCost);
if((distance.get(new Pair<>(pillar2,disk2)) > tempCost)){
distance.put(new Pair<>(pillar1, disk1),tempCost);
}
queue.add(pillar2);
......@@ -108,7 +108,7 @@ public class Algorithm {
public List<Pair<Pillar,Disk>> getAdj(Pillar pillar, Disk disk){
List<Pair<Pillar,Disk>> temp = new ArrayList<>();
for(Map.Entry<Pillar,Disk> entry : pairs.entrySet()){
for(Pair<Pillar, Disk> entry : pairs){
Pillar pillarPair = entry.getKey();
Disk diskPair = entry.getValue();
......@@ -121,9 +121,9 @@ public class Algorithm {
}
public void makePairs (){
for(int i = 0; i < pillars.size();i++){
for(int j = 0; j < disks.size();j++){
pairs.put(pillars.get(i),disks.get(j));
for (Pillar pillar : pillars) {
for (Disk disk : disks) {
pairs.add(new Pair<>(pillar, disk));
}
}
}
......@@ -178,8 +178,6 @@ public class Algorithm {
tempDisk = new Disk(input.get(i).get(0),input.get(i).get(1));
disks.add(tempDisk);
}
maxDistance = (int) (disks.get(disks.size()-1).getRadius()*2);
maxDistanceHalf = (int) (disks.get(disks.size()-1).getRadius());
pillars.add(src);
Pillar tempPillar = null;
......
//import java.io.File;
//import java.io.FileNotFoundException;
//import java.util.*;
//
//
///*
//X_k = x coord for k'th pillar
//Y_k = y coord for k'th pillar
//R_i = Radius of the i'th disk
//C_i = Cost of the i'th disk
//
// */
//
//
//public class Algorithm1 {
//
// 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<>();
// private final HashSet<Edge> edges = new HashSet<>();
// private int N;
// private int M;
// private int W;
// 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 HashMap<Pillar, Long> distance = new HashMap<Pillar,Long>();
//
//
//
//
// public void main(){
// src.setCost(0L);
//
// initiateVector();
// makeEdges();
//
//
//
//
// 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();
// visited.add(pillar);
// Long cost = pillar.getCost();
//
// for(Map.Entry<Pair,Pair> entry: pillar.getAdj().entrySet()){
// Pillar tempPillar = (Pillar) entry.getKey().getKey();
// Long tempCost = tempPillar.getCost();
// Long edgeWeight = (Long) entry.getKey().getValue();
// Disk disk1 = (Disk) entry.getValue().getKey();
// Disk disk2 = (Disk) entry.getValue().getValue();
//
//
// if((tempCost > cost + edgeWeight)){
// distance.put(pillar,cost+edgeWeight);
// tempPillar.setCost(disk1.getCost() /*+ pillar.getCost()*/);
//
// }
// queue.add(tempPillar);
//
// }
//
// }
// }
//
// public void makeEdges(){
// 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);
// diskCheck(pillar1,pillar2);
// }
// }
// }
//
// public void diskCheck(Pillar pillar1, Pillar pillar2){
// Long lowestCost = Long.MAX_VALUE;
// Disk disk1 = null;
// Disk disk2 = null;
//
// for(int i = 0; i < disks.size(); i++){
// for(int j = i; j < disks.size(); j++){
// if(itselfCheck(pillar1,pillar2) && distanceCheck(pillar1,pillar2,disks.get(i),disks.get(j))){
// System.out.println("Checking for: " + pillar1.getID() + " and " + pillar2.getID()+ " : " + lowestCost + " > " + (disks.get(i).getCost()+disks.get(j).getCost()));
// if(pillar1.getID() != 0 && pillar2.getID() != 0 && pillar1.getID() != -1 && pillar2.getID() != -1 && (lowestCost > (disks.get(i).getCost()+disks.get(j).getCost()))){
// lowestCost = (disks.get(i).getCost()+disks.get(j).getCost());
// System.out.println("Lowestcost: " + lowestCost);
// disk1 = disks.get(i);
// disk2 = disks.get(j);
// } else if(lowestCost > disks.get(i).getCost() && ((pillar1.getID() == -1 || pillar2.getID() == -1) || (pillar1.getID() == 0 || pillar2.getID() == 0))){
// lowestCost = disks.get(i).getCost();
// System.out.println("lowestcost: " + lowestCost);
// disk1 = disks.get(i);
// }
// }
// }
//
// }
//
// if (lowestCost != Long.MAX_VALUE){
// pillar1.addAdj(pillar2, lowestCost,disk1,disk2);
// }
//
// }
//
// public boolean itselfCheck(Pillar pillar1, Pillar pillar2){
// return distancePoints(pillar1.getX(),pillar1.getY(),pillar2.getX(),pillar2.getY()) != 0;
// }
//
// public boolean distanceCheck(Pillar pillar1, Pillar pillar2, Disk disk1, Disk disk2){
// if(pillar1.getID() != 0 && pillar2.getID() != 0 && pillar1.getID() != -1 && pillar2.getID() != -1){
// return distancePoints(pillar1.getX(), pillar1.getY(), pillar2.getX(), pillar2.getY()) <= (disk1.getRadius() + disk2.getRadius());
// } else {
// return distancePoints(pillar1.getX(), pillar1.getY(), pillar2.getX(), pillar2.getY()) <= disk1.getRadius();
// }
// }
//
//
//
//
//
//
// public void initiateVector(){
// readFromFile();
//
// N = input.get(0).get(0);
// M = input.get(0).get(1);
// W = input.get(0).get(2);
// target = new Pillar(0,W, -1);
//
// Disk tempDisk = null;
// for(int i = N + 1; i <= N + M; i++){
// tempDisk = new Disk(input.get(i).get(0),input.get(i).get(1));
// 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),i);
// pillars.add(tempPillar);
// }
// pillars.add(target);
//
// }
//
// public void readFromFile(){
// File file = new File(fileName);
// Scanner sc;
// try {
// sc = new Scanner(file);
//
// while(sc.hasNextLine()){
//// System.out.print(sc.nextLine() + "\n");
// addToVector(sc.nextLine());
// }
// } catch (FileNotFoundException e) {
// e.printStackTrace();
// }
//
//
// }
//
// public double distancePoints(
// double x1,
// double y1,
// double x2,
// double y2) {
// return Math.sqrt((y2 - y1) * (y2 - y1) + (x2 - x1) * (x2 - x1));
// }
//
// public void addToVector(String line){
// String[] split = line.split("\\s+");
// Vector<Integer> temp = new Vector<Integer>();
// for(String strings : split){
// temp.add(Integer.parseInt(strings));
// }
//
// input.add(temp);
//
// }
//
//// 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());
// }
// }
//
//
//}
public class Pair<X, Y> {
private final X key;
private final Y value;
private final Pillar key;
private final Disk value;
public Pair(X key, Y value){
public Pair(Pillar key, Disk value){
this.key = key;
this.value = value;
}
public X getKey() {
public Pillar getKey() {
return key;
}
public Y getValue() {
public Disk getValue() {
return value;
}
public int hashCode() {
return (int) ((key.getID() << 16) + value.getRadius());
}
}
import java.util.HashMap;
public class Pillar1 implements Comparable<Pillar1> {
private final int X;
private final int Y;
private Long Cost = Long.MAX_VALUE;
private final int ID;
private HashMap<Pair, Pair> adj = new HashMap<>();
public Pillar1(int X, int Y, int ID){
this.X = X;
this.Y = Y;
this.ID = ID;
}
public int getY(){
return Y;
}
public int getX(){
return X;
}
public void setCost(Long cost){
this.Cost = cost;
}
public void addAdj(Pillar1 pillar, Long cost, Disk disk1, Disk disk2){
Pair<Pillar1,Long> pair1 = new Pair<>(pillar,cost);
Pair<Disk,Disk> pair2 = new Pair<>(disk1,disk2);
this.adj.put(pair1, pair2);
}
public HashMap<Pair,Pair> getAdj(){
return adj;
}
public Long getCost(){
return Cost;
}
public int getID(){
return ID;
}
@Override
public int compareTo(Pillar1 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