Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Lars Esselink
AD project 1
Commits
9bbce4fa
Commit
9bbce4fa
authored
Nov 11, 2021
by
Lars Esselink
Browse files
- backup
parent
0274b222
Changes
5
Hide whitespace changes
Inline
Side-by-side
out/production/program/Algorithm.class
View file @
9bbce4fa
No preview for this file type
src/Algorithm.java
View file @
9bbce4fa
...
...
@@ -17,7 +17,7 @@ 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/0
1
-sample.in"
;
private
final
String
fileName
=
"/home/ldesselink/Documents/CS/AD/project1/rep/testcases/0
2
-sample.in"
;
private
final
Vector
<
Vector
<
Integer
>>
input
=
new
Vector
<>();
private
final
Vector
<
Pillar
>
pillars
=
new
Vector
<>();
private
final
Vector
<
Disk
>
disks
=
new
Vector
<>();
...
...
@@ -25,12 +25,19 @@ public class Algorithm {
private
int
N
;
private
int
M
;
private
int
W
;
private
Pillar
src
=
new
Pillar
(
0
,
0
,
null
);
private
Pillar
target
=
new
Pillar
(
0
,
W
,
null
);
public
void
main
(){
initiateVector
();
makeEdges
();
for
(
Edge
edge
:
edges
){
System
.
out
.
println
(
edge
.
toString
()+
" = "
+
edge
.
getCost
());
}
}
...
...
@@ -38,9 +45,10 @@ public class Algorithm {
public
void
makeEdges
(){
for
(
Pillar
pillar1
:
pillars
){
for
(
Pillar
pillar2:
pillars
){
for
(
Disk
disk:
disks
){
if
(
distancePoints
(
pillar1
.
getX
(),
pillar1
.
getY
(),
pillar2
.
getX
(),
pillar2
.
getY
())
!=
0
){
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
)){
edges
.
add
(
new
Edge
(
pillar1
,
pillar2
,
disks
.
get
(
i
).
getCost
()));
i
=
disks
.
size
();
}
}
}
...
...
@@ -67,7 +75,7 @@ public class Algorithm {
Pillar
tempPillar
=
null
;
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
);
}
...
...
src/Dijkstra.java
0 → 100644
View file @
9bbce4fa
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
;
}
}
src/Edge.java
View file @
9bbce4fa
public
class
Edge
{
import
java.util.Comparator
;
public
class
Edge
implements
Comparator
<
Edge
>
{
private
final
Pillar
pillar1
;
private
final
Pillar
pillar2
;
private
final
long
cost
;
...
...
@@ -10,6 +12,7 @@ public class Edge {
}
public
Pillar
getPillar1
()
{
return
pillar1
;
}
...
...
@@ -21,4 +24,23 @@ public class Edge {
public
long
getCost
()
{
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
()
+
")"
+
")"
);
}
}
src/Pillar.java
View file @
9bbce4fa
public
class
Pillar
{
import
java.util.Comparator
;
public
class
Pillar
implements
Comparator
<
Pillar
>
{
private
final
int
X
;
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
.
Y
=
Y
;
this
.
Cost
=
Cost
;
}
public
int
getY
(){
...
...
@@ -15,4 +20,20 @@ public class Pillar {
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
;
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment