Commit c1179685 authored by lesselink's avatar lesselink
Browse files

-backup

parent 8135ed07
......@@ -15,8 +15,8 @@ C_i = Cost of the i'th disk
public class Algorithm {
// private final String fileName = "D:\\Documenten\\Google Drive\\Computing science\\Year 2\\Semester 1\\Algorithms and data structures (NWI-IBC027)\\project 1\\testcases\\01-sample.in";
private final String fileName = "/home/ldesselink/Documents/CS/AD/project1/rep/testcases/02-sample.in";
private final String fileName = "D:\\Documenten\\Google Drive\\Computing science\\Year 2\\Semester 1\\Algorithms and data structures (NWI-IBC027)\\project 1\\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<>();
......@@ -59,18 +59,18 @@ public class Algorithm {
while(!queue.isEmpty()){
Pillar pillar = queue.remove();
System.out.println("from pillar: " + pillar.getID());
System.out.println("from pillar " + pillar.getID() + " with cost: " + pillar.getCost());
visited.add(pillar);
for(Map.Entry<Pillar,Long> entry: pillar.getAdj().entrySet()){
System.out.println("working on: " + entry.getKey().getID());
System.out.println(entry.getValue() + " >= " + pillar.getCost() + " + " + entry.getValue());
System.out.println(entry.getKey().getCost() + " >= " + pillar.getCost() + " + " + entry.getValue());
if(entry.getValue() >= pillar.getCost() + entry.getValue() && pillar.getCost() != -1 ){
if(entry.getKey().getCost() > pillar.getCost() + entry.getValue()){
long cost = (pillar.getCost() + entry.getValue());
System.out.println(entry.getKey().getID() + " " + cost);
System.out.println("Pillar "+ entry.getKey().getID() + " gets cost: " + cost);
distance.put(entry.getKey(),cost);
entry.getKey().setCost((pillar.getCost() + entry.getValue()));
......@@ -88,7 +88,7 @@ public class Algorithm {
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)){
if(itselfCheck(pillar1,pillar2) && distanceCheck(pillar1,pillar2,disks.get(i))){
// edges.add(new Edge(pillar1,pillar2,disks.get(i).getCost()));
pillar1.addAdj(pillar2, disks.get(i).getCost());
i = disks.size();
......@@ -98,6 +98,18 @@ public class Algorithm {
}
}
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 disk){
if(pillar1.getID() != 0 && pillar2.getID() != 0 && pillar1.getID() != -1 && pillar2.getID() != -1){
return distancePoints(pillar1.getX(), pillar1.getY(), pillar2.getX(), pillar2.getY()) <= (disk.getRadius() * 2);
} else {
return distancePoints(pillar1.getX(), pillar1.getY(), pillar2.getX(), pillar2.getY()) <= disk.getRadius();
}
}
public void initiateVector(){
readFromFile();
......
......@@ -6,7 +6,7 @@ import java.util.List;
public class Pillar implements Comparable<Pillar> {
private final int X;
private final int Y;
private Long Cost = -1L;
private Long Cost = Long.MAX_VALUE;
private final int ID;
private HashMap<Pillar,Long> adj = new HashMap<Pillar,Long>();
......@@ -26,7 +26,7 @@ public class Pillar implements Comparable<Pillar> {
}
public void setCost(Long cost){
// this.Cost = cost;
this.Cost = cost;
}
public void addAdj(Pillar adj, Long cost){
......
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