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
f3fc3a98
Commit
f3fc3a98
authored
1 year ago
by
julienpillis
Browse files
Options
Downloads
Patches
Plain Diff
modifications mineures
parent
b81b73e6
No related branches found
No related tags found
2 merge requests
!4
Multiple pixels agt
,
!2
Agents
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
agent.go
+27
-25
27 additions, 25 deletions
agent.go
simu.go
+1
-1
1 addition, 1 deletion
simu.go
with
28 additions
and
26 deletions
agent.go
+
27
−
25
View file @
f3fc3a98
...
...
@@ -2,6 +2,7 @@ package simulation
import
(
//"fmt"
"log"
"math/rand"
"time"
...
...
@@ -37,19 +38,22 @@ type Agent struct {
}
type
Behavior
interface
{
Percept
(
*
Agent
,
*
Environment
)
Percept
(
*
Agent
)
Deliberate
(
*
Agent
)
Act
(
*
Agent
,
*
Environment
)
Act
(
*
Agent
)
}
type
UsagerLambda
struct
{}
func
(
ul
*
UsagerLambda
)
Percept
(
ag
*
Agent
,
env
*
Environment
)
{
func
(
ul
*
UsagerLambda
)
Percept
(
ag
*
Agent
)
{
ag
.
stuck
=
ag
.
isStuck
()
if
ag
.
stuck
{
return
}
}
func
(
ul
*
UsagerLambda
)
Deliberate
(
ag
*
Agent
)
{
// Si l'agent est bloqué, il doit attendre qu'une case se libère autour de lui
if
ag
.
stuck
{
ag
.
decision
=
Wait
}
else
{
...
...
@@ -57,11 +61,10 @@ func (ul *UsagerLambda) Deliberate(ag *Agent) {
}
}
func
(
ul
*
UsagerLambda
)
Act
(
ag
*
Agent
,
env
*
Environment
)
{
func
(
ul
*
UsagerLambda
)
Act
(
ag
*
Agent
)
{
if
ag
.
decision
==
Move
{
ag
.
MoveAgent
()
}
if
ag
.
decision
==
Wait
{
}
else
if
ag
.
decision
==
Wait
{
n
:=
rand
.
Intn
(
2
)
// temps d'attente aléatoire
time
.
Sleep
(
time
.
Duration
(
n
)
*
time
.
Second
)
}
...
...
@@ -80,13 +83,12 @@ func (ag *Agent) Start() {
log
.
Printf
(
"%s starting...
\n
"
,
ag
.
id
)
go
func
()
{
env
:=
ag
.
env
var
step
int
for
{
step
=
<-
ag
.
syncChan
ag
.
behavior
.
Percept
(
ag
,
env
)
ag
.
behavior
.
Percept
(
ag
)
ag
.
behavior
.
Deliberate
(
ag
)
ag
.
behavior
.
Act
(
ag
,
env
)
ag
.
behavior
.
Act
(
ag
)
ag
.
syncChan
<-
step
}
}()
...
...
@@ -130,15 +132,26 @@ func (ag *Agent) isStuck() bool {
}
func
(
ag
*
Agent
)
MoveAgent
()
{
// TODO: Gérer les moments où les agents font du quasi-sur place car il ne peuvent plus bouger
// TODO: Parfois, certains agents ne bougent plus,
// TODO: Il arrive encore que certains agents soient bloqués, mais c'est quand il n'y a aucun mouvement possible.
// Il faudrait faire en sorte que les agents bougent et laisse passer les autres
// ============ Initialisation des noeuds de départ ======================
start
:=
Node
{
ag
.
coordBasOccupation
[
0
],
ag
.
coordBasOccupation
[
1
],
0
,
0
}
end
:=
Node
{
ag
.
destination
[
0
],
ag
.
destination
[
1
],
0
,
0
}
// ==================
1ère t
entative de calcul du chemin =======================
// ==================
T
entative de calcul du chemin =======================
path
:=
findPath
(
ag
.
env
.
station
,
start
,
end
,
Node
{})
// ================== Etude de faisabilité =======================
if
IsAgentBlocking
(
path
,
ag
.
env
)
{
// Si un agent bloque notre déplacement, on attend un temps aléatoire, et reconstruit un chemin en évitant la position
time
.
Sleep
(
time
.
Duration
(
rand
.
Intn
(
1000
))
*
time
.
Millisecond
)
path
=
findPath
(
ag
.
env
.
station
,
start
,
end
,
path
[
0
])
time
.
Sleep
(
time
.
Second
)
}
if
IsMovementSafe
(
path
,
ag
.
env
)
{
ag
.
env
.
station
[
ag
.
coordBasOccupation
[
0
]][
ag
.
coordBasOccupation
[
1
]]
=
ag
.
isOn
ag
.
isOn
=
ag
.
env
.
station
[
path
[
0
]
.
row
][
path
[
0
]
.
col
]
...
...
@@ -146,19 +159,8 @@ func (ag *Agent) MoveAgent() {
ag
.
coordBasOccupation
[
1
]
=
path
[
0
]
.
col
ag
.
env
.
station
[
ag
.
coordBasOccupation
[
0
]][
ag
.
coordBasOccupation
[
1
]]
=
"A"
}
else
if
IsAgentBlocking
(
path
,
ag
.
env
)
{
// Si un agent bloque notre déplacement, on attend un temps aléatoire, et reconstruit un chemin en évitant la position
time
.
Sleep
(
time
.
Duration
(
rand
.
Intn
(
1000
))
*
time
.
Millisecond
)
path
:=
findPath
(
ag
.
env
.
station
,
start
,
end
,
path
[
0
])
if
len
(
path
)
>
0
&&
(
ag
.
env
.
station
[
path
[
0
]
.
row
][
path
[
0
]
.
col
]
==
"B"
||
ag
.
env
.
station
[
path
[
0
]
.
row
][
path
[
0
]
.
col
]
==
"_"
)
{
ag
.
env
.
station
[
ag
.
coordBasOccupation
[
0
]][
ag
.
coordBasOccupation
[
1
]]
=
ag
.
isOn
ag
.
isOn
=
ag
.
env
.
station
[
path
[
0
]
.
row
][
path
[
0
]
.
col
]
ag
.
coordBasOccupation
[
0
]
=
path
[
0
]
.
row
ag
.
coordBasOccupation
[
1
]
=
path
[
0
]
.
col
ag
.
env
.
station
[
ag
.
coordBasOccupation
[
0
]][
ag
.
coordBasOccupation
[
1
]]
=
"A"
}
// ============ Prise en compte de la vitesse de déplacement ======================
time
.
Sleep
(
ag
.
vitesse
)
}
// ============ Prise en compte de la vitesse de déplacement ======================
time
.
Sleep
(
ag
.
vitesse
)
}
This diff is collapsed.
Click to expand it.
simu.go
+
1
−
1
View file @
f3fc3a98
...
...
@@ -91,7 +91,7 @@ func NewSimulation(agentCount int, maxStep int, maxDuration time.Duration) (simu
// création de l'agent
id
:=
fmt
.
Sprintf
(
"Agent #%d"
,
i
)
syncChan
:=
make
(
chan
int
)
ag
:=
NewAgent
(
id
,
&
simu
.
env
,
syncChan
,
time
.
Duration
(
200
*
time
.
Millis
econd
),
0
,
true
,
Coord
{
0
,
8
+
i
%
2
},
Coord
{
0
,
8
+
i
%
2
},
&
UsagerLambda
{},
Coord
{
0
,
8
+
i
%
2
},
Coord
{
12
-
4
*
(
i
%
2
),
18
-
15
*
(
i
%
2
)})
ag
:=
NewAgent
(
id
,
&
simu
.
env
,
syncChan
,
time
.
Duration
(
time
.
S
econd
),
0
,
true
,
Coord
{
0
,
8
+
i
%
2
},
Coord
{
0
,
8
+
i
%
2
},
&
UsagerLambda
{},
Coord
{
0
,
8
+
i
%
2
},
Coord
{
12
-
4
*
(
i
%
2
),
18
-
15
*
(
i
%
2
)})
//ag := NewAgent(id, &simu.env, syncChan, 1, 0, true, Coord{4,10}, Coord{4,10}, &UsagerLambda{}, Coord{4,10}, Coord{0, 0})
...
...
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