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
f89bfb28
Commit
f89bfb28
authored
Nov 19, 2021
by
larsesselink
Browse files
-backup
parent
052c7ac0
Changes
4
Hide whitespace changes
Inline
Side-by-side
out/production/program/Algorithm.class
View file @
f89bfb28
No preview for this file type
out/production/program/Pair.class
View file @
f89bfb28
No preview for this file type
src/Algorithm.java
View file @
f89bfb28
...
...
@@ -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
Li
s
t
<
Pillar
>
visited
=
new
ArrayLis
t
<>();
private
final
HashMap
<
Pair
<
Pillar
,
Disk
>,
Long
>
distance
=
new
HashMap
<>();
private
final
Li
nkedHashSe
t
<
Pillar
>
visited
=
new
LinkedHashSe
t
<>();
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
();
// 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
((
distance
.
get
(
new
Pair
<>(
pillar2
,
disk2
))
>
tempCost
)){
distance
.
put
(
new
Pair
<>(
pillar1
,
disk1
),
tempCost
);
if
(!
visited
.
contains
(
pillar2
))
{
queue
.
add
(
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
<>(
pillar
s
.
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
());
}
}
}
src/Pair.java
View file @
f89bfb28
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
());
}
}
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