Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vsa-frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Carlos Alvarez
vsa-frontend
Commits
b9651954
Commit
b9651954
authored
Dec 05, 2023
by
Carlos
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
applying djikstra algo
parent
2230c3e0
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
151 additions
and
22 deletions
+151
-22
index.mjs
server/index.mjs
+101
-8
package-lock.json
server/package-lock.json
+7
-1
package.json
server/package.json
+2
-1
App.tsx
src/App.tsx
+1
-10
app.py
utils-resources/app.py
+1
-1
coordinates.txt
utils-resources/coordinates.txt
+39
-1
No files found.
server/index.mjs
View file @
b9651954
import
express
from
'express'
import
Graph
from
'node-dijkstra'
;
const
route
=
new
Graph
()
const
app
=
express
()
// Node graph (store floor plan) with edges, nodes and distance.
route
.
addNode
(
'SP5'
,
{
C1C2
:
1
})
route
.
addNode
(
'C1C2'
,
{
SP5
:
1
,
C1
:
1
,
SP6SP5
:
1
})
route
.
addNode
(
'C1'
,
{
C1C2
:
1
})
route
.
addNode
(
'SP6SP5'
,
{
C1C2
:
1
,
C1B1
:
1
,
C2B2
:
1
})
route
.
addNode
(
'C1B1'
,
{
SP6SP5
:
1
,
SP6
:
1
,
B1
:
1
})
route
.
addNode
(
'SP6'
,
{
C1B1
:
1
})
route
.
addNode
(
'B1'
,
{
C1B1
:
1
})
route
.
addNode
(
'C2B2'
,
{
SP6SP5
:
1
,
C2
:
1
,
B2
:
1
,
C3B3
:
1
})
route
.
addNode
(
'B2'
,
{
C2B2
:
1
})
route
.
addNode
(
'C2'
,
{
C2B2
:
1
})
route
.
addNode
(
'C3B3'
,
{
C2B2
:
1
,
C3
:
1
,
B3
:
1
,
SP3SP4
:
1
})
route
.
addNode
(
'B3'
,
{
C3B3
:
1
})
route
.
addNode
(
'C3'
,
{
C3B3
:
1
})
route
.
addNode
(
'SP3SP4'
,
{
C3C4
:
1
,
C4B5
:
1
,
C3B3
:
1
,
B4B5
:
1
})
route
.
addNode
(
'C3C4'
,
{
SP3SP4
:
1
,
C4
:
1
,
SP4
:
1
})
route
.
addNode
(
'SP4'
,
{
C3C4
:
1
})
route
.
addNode
(
'C4'
,
{
C3C4
:
1
})
route
.
addNode
(
'C4B5'
,
{
SP3
:
1
,
SP3SP4
:
1
,
B5
:
1
})
route
.
addNode
(
'B5'
,
{
C4B5
:
1
})
route
.
addNode
(
'SP3'
,
{
C4B5
:
1
})
route
.
addNode
(
'B4B5'
,
{
SP3SP4
:
1
,
B4
:
1
,
SP2B4B5
:
1
})
route
.
addNode
(
'B4'
,
{
B4B5
:
1
})
route
.
addNode
(
'SP2B4B5'
,
{
B4B5
:
1
,
B5A3
:
1
,
B2A2
:
2
})
route
.
addNode
(
'B5A3'
,
{
SP2B4B5
:
1
,
A3
:
1
,
SP2
:
1
})
route
.
addNode
(
'A3'
,
{
B5A3
:
1
})
route
.
addNode
(
'SP2'
,
{
B5A3
:
1
})
route
.
addNode
(
'B2A2'
,
{
A2
:
1
,
SP2B4B5
:
2
,
B1A1
:
2
})
route
.
addNode
(
'A2'
,
{
B2A2
:
1
})
route
.
addNode
(
'B1A1'
,
{
B2A2
:
2
,
A1
:
2
,
SP1
:
1
})
route
.
addNode
(
'A1'
,
{
B1A1
:
1
})
route
.
addNode
(
'SP1'
,
{
B1A1
:
1
})
// coordinates
const
coordinates
=
{
SP5
:
[
101.75
,
5
],
C1C2
:
[
101.75
,
4.3
],
C1
:
[
101.4
,
4.3
],
C1B1
:
[
100.5
,
3.3
],
B1
:
[
100.5
,
3.0
],
SP6
:
[
100
,
3.3
],
SP6SP5
:
[
101.75
,
3.3
],
SP3SP4
:
[
104.85
,
3.3
],
C2B2
:
[
102.7
,
3.3
],
C2
:
[
102.7
,
3.6
],
B2
:
[
102.7
,
3.0
],
C3B3
:
[
103.7
,
3.3
],
C3
:
[
103.7
,
3.6
],
B3
:
[
103.7
,
3.0
],
C4B5
:
[
106.2
,
3.3
],
SP3
:
[
107
,
3.3
],
B5
:
[
106.2
,
3.0
],
C3C4
:
[
104.85
,
4.3
],
C4
:
[
105.2
,
4.3
],
SP4
:
[
104.85
,
5
],
B4B5
:
[
104.85
,
2
],
B4
:
[
104.50
,
2
],
SP2B4B5
:
[
104.85
,
1.35
],
B5A3
:
[
105.5
,
1.35
],
A3
:
[
105.5
,
1.0
],
SP2
:
[
107
,
1.35
],
B2A2
:
[
102.5
,
1.35
],
A2
:
[
102.5
,
1.0
],
B1A1
:
[
100.5
,
1.35
],
A1
:
[
100.5
,
1.0
],
SP1
:
[
100
,
1.35
],
}
const
getCoordinates
=
(
shortestPath
)
=>
{
const
c
=
shortestPath
.
map
((
locationId
)
=>
{
return
coordinates
[
locationId
];
})
return
c
;
}
app
.
get
(
'/getShortestPath'
,
function
(
req
,
res
)
{
console
.
log
(
req
.
query
.
product
Coordinates
);
console
.
log
(
req
.
query
.
startingPoint
Coordinates
);
console
.
log
(
req
.
query
.
product
LocationId
);
console
.
log
(
req
.
query
.
startingPoint
Id
);
// consume the dijkstra lib to get the path
res
.
send
([
[
100
,
1.35
],
[
104.85
,
1.35
],
[
104.85
,
2
],
[
104.5
,
2
]
])
const
shortestPath
=
route
.
path
(
req
.
query
.
startingPointId
,
req
.
query
.
productLocationId
);
console
.
log
(
'shortesPath:'
,
shortestPath
);
const
coordinatesPath
=
getCoordinates
(
shortestPath
);
console
.
log
(
'coordinatesPath:'
,
coordinatesPath
);
// res.send([
// [100, 1.35],
// [104.85, 1.35],
// [104.85, 2],
// [104.5,2]
// ])
res
.
send
(
coordinatesPath
);
})
console
.
log
(
"listening in port: 3000"
)
app
.
listen
(
3000
)
\ No newline at end of file
server/package-lock.json
View file @
b9651954
...
...
@@ -9,7 +9,8 @@
"version"
:
"1.0.0"
,
"license"
:
"ISC"
,
"dependencies"
:
{
"express"
:
"^4.18.2"
"express"
:
"^4.18.2"
,
"node-dijkstra"
:
"^2.5.0"
}
},
"node_modules/accepts"
:
{
...
...
@@ -423,6 +424,11 @@
"node"
:
">= 0.6"
}
},
"node_modules/node-dijkstra"
:
{
"version"
:
"2.5.0"
,
"resolved"
:
"https://registry.npmjs.org/node-dijkstra/-/node-dijkstra-2.5.0.tgz"
,
"integrity"
:
"sha512-2REYb1lo8yDRAY1gsdhjwQdGVSh47VI5Z5wS8sCqydO/P1OVAKOwLuV1fDxNLvbrtMspW7k2UZ2JKIKP06hl+A=="
},
"node_modules/object-inspect"
:
{
"version"
:
"1.13.1"
,
"resolved"
:
"https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.1.tgz"
,
...
...
server/package.json
View file @
b9651954
...
...
@@ -9,6 +9,7 @@
"author"
:
"Carlos Alvarez"
,
"license"
:
"ISC"
,
"dependencies"
:
{
"express"
:
"^4.18.2"
"express"
:
"^4.18.2"
,
"node-dijkstra"
:
"^2.5.0"
}
}
src/App.tsx
View file @
b9651954
...
...
@@ -6,15 +6,7 @@ import useFetch from "./hooks/useFetch";
import
ProductListItem
from
"./components/productListItem"
;
import
{
useEffect
,
useState
}
from
"react"
;
import
Graph
from
'node-dijkstra'
;
const
route
=
new
Graph
()
route
.
addNode
(
'A'
,
{
B
:
1
})
route
.
addNode
(
'B'
,
{
A
:
1
,
C
:
2
,
D
:
4
})
route
.
addNode
(
'C'
,
{
B
:
2
,
D
:
1
})
route
.
addNode
(
'D'
,
{
C
:
1
,
B
:
4
})
function
App
()
{
const
{
...
...
@@ -38,7 +30,6 @@ function App() {
}
=
useFetch
(
`
${
import
.
meta
.
env
.
VITE_API_ENDPOINT
}
/todos`
);
const
[
currentProductId
,
setCurrentProductId
]
=
useState
<
null
|
number
>
(
null
);
console
.
log
(
route
.
path
(
'A'
,
'D'
));
// => [ 'A', 'B', 'C', 'D' ]
useEffect
(()
=>
{
if
(
results
.
length
>
0
)
{
...
...
utils-resources/app.py
View file @
b9651954
...
...
@@ -29,7 +29,7 @@ def hello_world():
print
(
'hee'
)
# pre Step: getting the path lineString coordinates
api_url
=
"http://localhost:3000/getShortestPath?product
Coordinates=[104.5,
%202
]&startingPointCoordinates=[100,
%201.35
]
"
api_url
=
"http://localhost:3000/getShortestPath?product
LocationId=SP5&startingPointId=A1
"
response
=
requests
.
get
(
api_url
)
coordinates
=
response
.
json
()
...
...
utils-resources/coordinates.txt
View file @
b9651954
// Creating grahp, nodes and edges
route.addNode('SP5', { C1C2:1 })
route.addNode('C1C2', { SP5:1, C1:1, SP6SP5:1 })
route.addNode('C1', { C1C2:1 })
route.addNode('SP6SP5', { C1C2:1, C1B1:1, C2B2:1 })
route.addNode('C1B1', { SP6SP5:1, SP6:1, B1:1 })
route.addNode('SP6', { C1B1:1 })
route.addNode('B1', { C1B1:1 })
route.addNode('C2B2', { SP6SP5:1, C2:1, B2:1, C3B3:1 })
route.addNode('B2', { C2B2:1 })
route.addNode('C2', { C2B2:1 })
route.addNode('C3B3', { C2B2:1, C3:1, B3:1, SP3SP4:1 })
route.addNode('B3', { C3B3:1 })
route.addNode('C3', { C3B3:1 })
route.addNode('SP3SP4', { C3C4:1, C4B5:1, C3B3:1, B4B5:1 })
route.addNode('C3C4', { SP3SP4:1, C4:1, SP4:1 })
route.addNode('SP4', { C3C4:1 })
route.addNode('C4', { C3C4:1 })
route.addNode('C4B5', { SP3:1, SP3SP4:1, B5:1 })
route.addNode('B5', { C4B5:1 })
route.addNode('SP3', { C4B5:1 })
route.addNode('B4B5', { SP3SP4:1, B4:1, SP2B4B5:1 })
route.addNode('B4', { B4B5:1 })
route.addNode('SP2B4B5', { B4B5:1, B5A3:1, B2A2:2 })
route.addNode('B5A3', { SP2B4B5:1, A3:1, SP2:1 })
route.addNode('A3', { B5A3:1 })
route.addNode('SP2', { B5A3:1 })
route.addNode('B2A2', { A2:1, SP2B4B5:2, B1A1:2 })
route.addNode('A2', { B2A2:1 })
route.addNode('B1A1', { B2A2:2, A1:2, SP1:1 })
route.addNode('A1', { B1A1:1 })
route.addNode('SP1', { B1A1:1 })
// Coordinates in the plot
SP5: [101.75, 5],
C1C2: [101.75, 4.3],
...
...
@@ -12,7 +50,7 @@ C1B1: [100.5, 3.3],
B1: [100.5, 3.0],
SP6: [100, 3.3],
SP6SP5: [101.75, 3.3],
SP3
PS
4: [104.85, 3.3]
SP3
SP
4: [104.85, 3.3]
C2B2: [102.7, 3.3],
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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