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
1f737793
Commit
1f737793
authored
1 year ago
by
Yousra Hassan
Browse files
Options
Downloads
Patches
Plain Diff
usager_impoli comportement
parent
50bf891d
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
go.mod
+1
-1
1 addition, 1 deletion
go.mod
internal/simulation/agent.go
+66
-15
66 additions, 15 deletions
internal/simulation/agent.go
internal/simulation/yousra
+0
-55
0 additions, 55 deletions
internal/simulation/yousra
with
67 additions
and
71 deletions
go.mod
+
1
−
1
View file @
1f737793
module metrosim
go 1.2
1.1
go 1.2
3
This diff is collapsed.
Click to expand it.
internal/simulation/agent.go
+
66
−
15
View file @
1f737793
...
...
@@ -61,10 +61,9 @@ type Agent struct {
type
Request
struct
{
demandeur
AgentID
//chan Request ?? boucle NON ??
decision
int
decision
int
}
type
Behavior
interface
{
Percept
(
*
Agent
)
Deliberate
(
*
Agent
)
...
...
@@ -151,7 +150,6 @@ func IsMovementSafe(path []alg.Node, agt *Agent, env *Environment) (bool, int) {
}
return
false
,
agt
.
orientation
}
func
IsAgentBlocking
(
path
[]
alg
.
Node
,
agt
*
Agent
,
env
*
Environment
)
bool
{
...
...
@@ -166,7 +164,7 @@ func IsAgentBlocking(path []alg.Node, agt *Agent, env *Environment) bool {
ag
.
position
=
Coord
{
path
[
0
]
.
Row
(),
path
[
0
]
.
Col
()}
for
or
:=
0
;
or
<
4
;
or
++
{
rotateAgent
(
&
ag
,
or
)
blocking
:=
false
blocking
:=
false
//Test
// Calcul des bornes de position de l'agent après mouvement
...
...
@@ -210,7 +208,7 @@ func (ag *Agent) isStuck() bool {
count
++
}
// Case inaccessible
if
i
<
0
||
j
<
0
||
i
>
19
||
j
>
19
||
ag
.
env
.
station
[
i
][
j
]
==
"X"
||
ag
.
env
.
station
[
i
][
j
]
==
"Q"
||
existAgent
(
ag
.
env
.
station
[
i
][
j
])
{
if
i
<
0
||
j
<
0
||
i
>
19
||
j
>
19
||
ag
.
env
.
station
[
i
][
j
]
==
"X"
||
ag
.
env
.
station
[
i
][
j
]
==
"Q"
||
existAgent
(
ag
.
env
.
station
[
i
][
j
])
{
not_acc
++
}
...
...
@@ -222,8 +220,30 @@ func (ag *Agent) isStuck() bool {
return
not_acc
==
count
}
func
(
ag
*
Agent
)
WhichAgent
()
string
{
if
ag
.
direction
==
0
{
// vers le haut
return
ag
.
env
.
station
[
ag
.
position
[
0
]
-
1
][
ag
.
position
[
1
]]
}
else
if
ag
.
direction
==
1
{
// vers la droite
return
ag
.
env
.
station
[
ag
.
position
[
0
]][
ag
.
position
[
1
]
+
1
]
}
else
if
ag
.
direction
==
2
{
// vers le bas
return
ag
.
env
.
station
[
ag
.
position
[
0
]
+
1
][
ag
.
position
[
1
]]
}
else
{
// vers la gauche
return
ag
.
env
.
station
[
ag
.
position
[
0
]][
ag
.
position
[
1
]
-
1
]
}
}
func
(
env
*
Environment
)
FindAgentByID
(
agtId
AgentID
)
*
Agent
{
for
i
:=
range
env
.
ags
{
if
env
.
ags
[
i
]
.
id
==
agtId
{
return
&
env
.
ags
[
i
]
}
}
return
nil
}
func
(
ag
*
Agent
)
MoveAgent
()
{
//fmt.Println("[Agent, MoveAgent] destination ", ag.destination)
// ================== Tentative de calcul du chemin =======================
if
len
(
ag
.
path
)
==
0
{
start
,
end
:=
ag
.
generatePathExtremities
()
...
...
@@ -231,24 +251,55 @@ func (ag *Agent) MoveAgent() {
path
:=
alg
.
FindPath
(
ag
.
env
.
station
,
start
,
end
,
*
alg
.
NewNode
(
-
1
,
-
1
,
0
,
0
,
0
,
0
),
false
)
ag
.
path
=
path
}
// ================== Etude de faisabilité =======================
if
IsAgentBlocking
(
ag
.
path
,
ag
,
ag
.
env
)
{
// TODO:voir comment gérer les situations de blocage
start
,
end
:=
ag
.
generatePathExtremities
()
// Si un agent bloque notre déplacement, on attend un temps aléatoire, et reconstruit
time
.
Sleep
(
time
.
Duration
(
rand
.
Intn
(
1000
))
*
time
.
Millisecond
)
path
:=
alg
.
FindPath
(
ag
.
env
.
station
,
start
,
end
,
*
alg
.
NewNode
(
-
1
,
-
1
,
0
,
0
,
0
,
0
),
false
)
ag
.
path
=
path
return
if
ag
.
politesse
{
// TODO:voir comment gérer les situations de blocage
start
,
end
:=
ag
.
generatePathExtremities
()
// Si un agent bloque notre déplacement, on attend un temps aléatoire, et reconstruit
time
.
Sleep
(
time
.
Duration
(
rand
.
Intn
(
1000
))
*
time
.
Millisecond
)
path
:=
alg
.
FindPath
(
ag
.
env
.
station
,
start
,
end
,
*
alg
.
NewNode
(
-
1
,
-
1
,
0
,
0
,
0
,
0
),
false
)
ag
.
path
=
path
return
}
else
{
//Si individu impoli, demande à l'agent devant de bouger
//On récupère le id de la personne devant
blockingAgentID
:=
AgentID
(
ag
.
WhichAgent
())
blockingAgent
:=
ag
.
env
.
FindAgentByID
(
blockingAgentID
)
var
reqToBlockingAgent
*
Request
var
reqToImpoliteAgent
*
Request
i
:=
0
accept
:=
false
for
!
accept
&&
i
<
3
{
//Demande à l'agent qui bloque de se pousser (réitère trois fois s'il lui dit pas possible)
i
+=
1
reqToBlockingAgent
=
NewRequest
(
blockingAgentID
,
3
)
ag
.
env
.
agentsChan
[
blockingAgentID
]
<-
*
reqToBlockingAgent
//BlockingAgent cherche si autour de lui c'est vide
possible
,
or
:=
IsMovementSafe
(
blockingAgent
.
path
,
blockingAgent
,
blockingAgent
.
env
)
if
!
possible
{
reqToImpoliteAgent
=
NewRequest
(
ag
.
id
,
0
)
ag
.
env
.
agentsChan
[
ag
.
id
]
<-
*
reqToImpoliteAgent
}
else
{
//Bouge sur la case possible
accept
=
true
coordBlockingAgent
:=
blockingAgent
.
position
//Gérer le déplacement de Ag et de BlockingAgent + déplacement en fonction de la force !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}
}
}
}
// ================== Déplacement si aucun problème =======================
// ================== Déplacement si aucun problème ou si blockingAgent se pousse =======================
safe
,
or
:=
IsMovementSafe
(
ag
.
path
,
ag
,
ag
.
env
)
if
safe
{
RemoveAgent
(
&
ag
.
env
.
station
,
ag
)
rotateAgent
(
ag
,
or
)
// mise à jour de l'orientation
//ag.env.station[ag.coordBasOccupation[0]][ag.coordBasOccupation[1]] = ag.isOn
//MODIFICATION DE DIRECTION
//MODIFICATION DE DIRECTION
ag
.
direction
=
calculDirection
(
ag
.
position
,
Coord
{
ag
.
path
[
0
]
.
Row
(),
ag
.
path
[
0
]
.
Col
()})
//fmt.Println("[MoveAgent]Direction : ", ag.direction)
ag
.
position
[
0
]
=
ag
.
path
[
0
]
.
Row
()
...
...
This diff is collapsed.
Click to expand it.
internal/simulation/yousra
deleted
100644 → 0
+
0
−
55
View file @
50bf891d
// ================== Comprendre la structure du code ==================
Agent :
id AgentID //identification
vitesse time.Duration //vitesse
force int
politesse bool
position Coord // Coordonnées de référence, width et height on compte width et height à partir de cette position
departure Coord
destination Coord
behavior Behavior
env *Environment //Environnement dan slequel il est
syncChan chan int
decision int
isOn map[Coord]string // Contenu de la case sur laquelle il se trouve
stuck bool
width int
height int
orientation int //0 : vers le haut, 1 : vers la droite, 2 : vers le bas, 3 : vers la gauche
path []alg.Node
request *Request
if ag.politesse == false {
}
// =============== Questions =================
Pourquoi l environnement dans Percept est passé par copie alors que cekui de Act par pointeur? dan sle cours.
Réponse : pointeur pour qu on puisse agir dessus?
a quoi sert log dans simulation?
Dans le projet :
- A quoi sert sync.Map dans Simulation?
- Vous avez pas fait tous les getters dans Agent?
- Attributs syncChan et path dans Agent? qu est ce que le channel de synchro qui prend plusieurs channel entre eux
// Lancement de l'orchestration de tous les agents
// simu.step += 1 // plus de sens
for _, agt := range simu.agents {
go func(agt Agent) {
step := 0
for {
step++
c, _ := simu.syncChans.Load(agt.ID()) // communiquer les steps aux agents
c.(chan int) <- step // /!\ utilisation d'un "Type Assertion"
time.Sleep(1 * time.Millisecond) // "cool down"
<-c.(chan int)
}
}(agt)
\ No newline at end of file
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