diff --git a/internal/simulation/agent.go b/internal/simulation/agent.go index b7751300aadcdb4a81d1a0ea982aa5bf56c12ffd..abfbf674fdcc11f2c51f9b2cdb9127cc23e5ee91 100644 --- a/internal/simulation/agent.go +++ b/internal/simulation/agent.go @@ -241,7 +241,7 @@ func writeAgent(matrix *[20][20]string, agt *Agent) { for i := borneInfRow; i < borneSupRow; i++ { for j := borneInfCol; j < borneSupCol; j++ { - matrix[i][j] = string(agt.id) + matrix[i][j] = string(agt.id)[0:1] } } diff --git a/internal/simulation/controleur.go b/internal/simulation/controleur.go index b7e3ea0fb2c0445e25ea9715254c4b1b4a648427..57217dd901ad263be2c3800d326af345c2f723ba 100644 --- a/internal/simulation/controleur.go +++ b/internal/simulation/controleur.go @@ -54,7 +54,7 @@ func (c *Controleur) Deliberate(ag *Agent) { } else if matchedFraud { ag.decision = Expel // virer l'agent devant lui } else{ - // Comportement de l'usager lambda (par defaut) + // Comportement de l'usager lambda (comportement par defaut) if ag.stuck { ag.decision = Wait } else { @@ -71,7 +71,7 @@ func (c *Controleur) Act(ag *Agent) { n := rand.Intn(2) // temps d'attente aléatoire time.Sleep(time.Duration(n) * time.Second) } else { - agt_face_id := AgentID(c.faceCase) + agt_face_id := AgentID(c.faceCase) //id de l'agent qui se trouve devant le controleur ag.env.agentsChan[agt_face_id] <- *NewRequest(ag.id, ag.decision) // envoie la decision du controleur à l'agent qui se trouve devant lui } } diff --git a/internal/simulation/env.go b/internal/simulation/env.go index 5ed6c4b7f6e5e8ecd2d3a0f0b4b952410d00de40..da1d775de505638f22062c8903743a25e4ed04a6 100644 --- a/internal/simulation/env.go +++ b/internal/simulation/env.go @@ -16,6 +16,7 @@ type Environment struct { + func NewEnvironment(ags []Agent, carte [20][20]string, agentsCh map[AgentID]chan Request) (env *Environment) { return &Environment{ags: ags, agentCount: len(ags), station: carte, agentsChan: agentsCh} } diff --git a/internal/simulation/simu.go b/internal/simulation/simu.go index 04b7e22d665eae703a788a205dcc712960862e8e..ad483a5de3ffd52169c449149a950df4e85554bf 100644 --- a/internal/simulation/simu.go +++ b/internal/simulation/simu.go @@ -87,7 +87,7 @@ func NewSimulation(agentCount int, maxStep int, maxDuration time.Duration) (simu simu.maxDuration = maxDuration // Communication entre agents - mapChan := make(map[AgentID]chan AgentID) + mapChan := make(map[AgentID]chan Request) simu.env = *NewEnvironment([]Agent{}, carte, mapChan) //simu.env = *NewEnvironment([]Agent{}, playground, mapChan) @@ -110,17 +110,18 @@ func NewSimulation(agentCount int, maxStep int, maxDuration time.Duration) (simu // ajout de l'agent à l'environnement ag.env.AddAgent(*ag) - // ajout - simu.env.agentsChan[ag.id] = make(chan Requete) + // ajout du channel de l'agent à l'environnement + simu.env.agentsChan[ag.id] = make(chan Request) } + + return simu } func (simu *Simulation) Run() { // A REVOIR si nécessaire de faire appeler simu.env.pi() log.Printf("Démarrage de la simulation [step: %d, π: %f]", simu.step, simu.env.PI()) - // Démarrage du micro-service de Log go simu.Log() // Démarrage du micro-service d'affichage @@ -167,8 +168,9 @@ func (simu *Simulation) Print() { } fmt.Println() fmt.Println() + fmt.Println("============================================================") //time.Sleep(time.Second / 4) // 60 fps ! - time.Sleep(500 * time.Millisecond) // 1 fps ! + time.Sleep(5000 * time.Millisecond) // 1 fps ! //fmt.Print("\033[H\033[2J") // effacement du terminal } } diff --git a/internal/simulation/usagerLambda.go b/internal/simulation/usagerLambda.go index 104164455a85249edf0856cee6f0d577851cda87..29820a032506c6128f2cc599396ff3e7d556d96b 100644 --- a/internal/simulation/usagerLambda.go +++ b/internal/simulation/usagerLambda.go @@ -23,7 +23,7 @@ func (ul *UsagerLambda) Percept(ag *Agent) { func (ul *UsagerLambda) Deliberate(ag *Agent) { if ul.req.decision == Wait{ ag.decision = Wait - } else if ul.req.decision == Expel{ + } else if ul.req.decision == Expel{ // cette condition est inutile car l'usager lambda ne peut pas etre expulsé ag.decision = Expel } else if ag.stuck { ag.decision = Wait @@ -39,7 +39,7 @@ func (ul *UsagerLambda) Act(ag *Agent) { n := rand.Intn(2) // temps d'attente aléatoire time.Sleep(time.Duration(n) * time.Second) } else { - ag.destination = ul.findNearestExit(ag.env) + ag.destination = ag.departure ag.MoveAgent() } } @@ -47,7 +47,7 @@ func (ul *UsagerLambda) Act(ag *Agent) { /* * Fonction qui permet de trouver la sortie la plus proche -*/ + func (ul *UsagerLambda) findNearestExit(env *Environment) Coord{ station := env.station for i := 0; i < len(station); i++ { @@ -59,3 +59,4 @@ func (ul *UsagerLambda) findNearestExit(env *Environment) Coord{ } return Coord{0,0} } +*/ \ No newline at end of file