Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MetroSim
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
Julien Pillis
MetroSim
Commits
0b5a3bb2
Commit
0b5a3bb2
authored
1 year ago
by
julienpillis
Browse files
Options
Downloads
Patches
Plain Diff
amélioration affichage métro
parent
8cbb7164
No related branches found
No related tags found
1 merge request
!14
Merge v2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
internal/algorithms/astar.go
+2
-2
2 additions, 2 deletions
internal/algorithms/astar.go
internal/simulation/metro.go
+95
-12
95 additions, 12 deletions
internal/simulation/metro.go
internal/simulation/way.go
+14
-3
14 additions, 3 deletions
internal/simulation/way.go
with
111 additions
and
17 deletions
internal/algorithms/astar.go
+
2
−
2
View file @
0b5a3bb2
...
...
@@ -181,10 +181,10 @@ func Heuristic(row, col int, end Node) int {
// On introduit de l'aléatoire pour ajouter de la diversité dans la construction des chemins
// On évite d'avoir tout le temps le même chemin pour un même point de départ et d'arrivé
//return abs(row-end.row) + abs(col-end.col) + rand.Intn(3)
return
a
bs
(
row
-
end
.
row
)
+
a
bs
(
col
-
end
.
col
)
+
rand
.
Intn
(
10
)
return
A
bs
(
row
-
end
.
row
)
+
A
bs
(
col
-
end
.
col
)
+
rand
.
Intn
(
10
)
}
func
a
bs
(
x
int
)
int
{
func
A
bs
(
x
int
)
int
{
if
x
<
0
{
return
-
x
}
...
...
This diff is collapsed.
Click to expand it.
internal/simulation/metro.go
+
95
−
12
View file @
0b5a3bb2
...
...
@@ -6,6 +6,8 @@ import (
"time"
)
var
metro_speed
int
=
5
// Nombre de seconde de l'entrée en gare
type
Metro
struct
{
frequency
time
.
Duration
stopTime
time
.
Duration
...
...
@@ -31,13 +33,14 @@ func (metro *Metro) Start() {
//var step int
for
{
//step = <-metro.syncChan
if
refTime
.
Add
(
metro
.
frequency
)
.
Before
(
time
.
Now
())
{
if
refTime
.
Add
(
metro
.
frequency
)
.
Sub
(
time
.
Now
())
<=
time
.
Duration
(
metro_speed
)
*
time
.
Second
{
metro
.
printMetro
()
}
if
refTime
.
Add
(
metro
.
frequency
)
.
Before
(
time
.
Now
())
{
metro
.
dropUsers
()
metro
.
pickUpUsers
()
metro
.
removeMetro
()
metro
.
freeSpace
=
rand
.
Intn
(
10
)
//fmt.Println(metro.way.id, metro.freeSpace)
//go metro.dropUsers()
refTime
=
time
.
Now
()
}
//metro.syncChan <- step
...
...
@@ -82,26 +85,106 @@ func (metro *Metro) findAgent(agent AgentID) *Agent {
func
(
metro
*
Metro
)
printMetro
()
{
for
x
:=
metro
.
way
.
upLeftCoord
[
0
];
x
<=
metro
.
way
.
downRightCoord
[
0
];
x
++
{
for
y
:=
metro
.
way
.
upLeftCoord
[
1
];
y
<=
metro
.
way
.
downRightCoord
[
1
];
y
++
{
if
metro
.
way
.
env
.
station
[
x
][
y
]
==
"Q"
{
metro
.
way
.
env
.
station
[
x
][
y
]
=
"M"
if
metro
.
way
.
horizontal
{
waiting_time
:=
time
.
Duration
((
metro_speed
*
1000
)
/
(
metro
.
way
.
downRightCoord
[
1
]
-
metro
.
way
.
upLeftCoord
[
1
]))
if
metro
.
way
.
goToLeft
{
for
y
:=
metro
.
way
.
downRightCoord
[
1
];
y
>=
metro
.
way
.
upLeftCoord
[
1
];
y
--
{
for
x
:=
metro
.
way
.
upLeftCoord
[
0
];
x
<=
metro
.
way
.
downRightCoord
[
0
];
x
++
{
if
metro
.
way
.
env
.
station
[
x
][
y
]
==
"Q"
{
metro
.
way
.
env
.
station
[
x
][
y
]
=
"M"
}
}
time
.
Sleep
(
waiting_time
*
time
.
Millisecond
)
}
}
else
{
for
y
:=
metro
.
way
.
upLeftCoord
[
1
];
y
<=
metro
.
way
.
downRightCoord
[
1
];
y
++
{
for
x
:=
metro
.
way
.
upLeftCoord
[
0
];
x
<=
metro
.
way
.
downRightCoord
[
0
];
x
++
{
if
metro
.
way
.
env
.
station
[
x
][
y
]
==
"Q"
{
metro
.
way
.
env
.
station
[
x
][
y
]
=
"M"
}
}
time
.
Sleep
(
waiting_time
*
time
.
Millisecond
)
}
}
}
else
{
waiting_time
:=
time
.
Duration
((
metro_speed
*
1000
)
/
(
metro
.
way
.
downRightCoord
[
0
]
-
metro
.
way
.
upLeftCoord
[
0
]))
if
metro
.
way
.
goToLeft
{
// de bas en haut
for
x
:=
metro
.
way
.
downRightCoord
[
0
];
x
>=
metro
.
way
.
upLeftCoord
[
0
];
x
--
{
for
y
:=
metro
.
way
.
upLeftCoord
[
1
];
y
<=
metro
.
way
.
downRightCoord
[
1
];
y
++
{
if
metro
.
way
.
env
.
station
[
x
][
y
]
==
"Q"
{
metro
.
way
.
env
.
station
[
x
][
y
]
=
"M"
}
}
time
.
Sleep
(
waiting_time
*
time
.
Millisecond
)
}
}
else
{
for
x
:=
metro
.
way
.
upLeftCoord
[
0
];
x
<=
metro
.
way
.
downRightCoord
[
0
];
x
++
{
for
y
:=
metro
.
way
.
upLeftCoord
[
1
];
y
<=
metro
.
way
.
downRightCoord
[
1
];
y
++
{
if
metro
.
way
.
env
.
station
[
x
][
y
]
==
"Q"
{
metro
.
way
.
env
.
station
[
x
][
y
]
=
"M"
}
}
time
.
Sleep
(
waiting_time
*
time
.
Millisecond
)
}
}
}
}
func
(
metro
*
Metro
)
removeMetro
()
{
for
x
:=
metro
.
way
.
upLeftCoord
[
0
];
x
<=
metro
.
way
.
downRightCoord
[
0
];
x
++
{
for
y
:=
metro
.
way
.
upLeftCoord
[
1
];
y
<=
metro
.
way
.
downRightCoord
[
1
];
y
++
{
if
metro
.
way
.
env
.
station
[
x
][
y
]
==
"M"
{
metro
.
way
.
env
.
station
[
x
][
y
]
=
"Q"
if
metro
.
way
.
horizontal
{
waiting_time
:=
time
.
Duration
((
metro_speed
*
1000
)
/
(
metro
.
way
.
downRightCoord
[
1
]
-
metro
.
way
.
upLeftCoord
[
1
]))
if
metro
.
way
.
goToLeft
{
for
y
:=
metro
.
way
.
downRightCoord
[
1
];
y
>=
metro
.
way
.
upLeftCoord
[
1
];
y
--
{
for
x
:=
metro
.
way
.
upLeftCoord
[
0
];
x
<=
metro
.
way
.
downRightCoord
[
0
];
x
++
{
if
metro
.
way
.
env
.
station
[
x
][
y
]
==
"M"
{
metro
.
way
.
env
.
station
[
x
][
y
]
=
"Q"
}
}
time
.
Sleep
(
waiting_time
*
time
.
Millisecond
)
}
}
else
{
for
y
:=
metro
.
way
.
upLeftCoord
[
1
];
y
<=
metro
.
way
.
downRightCoord
[
1
];
y
++
{
for
x
:=
metro
.
way
.
upLeftCoord
[
0
];
x
<=
metro
.
way
.
downRightCoord
[
0
];
x
++
{
if
metro
.
way
.
env
.
station
[
x
][
y
]
==
"M"
{
metro
.
way
.
env
.
station
[
x
][
y
]
=
"Q"
}
}
time
.
Sleep
(
waiting_time
*
time
.
Millisecond
)
}
}
}
else
{
waiting_time
:=
time
.
Duration
((
metro_speed
*
1000
)
/
(
metro
.
way
.
downRightCoord
[
0
]
-
metro
.
way
.
upLeftCoord
[
0
]))
if
metro
.
way
.
goToLeft
{
// de bas en haut
for
x
:=
metro
.
way
.
downRightCoord
[
0
];
x
>=
metro
.
way
.
upLeftCoord
[
0
];
x
--
{
for
y
:=
metro
.
way
.
upLeftCoord
[
1
];
y
<=
metro
.
way
.
downRightCoord
[
1
];
y
++
{
if
metro
.
way
.
env
.
station
[
x
][
y
]
==
"M"
{
metro
.
way
.
env
.
station
[
x
][
y
]
=
"Q"
}
}
time
.
Sleep
(
waiting_time
*
time
.
Millisecond
)
}
}
else
{
for
x
:=
metro
.
way
.
upLeftCoord
[
0
];
x
<=
metro
.
way
.
downRightCoord
[
0
];
x
++
{
for
y
:=
metro
.
way
.
upLeftCoord
[
1
];
y
<=
metro
.
way
.
downRightCoord
[
1
];
y
++
{
if
metro
.
way
.
env
.
station
[
x
][
y
]
==
"M"
{
metro
.
way
.
env
.
station
[
x
][
y
]
=
"Q"
}
}
time
.
Sleep
(
waiting_time
*
time
.
Millisecond
)
}
}
}
}
func
(
metro
*
Metro
)
drop
Agent
s
()
{
func
(
metro
*
Metro
)
drop
User
s
()
{
}
This diff is collapsed.
Click to expand it.
internal/simulation/way.go
+
14
−
3
View file @
0b5a3bb2
...
...
@@ -4,11 +4,16 @@ package simulation
* Classe et méthodes principales de la structure Way (porte de métro)
*/
import
(
alg
"metrosim/internal/algorithms"
)
type
Way
struct
{
id
WayID
upLeftCoord
Coord
// inclus
downRightCoord
Coord
// inclus
goToLeft
bool
// si vrai, le métro se déplace de droite à gauche, si faux de gauche à droite
upLeftCoord
Coord
// inclus
downRightCoord
Coord
// inclus
goToLeft
bool
// si vrai, le métro se déplace de droite à gauche, si faux de gauche à droite
horizontal
bool
gates
[]
Coord
//listes des portes associée à la voie
env
*
Environment
}
...
...
@@ -23,11 +28,17 @@ func NewWay(wayId WayID, upLeftCoord, downRightCoord Coord, goToLeft bool, gates
}
}
/* Sens de la voie */
horizontal
:=
true
if
alg
.
Abs
(
upLeftCoord
[
0
]
-
downRightCoord
[
0
])
>
alg
.
Abs
(
upLeftCoord
[
1
]
-
downRightCoord
[
1
])
{
horizontal
=
false
}
return
&
Way
{
id
:
wayId
,
upLeftCoord
:
upLeftCoord
,
downRightCoord
:
downRightCoord
,
goToLeft
:
goToLeft
,
horizontal
:
horizontal
,
gates
:
gates
,
env
:
env
}
}
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