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
Compare revisions
47cbaa1217b4e5f5d1c8fd851ea1cf8217524b95 to d04c80fea5248c5526455f1c006efa1543da8878
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
pillisju/metrosim
Select target project
No results found
d04c80fea5248c5526455f1c006efa1543da8878
Select Git revision
Swap
Target
pillisju/metrosim
Select target project
pillisju/metrosim
1 result
47cbaa1217b4e5f5d1c8fd851ea1cf8217524b95
Select Git revision
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (2)
usager impoli
· c0a9428a
Yousra Hassan
authored
1 year ago
c0a9428a
Merge branch 'merge_v2' of
https://gitlab.utc.fr/pillisju/metrosim
into merge_v2
· d04c80fe
Yousra Hassan
authored
1 year ago
d04c80fe
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
internal/simulation/agent.go
+81
-0
81 additions, 0 deletions
internal/simulation/agent.go
internal/simulation/usagerLambda.go
+18
-16
18 additions, 16 deletions
internal/simulation/usagerLambda.go
with
99 additions
and
16 deletions
internal/simulation/agent.go
View file @
d04c80fe
...
@@ -243,6 +243,87 @@ func (ag *Agent) NextCell() string {
...
@@ -243,6 +243,87 @@ func (ag *Agent) NextCell() string {
return
"X"
return
"X"
}
}
func
(
agt
*
Agent
)
MyNextCellIsSafe
()
bool
{
// Simulation du déplacement
ag
:=
*
agt
switch
ag
.
direction
{
case
0
:
//haut
ag
.
position
=
alg
.
Coord
{
ag
.
position
[
0
]
-
1
,
ag
.
position
[
1
]}
case
1
:
//droite
ag
.
position
=
alg
.
Coord
{
ag
.
position
[
0
],
ag
.
position
[
1
]
+
1
}
case
2
:
//gauche
ag
.
position
=
alg
.
Coord
{
ag
.
position
[
0
]
+
1
,
ag
.
position
[
1
]}
case
3
:
//bas
ag
.
position
=
alg
.
Coord
{
ag
.
position
[
0
],
ag
.
position
[
1
]
-
1
}
}
if
!
(
ag
.
position
[
1
]
<
0
||
ag
.
position
[
0
]
<
0
||
ag
.
position
[
0
]
>
len
(
agt
.
env
.
station
[
0
])
||
ag
.
position
[
1
]
>
len
(
agt
.
env
.
station
[
1
]))
{
i
:=
ag
.
position
[
0
]
j
:=
ag
.
position
[
1
]
if
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é
//fmt.Println("[IsMovementSafe]case inaccessible :",agt.id)
return
false
}
else
{
return
true
}
}
return
false
}
func
(
ag
*
Agent
)
ShiftAgent
()
bool
{
//fmt.Printf("ShiftAgent")
storeDirection
:=
ag
.
direction
//enregistrer l'orientation initiale de l'agent
for
i
:=
0
;
i
<
4
;
i
++
{
ag
.
direction
=
(
storeDirection
+
i
)
%
4
safe
:=
ag
.
MyNextCellIsSafe
()
if
safe
{
// Deplacement possible safe=true
switch
ag
.
direction
{
case
0
:
//haut
ag
.
position
=
alg
.
Coord
{
ag
.
position
[
0
]
-
1
,
ag
.
position
[
1
]}
case
1
:
//droite
ag
.
position
=
alg
.
Coord
{
ag
.
position
[
0
],
ag
.
position
[
1
]
+
1
}
case
2
:
ag
.
position
=
alg
.
Coord
{
ag
.
position
[
0
]
+
1
,
ag
.
position
[
1
]}
case
3
:
ag
.
position
=
alg
.
Coord
{
ag
.
position
[
0
],
ag
.
position
[
1
]
-
1
}
}
//Début du déplacement
ag
.
env
.
Lock
()
x
:=
ag
.
position
[
0
]
y
:=
ag
.
position
[
1
]
if
len
(
ag
.
isOn
)
>
0
{
// Suppression de l'agent
ag
.
env
.
station
[
x
][
y
]
=
ag
.
isOn
[
alg
.
Coord
{
x
,
y
}]
alg
.
RemoveCoord
(
alg
.
Coord
{
x
,
y
},
ag
.
isOn
)
}
// Enregistrement des valeurs précédentes de la matrice
ag
.
isOn
[
alg
.
Coord
{
x
,
y
}]
=
ag
.
env
.
station
[
x
][
y
]
//Ecriture agent dans la matrice (déplacement)
ag
.
env
.
station
[
x
][
y
]
=
string
(
ag
.
id
)
ag
.
env
.
Unlock
()
//Fin du déplacement
// Prise en compte de la vitesse de déplacement
time
.
Sleep
(
ag
.
vitesse
*
time
.
Millisecond
)
fmt
.
Printf
(
"J'ai bougé"
)
return
true
}
}
//si on peut aller nulle part, on se remet dans notre config initiale
ag
.
direction
=
storeDirection
//fmt.Printf("Je me bouge pas")
return
false
}
func
(
ag
*
Agent
)
MoveAgent
()
bool
{
func
(
ag
*
Agent
)
MoveAgent
()
bool
{
//fmt.Printf("[MoveAgent, %s ] direction = %d \n",ag.id, ag.direction)
//fmt.Printf("[MoveAgent, %s ] direction = %d \n",ag.id, ag.direction)
// ================== Tentative de calcul du chemin =======================
// ================== Tentative de calcul du chemin =======================
...
...
This diff is collapsed.
Click to expand it.
internal/simulation/usagerLambda.go
View file @
d04c80fe
...
@@ -22,9 +22,9 @@ func (ul *UsagerLambda) Percept(ag *Agent) {
...
@@ -22,9 +22,9 @@ func (ul *UsagerLambda) Percept(ag *Agent) {
*/
*/
switch
{
switch
{
case
ag
.
request
!=
nil
:
//verifier si l'agent est communiqué par un autre agent, par exemple un controleur lui a demandé de s'arreter
case
ag
.
request
!=
nil
:
//verifier si l'agent est communiqué par un autre agent, par exemple un controleur lui a demandé de s'arreter
fmt
.
Printf
(
"Requete recue par l'agent lambda %s : %d
\n
"
,
ag
.
id
,
ag
.
request
.
Decision
())
fmt
.
Printf
(
"Requete recue par l'agent lambda %s : %d
\n
"
,
ag
.
id
,
ag
.
request
.
Decision
())
ul
.
requete
=
ag
.
request
ul
.
requete
=
ag
.
request
default
:
default
:
ag
.
stuck
=
ag
.
isStuck
()
ag
.
stuck
=
ag
.
isStuck
()
if
ag
.
stuck
{
if
ag
.
stuck
{
...
@@ -38,7 +38,7 @@ func (ul *UsagerLambda) Deliberate(ag *Agent) {
...
@@ -38,7 +38,7 @@ func (ul *UsagerLambda) Deliberate(ag *Agent) {
if
ul
.
requete
!=
nil
{
if
ul
.
requete
!=
nil
{
switch
ul
.
requete
.
Decision
()
{
switch
ul
.
requete
.
Decision
()
{
case
Expel
:
case
Expel
:
ag
.
decision
=
Expel
ag
.
decision
=
Expel
return
return
case
Disappear
:
case
Disappear
:
...
@@ -54,6 +54,9 @@ func (ul *UsagerLambda) Deliberate(ag *Agent) {
...
@@ -54,6 +54,9 @@ func (ul *UsagerLambda) Deliberate(ag *Agent) {
case
Move
:
case
Move
:
ag
.
decision
=
Move
ag
.
decision
=
Move
return
return
case
YouHaveToMove
:
ag
.
decision
=
TryToMove
return
default
:
default
:
ag
.
decision
=
Move
ag
.
decision
=
Move
return
return
...
@@ -84,27 +87,26 @@ func (ul *UsagerLambda) Act(ag *Agent) {
...
@@ -84,27 +87,26 @@ func (ul *UsagerLambda) Act(ag *Agent) {
ag
.
env
.
RemoveAgent
(
ag
)
ag
.
env
.
RemoveAgent
(
ag
)
//fmt.Printf("Demandeur d'entrer le metro : %s \n",ul.requete.Demandeur())
//fmt.Printf("Demandeur d'entrer le metro : %s \n",ul.requete.Demandeur())
ul
.
requete
.
Demandeur
()
<-
*
req
.
NewRequest
(
ag
.
env
.
agentsChan
[
ag
.
id
],
ACK
)
ul
.
requete
.
Demandeur
()
<-
*
req
.
NewRequest
(
ag
.
env
.
agentsChan
[
ag
.
id
],
ACK
)
case
Expel
:
case
Expel
:
//fmt.Println("[AgentLambda, Act] Expel")
//fmt.Println("[AgentLambda, Act] Expel")
ag
.
destination
=
ag
.
findNearestExit
()
ag
.
destination
=
ag
.
findNearestExit
()
fmt
.
Printf
(
"[UsagerLambda, Act] position de l'agent %s = (%d , %d)
\n
"
,
ag
.
id
,
ag
.
position
[
0
],
ag
.
position
[
1
])
fmt
.
Printf
(
"[UsagerLambda, Act] position de l'agent %s = (%d , %d)
\n
"
,
ag
.
id
,
ag
.
position
[
0
],
ag
.
position
[
1
])
fmt
.
Printf
(
"[UsagerLambda, Act] destination de l'agent %s = (%d , %d)
\n
"
,
ag
.
id
,
ag
.
destination
[
0
],
ag
.
destination
[
1
])
fmt
.
Printf
(
"[UsagerLambda, Act] destination de l'agent %s = (%d , %d)
\n
"
,
ag
.
id
,
ag
.
destination
[
0
],
ag
.
destination
[
1
])
ag
.
env
.
controlledAgents
[
ag
.
id
]
=
true
ag
.
env
.
controlledAgents
[
ag
.
id
]
=
true
ag
.
path
=
make
([]
alg
.
Node
,
0
)
ag
.
path
=
make
([]
alg
.
Node
,
0
)
ag
.
MoveAgent
()
ag
.
MoveAgent
()
fmt
.
Printf
(
"[UsagerLambda, Act] J'ai bougé %s , ma position = (%d , %d)
\n
"
,
ag
.
id
,
ag
.
position
[
0
],
ag
.
position
[
1
])
fmt
.
Printf
(
"[UsagerLambda, Act] J'ai bougé %s , ma position = (%d , %d)
\n
"
,
ag
.
id
,
ag
.
position
[
0
],
ag
.
position
[
1
])
case
TryToMove
:
case
Noop
:
//fmt.Printf("Je suis %s est-ce que j'ai bougé? %t \n", ag.id, movement)
//Cas ou un usager impoli demande a un usager de bouger et il refuse
if
ag
.
ShiftAgent
()
{
ul
.
requete
.
Demandeur
()
<-
*
req
.
NewRequest
(
ag
.
env
.
agentsChan
[
ag
.
id
],
Noop
)
ul
.
requete
.
Demandeur
()
<-
*
req
.
NewRequest
(
ag
.
env
.
agentsChan
[
ag
.
id
],
Done
)
// nothing to do
}
else
{
case
Done
:
ul
.
requete
.
Demandeur
()
<-
*
req
.
NewRequest
(
ag
.
env
.
agentsChan
[
ag
.
id
],
Noop
)
//Cas ou un usager impoli demande a un usager de bouger et il le fait
}
ul
.
requete
.
Demandeur
()
<-
*
req
.
NewRequest
(
ag
.
env
.
agentsChan
[
ag
.
id
],
Done
)
}
}
//ag.request = nil // la requete est traitée
//ag.request = nil // la requete est traitée
if
ag
.
request
!=
nil
&&
ag
.
decision
==
ag
.
request
.
Decision
(){
if
ag
.
request
!=
nil
&&
ag
.
decision
==
ag
.
request
.
Decision
()
{
ag
.
request
=
nil
ag
.
request
=
nil
ul
.
requete
=
nil
ul
.
requete
=
nil
}
// la requete est traitée
}
// la requete est traitée
...
@@ -119,4 +121,4 @@ func (ul *UsagerLambda) SetUpDestination(ag *Agent) {
...
@@ -119,4 +121,4 @@ func (ul *UsagerLambda) SetUpDestination(ag *Agent) {
func
isControlledAgt
(
ag
*
Agent
)
bool
{
func
isControlledAgt
(
ag
*
Agent
)
bool
{
return
ag
.
env
.
controlledAgents
[
ag
.
id
]
return
ag
.
env
.
controlledAgents
[
ag
.
id
]
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.