Commit 9bbce4fa authored by Lars Esselink's avatar Lars Esselink
Browse files

- backup

parent 0274b222
...@@ -17,7 +17,7 @@ C_i = Cost of the i'th disk ...@@ -17,7 +17,7 @@ C_i = Cost of the i'th disk
public class Algorithm { 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 = "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/01-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<Vector<Integer>> input = new Vector<>();
private final Vector<Pillar> pillars = new Vector<>(); private final Vector<Pillar> pillars = new Vector<>();
private final Vector<Disk> disks = new Vector<>(); private final Vector<Disk> disks = new Vector<>();
...@@ -25,12 +25,19 @@ public class Algorithm { ...@@ -25,12 +25,19 @@ public class Algorithm {
private int N; private int N;
private int M; private int M;
private int W; private int W;
private Pillar src = new Pillar(0,0,null);
private Pillar target = new Pillar(0,W, null);
public void main(){ public void main(){
initiateVector(); initiateVector();
makeEdges();
for(Edge edge : edges){
System.out.println(edge.toString()+ " = " + edge.getCost());
}
} }
...@@ -38,9 +45,10 @@ public class Algorithm { ...@@ -38,9 +45,10 @@ public class Algorithm {
public void makeEdges(){ public void makeEdges(){
for(Pillar pillar1 : pillars){ for(Pillar pillar1 : pillars){
for(Pillar pillar2: pillars){ for(Pillar pillar2: pillars){
for(Disk disk: disks){ for(int i = 0; i < disks.size(); i++){
if(distancePoints(pillar1.getX(),pillar1.getY(),pillar2.getX(),pillar2.getY()) != 0){ 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)){
edges.add(new Edge(pillar1,pillar2,disks.get(i).getCost()));
i = disks.size();
} }
} }
} }
...@@ -67,7 +75,7 @@ public class Algorithm { ...@@ -67,7 +75,7 @@ public class Algorithm {
Pillar tempPillar = null; Pillar tempPillar = null;
for(int i = 1; i < N + 1; i++){ for(int i = 1; i < N + 1; i++){
tempPillar = new Pillar(input.get(i).get(0),input.get(i).get(1)); tempPillar = new Pillar(input.get(i).get(0),input.get(i).get(1),null);
pillars.add(tempPillar); pillars.add(tempPillar);
} }
......
import java.util.List;
public class Dijkstra {
private Long dist[];
List<List<Pillar>> adjacent;
public void dijkstraAlg(List<List<Pillar>> adjacent, long src){
this.adjacent = adjacent;
}
}
public class Edge { import java.util.Comparator;
public class Edge implements Comparator<Edge> {
private final Pillar pillar1; private final Pillar pillar1;
private final Pillar pillar2; private final Pillar pillar2;
private final long cost; private final long cost;
...@@ -10,6 +12,7 @@ public class Edge { ...@@ -10,6 +12,7 @@ public class Edge {
} }
public Pillar getPillar1() { public Pillar getPillar1() {
return pillar1; return pillar1;
} }
...@@ -21,4 +24,23 @@ public class Edge { ...@@ -21,4 +24,23 @@ public class Edge {
public long getCost() { public long getCost() {
return cost; return cost;
} }
public double distancePoints(double x1, double y1, double x2, double y2) {
return Math.sqrt((y2 - y1) * (y2 - y1) + (x2 - x1) * (x2 - x1));
}
@Override
public int compare(Edge o1, Edge o2) {
// if(distancePoints( )){
//
// } else if(){
//
// }
return 0;
}
@Override
public String toString(){
return ("(" + "(" + pillar1.getX() + "," + pillar1.getY() + ")" + "," + "(" + pillar2.getX() +"," + pillar2.getY() + ")" + ")");
}
} }
public class Pillar { import java.util.Comparator;
public class Pillar implements Comparator<Pillar> {
private final int X; private final int X;
private final int Y; private final int Y;
private final Long Cost;
public Pillar(int X, int Y){ public Pillar(int X, int Y, Long Cost){
this.X = X; this.X = X;
this.Y = Y; this.Y = Y;
this.Cost = Cost;
} }
public int getY(){ public int getY(){
...@@ -15,4 +20,20 @@ public class Pillar { ...@@ -15,4 +20,20 @@ public class Pillar {
return X; return X;
} }
public long getCost(){
return Cost;
}
@Override
public int compare(Pillar pillar1, Pillar pillar2){
if (pillar1.getCost() < pillar2.getCost())
return -1;
if (pillar1.getCost() > pillar2.getCost())
return 1;
return 0;
}
} }
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