Skip to content
Snippets Groups Projects
Commit c3d66ad4 authored by Jana Eltayeb El Rafei's avatar Jana Eltayeb El Rafei
Browse files

ajout_request_structure

parent 7cfe3f6d
No related branches found
No related tags found
1 merge request!8Controleur
......@@ -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]
}
}
......
......@@ -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
}
}
......@@ -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}
}
......
......@@ -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
}
}
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment