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
cd0682f2
Commit
cd0682f2
authored
1 year ago
by
julienpillis
Browse files
Options
Downloads
Patches
Plain Diff
amélioration flux entrée-sortie
parent
da9764b6
No related branches found
Branches containing commit
No related tags found
1 merge request
!14
Merge v2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
internal/simulation/agent.go
+28
-4
28 additions, 4 deletions
internal/simulation/agent.go
internal/simulation/metro.go
+24
-6
24 additions, 6 deletions
internal/simulation/metro.go
internal/simulation/way.go
+2
-14
2 additions, 14 deletions
internal/simulation/way.go
with
54 additions
and
24 deletions
internal/simulation/agent.go
+
28
−
4
View file @
cd0682f2
...
...
@@ -117,7 +117,17 @@ func (agt *Agent) IsMovementSafe() (bool, int) {
if
!
(
borneInfCol
<
0
||
borneInfRow
<
0
||
borneSupRow
>
50
||
borneSupCol
>
50
)
{
for
i
:=
borneInfRow
;
i
<
borneSupRow
;
i
++
{
for
j
:=
borneInfCol
;
j
<
borneSupCol
;
j
++
{
if
!
(
j
>=
infCol
&&
j
<
supCol
&&
i
>=
infRow
&&
i
<
supRow
)
&&
(
agt
.
env
.
station
[
i
][
j
]
!=
"B"
&&
agt
.
env
.
station
[
i
][
j
]
!=
"_"
&&
agt
.
env
.
station
[
i
][
j
]
!=
"W"
&&
agt
.
env
.
station
[
i
][
j
]
!=
"S"
&&
agt
.
env
.
station
[
i
][
j
]
!=
"O"
)
{
if
agt
.
env
.
station
[
i
][
j
]
==
"O"
{
// Vérification si porte de métro
metro
:=
findMetro
(
ag
.
env
,
&
alg
.
Coord
{
i
,
j
})
if
metro
!=
nil
&&
!
metro
.
way
.
gatesClosed
&&
alg
.
EqualCoord
(
&
ag
.
destination
,
&
alg
.
Coord
{
i
,
j
})
{
// On s'assure que les portes ne sont pas fermées et que c'est la destination
return
true
,
or
}
else
{
safe
=
false
}
}
if
!
(
j
>=
infCol
&&
j
<
supCol
&&
i
>=
infRow
&&
i
<
supRow
)
&&
(
agt
.
env
.
station
[
i
][
j
]
!=
"B"
&&
agt
.
env
.
station
[
i
][
j
]
!=
"_"
&&
agt
.
env
.
station
[
i
][
j
]
!=
"W"
&&
agt
.
env
.
station
[
i
][
j
]
!=
"S"
)
{
// Si on n'est pas sur une case atteignable, en dehors de la zone qu'occupe l'agent avant déplacement, on est bloqué
safe
=
false
}
...
...
@@ -216,8 +226,11 @@ func (ag *Agent) MoveAgent() {
if
len
(
ag
.
path
)
==
0
||
ag
.
isGoingToExitPath
()
{
start
,
end
:=
ag
.
generatePathExtremities
()
// Recherche d'un chemin si inexistant
ag
.
path
=
alg
.
FindPath
(
ag
.
env
.
station
,
start
,
end
,
*
alg
.
NewNode
(
-
1
,
-
1
,
0
,
0
,
0
,
0
),
false
,
2
*
time
.
Second
)
if
len
(
ag
.
path
)
>
0
{
ag
.
path
=
alg
.
FindPath
(
ag
.
env
.
station
,
start
,
end
,
ag
.
path
[
0
],
false
,
2
*
time
.
Second
)
}
else
{
ag
.
path
=
alg
.
FindPath
(
ag
.
env
.
station
,
start
,
end
,
*
alg
.
NewNode
(
-
1
,
-
1
,
0
,
0
,
0
,
0
),
false
,
2
*
time
.
Second
)
}
}
// ================== Etude de faisabilité =======================
...
...
@@ -333,7 +346,7 @@ func (ag *Agent) isGoingToExitPath() bool {
// Si la destination est une porte de métro, on va essayer de libérer le chemin des agents sortants
exit_path
:=
metro
.
way
.
pathsToExit
[
gate_index
]
for
_
,
cell
:=
range
exit_path
{
if
alg
.
EqualCoord
(
&
alg
.
Coord
{
cell
.
Row
(),
cell
.
Col
()},
&
a
g
.
position
)
{
if
alg
.
EqualCoord
(
&
alg
.
Coord
{
cell
.
Row
(),
cell
.
Col
()},
&
a
lg
.
Coord
{
ag
.
path
[
0
]
.
Row
(),
ag
.
path
[
0
]
.
Col
()}
)
{
return
true
}
}
...
...
@@ -343,3 +356,14 @@ func (ag *Agent) isGoingToExitPath() bool {
}
return
false
}
func
findMetro
(
env
*
Environment
,
gateToFind
*
alg
.
Coord
)
*
Metro
{
for
_
,
metro
:=
range
env
.
metros
{
for
_
,
gate
:=
range
metro
.
way
.
gates
{
if
alg
.
EqualCoord
(
&
gate
,
gateToFind
)
{
return
&
metro
}
}
}
return
nil
}
This diff is collapsed.
Click to expand it.
internal/simulation/metro.go
+
24
−
6
View file @
cd0682f2
...
...
@@ -49,9 +49,9 @@ func (metro *Metro) Start() {
}
if
refTime
.
Add
(
metro
.
frequency
)
.
Before
(
time
.
Now
())
{
metro
.
dropUsers
()
metro
.
way
.
openGates
()
metro
.
openGates
()
metro
.
pickUpUsers
()
metro
.
way
.
closeGates
()
metro
.
closeGates
()
metro
.
removeMetro
()
metro
.
freeSpace
=
rand
.
Intn
(
10
)
refTime
=
time
.
Now
()
...
...
@@ -81,14 +81,11 @@ func (metro *Metro) pickUpGate(gate *alg.Coord, endTime time.Time) {
if
!
time
.
Now
()
.
Before
(
endTime
)
{
return
}
else
{
gate_cell
:=
metro
.
way
.
env
.
station
[
gate
[
0
]][
gate
[
1
]]
if
len
(
gate_cell
)
>
1
{
agent
:=
metro
.
findAgent
(
AgentID
(
gate_cell
))
//fmt.Println("gate cell", gate[0],gate[1], "agent", agent)
if
agent
!=
nil
&&
agent
.
width
*
agent
.
height
<=
metro
.
freeSpace
&&
alg
.
EqualCoord
(
&
agent
.
destination
,
gate
)
{
//
fmt.Println("agent entering metro : ", agent.id)
fmt
.
Println
(
"agent entering metro : "
,
agent
.
id
,
"at gate "
,
gate
)
metro
.
way
.
env
.
agentsChan
[
agent
.
id
]
<-
*
req
.
NewRequest
(
metro
.
comChannel
,
EnterMetro
)
<-
metro
.
comChannel
metro
.
freeSpace
=
metro
.
freeSpace
-
agent
.
width
*
agent
.
height
...
...
@@ -232,3 +229,24 @@ func (metro *Metro) removeMetro() {
}
}
func
(
metro
*
Metro
)
openGates
()
{
// Début d'autorisation d'entrer dans le métro
for
_
,
gate
:=
range
metro
.
way
.
gates
{
metro
.
way
.
env
.
station
[
gate
[
0
]][
gate
[
1
]]
=
"O"
}
metro
.
way
.
gatesClosed
=
false
}
func
(
metro
*
Metro
)
closeGates
()
{
// Fin d'autorisation d'entrer dans le métro
metro
.
way
.
gatesClosed
=
true
for
_
,
gate
:=
range
metro
.
way
.
gates
{
if
len
(
metro
.
way
.
env
.
station
[
gate
[
0
]][
gate
[
1
]])
>
1
{
// On autorise les agents déjà sur la case à rentrer dans le métro
metro
.
pickUpGate
(
&
gate
,
time
.
Now
()
.
Add
(
time
.
Duration
(
1
*
time
.
Second
)))
}
metro
.
way
.
env
.
station
[
gate
[
0
]][
gate
[
1
]]
=
"G"
}
}
This diff is collapsed.
Click to expand it.
internal/simulation/way.go
+
2
−
14
View file @
cd0682f2
...
...
@@ -13,11 +13,12 @@ type Way struct {
id
WayID
upLeftCoord
alg
.
Coord
// inclus
downRightCoord
alg
.
Coord
// inclus
goToLeft
bool
// si vrai, le métro se déplace de droite à gauche, si faux de gauche à droite
goToLeft
bool
// si vrai, le métro se déplace de droite à gauche, si faux de gauche à droite
horizontal
bool
gates
[]
alg
.
Coord
//listes des portes associée à la voie
nearestExit
[]
alg
.
Coord
// Chemin vers la sortie la plus proche pour chaque porte (index vers pathsToExit)
pathsToExit
[][]
alg
.
Node
gatesClosed
bool
env
*
Environment
}
...
...
@@ -57,16 +58,3 @@ func NewWay(wayId WayID, upLeftCoord, downRightCoord alg.Coord, goToLeft bool, g
env
:
env
}
}
func
(
way
*
Way
)
openGates
()
{
// Début d'autorisation d'entrer dans le métro
for
_
,
gate
:=
range
way
.
gates
{
way
.
env
.
station
[
gate
[
0
]][
gate
[
1
]]
=
"O"
}
}
func
(
way
*
Way
)
closeGates
()
{
// Fin d'autorisation d'entrer dans le métro
for
_
,
gate
:=
range
way
.
gates
{
way
.
env
.
station
[
gate
[
0
]][
gate
[
1
]]
=
"G"
}
}
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