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
94e957d3
Commit
94e957d3
authored
1 year ago
by
Jana Eltayeb El Rafei
Browse files
Options
Downloads
Patches
Plain Diff
corriger_dest_usager_lambda
parent
a378b9da
No related branches found
No related tags found
1 merge request
!14
Merge v2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
internal/simulation/metro.go
+1
-0
1 addition, 0 deletions
internal/simulation/metro.go
internal/simulation/usagerLambda.go
+13
-2
13 additions, 2 deletions
internal/simulation/usagerLambda.go
with
14 additions
and
2 deletions
internal/simulation/metro.go
+
1
−
0
View file @
94e957d3
...
...
@@ -86,6 +86,7 @@ func (metro *Metro) pickUpGate(gate *alg.Coord, endTime time.Time) {
gate_cell
:=
metro
.
way
.
env
.
station
[
gate
[
0
]][
gate
[
1
]]
if
len
(
gate_cell
)
>
1
{
agent
:=
metro
.
findAgent
(
AgentID
(
gate_cell
))
if
agent
!=
nil
&&
agent
.
width
*
agent
.
height
<=
metro
.
freeSpace
&&
alg
.
EqualCoord
(
&
agent
.
destination
,
gate
)
{
fmt
.
Println
(
"agent entering metro : "
,
agent
.
id
,
"at gate "
,
gate
)
metro
.
way
.
env
.
agentsChan
[
agent
.
id
]
<-
*
req
.
NewRequest
(
metro
.
comChannel
,
EnterMetro
)
...
...
This diff is collapsed.
Click to expand it.
internal/simulation/usagerLambda.go
+
13
−
2
View file @
94e957d3
...
...
@@ -7,15 +7,16 @@ import (
alg
"metrosim/internal/algorithms"
req
"metrosim/internal/request"
"time"
//
"sync"
"sync"
)
type
UsagerLambda
struct
{
req
*
req
.
Request
once
sync
.
Once
}
func
(
ul
*
UsagerLambda
)
Percept
(
ag
*
Agent
)
{
//
ul.once.Do(func(){ul.setUpDestination(ag)}) // la fonction setUp est executé à la premiere appel de la fonction Percept()
ul
.
once
.
Do
(
func
(){
ul
.
setUp
Alea
Destination
(
ag
)})
// la fonction setUp est executé à la premiere appel de la fonction Percept()
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
//print("Requete recue par l'agent lambda : ", ag.request.decision, "\n")
...
...
@@ -40,6 +41,7 @@ func (ul *UsagerLambda) Deliberate(ag *Agent) {
case
Disappear
:
ag
.
decision
=
Disappear
case
EnterMetro
:
fmt
.
Println
(
"[UsagerLambda, Deliberate] EnterMetro"
)
ag
.
decision
=
EnterMetro
case
Wait
:
ag
.
decision
=
Wait
...
...
@@ -58,6 +60,7 @@ func (ul *UsagerLambda) Deliberate(ag *Agent) {
ag
.
decision
=
Move
}
ul
.
req
=
nil
//demande traitée
}
else
if
(
ag
.
position
!=
ag
.
departure
&&
ag
.
position
==
ag
.
destination
)
&&
(
ag
.
isOn
[
ag
.
position
]
==
"W"
||
ag
.
isOn
[
ag
.
position
]
==
"S"
)
{
// si l'agent est arrivé à sa destination et qu'il est sur une sortie
//fmt.Println(ag.id, "disappear")
ag
.
decision
=
Disappear
...
...
@@ -81,7 +84,9 @@ func (ul *UsagerLambda) Act(ag *Agent) {
case
Disappear
:
ag
.
env
.
RemoveAgent
(
ag
)
case
EnterMetro
:
fmt
.
Printf
(
"[UsagerLambda, Act] agent %s entre dans le Metro
\n
"
,
ag
.
id
)
ag
.
env
.
RemoveAgent
(
ag
)
fmt
.
Printf
(
"Demandeur d'entrer le metro : %s
\n
"
,
ag
.
request
.
Demandeur
())
ul
.
req
.
Demandeur
()
<-
*
req
.
NewRequest
(
ag
.
env
.
agentsChan
[
ag
.
id
],
ACK
)
case
Expel
:
//fmt.Println("[AgentLambda, Act] Expel")
...
...
@@ -109,3 +114,9 @@ func (ul *UsagerLambda) Act(ag *Agent) {
}
}
func
(
ul
*
UsagerLambda
)
setUpAleaDestination
(
ag
*
Agent
){
choix_voie
:=
rand
.
Intn
(
2
)
// choix de la voie de métro aléatoire
dest_porte
:=
rand
.
Intn
(
len
(
ag
.
env
.
metros
[
choix_voie
]
.
way
.
gates
))
// choix de la porte de métro aléatoire
ag
.
destination
=
ag
.
env
.
metros
[
choix_voie
]
.
way
.
gates
[
dest_porte
]
}
\ 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