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
94948b08
Commit
94948b08
authored
2 years ago
by
Pedro Pablo Cardona Arroyave
Browse files
Options
Downloads
Patches
Plain Diff
method that returns list of places is implemented
parent
bf00452e
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Task9.java
+37
-8
37 additions, 8 deletions
src/Task9.java
with
37 additions
and
8 deletions
src/Task9.java
+
37
−
8
View file @
94948b08
...
...
@@ -182,18 +182,18 @@ class Graph{
System
.
out
.
println
(
sb
.
toString
());
}
/*
private void setTypes(int nodeNumber,int typeValue, String name){
private
void
setTypes
(
int
nodeNumber
,
int
typeValue
,
String
name
){
Node
node
=
this
.
getNode
(
nodeNumber
);
if((typeValue&1) ==1) node.setType(
"Place name"
);
if((typeValue&2) == 2) node.setType(
"Gas station"
);
if((typeValue&4) == 4) node.setType(
"Charge station"
);
if((typeValue&8) == 8) node.setType(
"Eating place"
);
if((typeValue&16) == 16) node.setType(
"Drinking place"
);
if((typeValue&32) == 32) node.setType(
"Accommodation"
);
if
((
typeValue
&
1
)
==
1
)
node
.
setType
(
(
short
)
1
);
if
((
typeValue
&
2
)
==
2
)
node
.
setType
(
(
short
)
2
);
if
((
typeValue
&
4
)
==
4
)
node
.
setType
(
(
short
)
4
);
if
((
typeValue
&
8
)
==
8
)
node
.
setType
(
(
short
)
8
);
if
((
typeValue
&
16
)
==
16
)
node
.
setType
(
(
short
)
16
);
if
((
typeValue
&
32
)
==
32
)
node
.
setType
(
(
short
)
32
);
node
.
setName
(
name
);
}
*/
}
public
int
getNumberOfNodes
(){
return
nodes
.
size
();
...
...
@@ -235,6 +235,35 @@ class Dijkstra{
}
return
pathToNodes
[
destinationNumber
];
}
public
static
ListOfPlaces
getListOfPlaces
(
Graph
graph
,
int
startNumber
,
int
numberOfPlaces
,
short
type
){
PriorityQueue
<
Edge
>
priorityQueue
=
new
PriorityQueue
<>();
ListOfPlaces
listOfPlaces
=
new
ListOfPlaces
(
numberOfPlaces
);
int
[]
pathWeight
=
new
int
[
graph
.
getNumberOfNodes
()];
Arrays
.
fill
(
pathWeight
,
Integer
.
MAX_VALUE
);
List
<
Edge
>[]
pathToNodes
=
new
List
[
graph
.
getNumberOfNodes
()];
pathWeight
[
startNumber
]
=
0
;
Arrays
.
fill
(
pathToNodes
,
new
ArrayList
<>());
priorityQueue
.
addAll
(
graph
.
getAllEdgesFromNode
(
startNumber
));
while
(!
priorityQueue
.
isEmpty
()){
Edge
nextEdge
=
priorityQueue
.
poll
();
int
nextNode
=
nextEdge
.
destination
();
int
currentSum
=
pathWeight
[
nextEdge
.
start
()]
+
nextEdge
.
drivingTime
();
if
(
currentSum
<
pathWeight
[
nextNode
]){
pathWeight
[
nextNode
]
=
currentSum
;
pathToNodes
[
nextNode
]
=
new
ArrayList
<>(
pathToNodes
[
nextEdge
.
start
()]);
pathToNodes
[
nextNode
].
add
(
nextEdge
);
priorityQueue
.
addAll
(
graph
.
getAllEdgesFromNode
(
nextNode
));
Node
node
=
graph
.
getNode
(
nextNode
);
if
(
node
.
getName
()
!=
null
){
if
(
node
.
isTypeOf
(
type
)){
listOfPlaces
.
addPlace
(
node
,
currentSum
);
}
}
}
}
return
listOfPlaces
;
}
/*public static List<Edge> getShortestPath(Graph graph, int startNumber, int destinationNumber){
PriorityQueue<Edge> priorityQueue = new PriorityQueue<>();
Node startNode = graph.getNode(startNumber);
...
...
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