Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Ø
øving 9
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Awesome group
øving 9
Commits
a71a9a0c
Commit
a71a9a0c
authored
2 years ago
by
Pedro Pablo Cardona Arroyave
Browse files
Options
Downloads
Patches
Plain Diff
Alt mk1
parent
9beb0157
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Comparators.java
+15
-1
15 additions, 1 deletion
src/Comparators.java
src/Graph.java
+27
-0
27 additions, 0 deletions
src/Graph.java
src/Main.java
+1
-0
1 addition, 0 deletions
src/Main.java
with
43 additions
and
1 deletion
src/Comparators.java
+
15
−
1
View file @
a71a9a0c
...
@@ -6,5 +6,19 @@ public class Comparators {
...
@@ -6,5 +6,19 @@ public class Comparators {
return
Integer
.
compare
(
left
.
drivingTime
+
left
.
currentWeight
,
right
.
drivingTime
+
right
.
currentWeight
);
return
Integer
.
compare
(
left
.
drivingTime
+
left
.
currentWeight
,
right
.
drivingTime
+
right
.
currentWeight
);
}
}
}
}
//TODO: ALT comparator
static
class
AltComparator
implements
Comparator
<
Edge
>
{
int
[]
landMark
;
int
landMarkNumber
;
public
AltComparator
(
int
[]
landMarkValues
,
int
landMarkNumber
){
landMark
=
landMarkValues
;
this
.
landMarkNumber
=
landMarkNumber
;
}
@Override
public
int
compare
(
Edge
o1
,
Edge
o2
)
{
return
Integer
.
compare
(
o1
.
drivingTime
+
o1
.
currentWeight
+
getDelta
(
o1
.
destination
),
o2
.
drivingTime
+
o2
.
currentWeight
+
getDelta
(
o2
.
destination
));
}
private
int
getDelta
(
int
destination
){
return
landMark
[
destination
]
-
landMark
[
landMarkNumber
];
}
}
}
}
This diff is collapsed.
Click to expand it.
src/Graph.java
+
27
−
0
View file @
a71a9a0c
...
@@ -85,6 +85,32 @@ class Graph {
...
@@ -85,6 +85,32 @@ class Graph {
return
null
;
return
null
;
}
}
public
Edge
getShortestPathALT
(
int
startNumber
,
int
destinationNumber
)
throws
Exception
{
PriorityQueue
<
Edge
>
priorityQueue
=
new
PriorityQueue
<>(
new
Comparators
.
AltComparator
(
Utils
.
fileToArray
(
"testOslo.txt"
,
adjacencyList
.
size
()),
3430400
));
int
nodeSize
=
adjacencyList
.
size
();
int
[]
pathWeight
=
new
int
[
nodeSize
];
Arrays
.
fill
(
pathWeight
,
Integer
.
MAX_VALUE
);
pathWeight
[
startNumber
]
=
0
;
priorityQueue
.
addAll
(
adjacencyList
.
get
(
startNumber
));
while
(!
priorityQueue
.
isEmpty
())
{
Edge
nextEdge
=
priorityQueue
.
poll
();
int
nextNode
=
nextEdge
.
getDestination
();
int
start
=
nextEdge
.
getStart
();
int
currentSum
=
pathWeight
[
start
]
+
nextEdge
.
getDrivingTime
();
if
(
currentSum
<
pathWeight
[
nextNode
])
{
pathWeight
[
nextNode
]
=
currentSum
;
for
(
Edge
edge
:
adjacencyList
.
get
(
nextNode
))
{
edge
.
setCurrentWeight
(
pathWeight
[
start
]);
priorityQueue
.
add
(
edge
);
edge
.
setPreviousEdge
(
nextEdge
);
}
priorityQueue
.
addAll
(
adjacencyList
.
get
(
nextNode
));
}
if
(
nextNode
==
destinationNumber
)
return
nextEdge
;
}
return
null
;
}
public
Node
[]
getListOfPlaces
(
int
startNumber
,
byte
typeNumber
,
byte
numberPlaces
)
{
public
Node
[]
getListOfPlaces
(
int
startNumber
,
byte
typeNumber
,
byte
numberPlaces
)
{
PriorityQueue
<
Edge
>
priorityQueue
=
new
PriorityQueue
<>();
PriorityQueue
<
Edge
>
priorityQueue
=
new
PriorityQueue
<>();
Node
[]
listOfPlaces
=
new
Node
[
numberPlaces
];
Node
[]
listOfPlaces
=
new
Node
[
numberPlaces
];
...
@@ -119,6 +145,7 @@ class Graph {
...
@@ -119,6 +145,7 @@ class Graph {
return
listOfPlaces
;
return
listOfPlaces
;
}
}
public
int
[]
fromLandmark
(
int
landMark
)
{
public
int
[]
fromLandmark
(
int
landMark
)
{
PriorityQueue
<
Edge
>
priorityQueue
=
new
PriorityQueue
<>();
PriorityQueue
<
Edge
>
priorityQueue
=
new
PriorityQueue
<>();
int
nodeSize
=
adjacencyList
.
size
();
int
nodeSize
=
adjacencyList
.
size
();
...
...
This diff is collapsed.
Click to expand it.
src/Main.java
+
1
−
0
View file @
a71a9a0c
...
@@ -82,6 +82,7 @@ class ALTEdge implements Comparable<ALTEdge>{
...
@@ -82,6 +82,7 @@ class ALTEdge implements Comparable<ALTEdge>{
public
int
compareTo
(
ALTEdge
o
)
{
public
int
compareTo
(
ALTEdge
o
)
{
return
Integer
.
compare
(
drivingTime
+
currentWeight
+
getDelta
(),
o
.
drivingTime
+
o
.
currentWeight
+
o
.
getDelta
());
return
Integer
.
compare
(
drivingTime
+
currentWeight
+
getDelta
(),
o
.
drivingTime
+
o
.
currentWeight
+
o
.
getDelta
());
}
}
}
}
class
ALTGraph
{
class
ALTGraph
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment