Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • pillisju/metrosim
1 result
Show changes
Commits on Source (2)
...@@ -61,18 +61,19 @@ func simHandler(action string) http.HandlerFunc { ...@@ -61,18 +61,19 @@ func simHandler(action string) http.HandlerFunc {
} }
case "launch": case "launch":
log.Println("[API] Launch request") //TODELETElog.Println("[API] Launch request")
if simulation != nil { if simulation != nil {
log.Println("[API] running") //TODELETElog.Println("[API] running")
if !simulation.IsRunning() { if !simulation.IsRunning() {
log.Println("[API] running") //TODELETElog.Println("[API] running")
go simulation.Run() go simulation.Run()
} }
msg, _ := json.Marshal(simulation.Print()) msg, _ := json.Marshal(simulation.Print())
//TODELETEfmt.Printf("%d\n", len(msg))
fmt.Fprintf(w, "%s", msg) fmt.Fprintf(w, "%s", msg)
} }
case "stop": case "stop":
// TODO // TODOD
} }
} }
} }
......
...@@ -5,9 +5,6 @@ package simulation ...@@ -5,9 +5,6 @@ package simulation
*/ */
import ( import (
"fmt"
"log"
//"fmt" //"fmt"
//"log" //"log"
...@@ -77,7 +74,7 @@ func (ag *Agent) ID() AgentID { ...@@ -77,7 +74,7 @@ func (ag *Agent) ID() AgentID {
func (ag *Agent) Start() { func (ag *Agent) Start() {
log.Printf("%s starting...\n", ag.id) //TODELETElog.Printf("%s starting...\n", ag.id)
go ag.listenForRequests() go ag.listenForRequests()
// si c'est un controlleur on lance le timer de durée de vie // si c'est un controlleur on lance le timer de durée de vie
...@@ -313,7 +310,7 @@ func (ag *Agent) ShiftAgent() bool { ...@@ -313,7 +310,7 @@ func (ag *Agent) ShiftAgent() bool {
// Prise en compte de la vitesse de déplacement // Prise en compte de la vitesse de déplacement
time.Sleep(ag.vitesse * time.Millisecond) time.Sleep(ag.vitesse * time.Millisecond)
fmt.Printf("J'ai bougé") //TODELETEfmt.Printf("J'ai bougé")
return true return true
} }
} }
...@@ -363,18 +360,18 @@ func (ag *Agent) MoveAgent() bool { ...@@ -363,18 +360,18 @@ func (ag *Agent) MoveAgent() bool {
for !accept && i < 3 { for !accept && i < 3 {
//Demande à l'agent qui bloque de se pousser (réitère trois fois s'il lui dit pas possible) //Demande à l'agent qui bloque de se pousser (réitère trois fois s'il lui dit pas possible)
i += 1 i += 1
fmt.Printf("[MoveAgent, %s] You have to move %s for the %d time \n", ag.id, blockingAgentID, i) //TODELETEfmt.Printf("[MoveAgent, %s] You have to move %s for the %d time \n", ag.id, blockingAgentID, i)
reqToBlockingAgent = req.NewRequest(ag.env.agentsChan[ag.id], YouHaveToMove) //Création "Hello, je suis ag.id, move." reqToBlockingAgent = req.NewRequest(ag.env.agentsChan[ag.id], YouHaveToMove) //Création "Hello, je suis ag.id, move."
ag.env.agentsChan[blockingAgentID] <- *reqToBlockingAgent //Envoi requête ag.env.agentsChan[blockingAgentID] <- *reqToBlockingAgent //Envoi requête
repFromBlockingAgent := <-ag.env.agentsChan[ag.id] //Attend la réponse repFromBlockingAgent := <-ag.env.agentsChan[ag.id] //Attend la réponse
if repFromBlockingAgent.Decision() == Done { //BlockingAgent lui a répondu Done, il s'est donc poussé if repFromBlockingAgent.Decision() == Done { //BlockingAgent lui a répondu Done, il s'est donc poussé
fmt.Printf("okay i will move agent %s \n", ag.id) //TODELETEfmt.Printf("okay i will move agent %s \n", ag.id)
accept = true accept = true
} }
} }
if !accept { if !accept {
fmt.Printf("i can't move agent %s \n", ag.id) //TODELETEfmt.Printf("i can't move agent %s \n", ag.id)
return false //il ne peut pas bouger, il s'arrête return false //il ne peut pas bouger, il s'arrête
} }
} }
...@@ -430,10 +427,10 @@ func (ag *Agent) listenForRequests() { ...@@ -430,10 +427,10 @@ func (ag *Agent) listenForRequests() {
for { for {
if ag.request == nil { if ag.request == nil {
req := <-ag.env.agentsChan[ag.id] req := <-ag.env.agentsChan[ag.id]
fmt.Printf("[listenForRequests] Request received by :%s , decision : %d \n", ag.id, req.Decision()) //TODELETEfmt.Printf("[listenForRequests] Request received by :%s , decision : %d \n", ag.id, req.Decision())
ag.request = &req ag.request = &req
if ag.request.Decision() == Expel { if ag.request.Decision() == Expel {
fmt.Println("[listenForRequests] Expel received by :", ag.id) //TODELETEfmt.Println("[listenForRequests] Expel received by :", ag.id)
} }
if ag.request != nil && (ag.request.Decision() == Disappear || ag.request.Decision() == EnterMetro) { if ag.request != nil && (ag.request.Decision() == Disappear || ag.request.Decision() == EnterMetro) {
return return
......
...@@ -48,7 +48,8 @@ func (c *Controleur) Deliberate(ag *Agent) { ...@@ -48,7 +48,8 @@ func (c *Controleur) Deliberate(ag *Agent) {
// Vérifier si la valeur de faceCase ne correspond pas au motif // Vérifier si la valeur de faceCase ne correspond pas au motif
matchedCont, err1 := regexp.MatchString(regexCont, c.faceCase) matchedCont, err1 := regexp.MatchString(regexCont, c.faceCase)
matchedFraud, err := regexp.MatchString(regexFraudeur, c.faceCase) matchedFraud, err := regexp.MatchString(regexFraudeur, c.faceCase)
//fmt.Println("faceCase : ", c.faceCase) //
//.0fmt.Println("faceCase : ", c.faceCase)
//fmt.Println("matchedAgt : ", matchedAgt) //fmt.Println("matchedAgt : ", matchedAgt)
if err != nil { if err != nil {
...@@ -102,9 +103,9 @@ func (c *Controleur) Act(ag *Agent) { ...@@ -102,9 +103,9 @@ func (c *Controleur) Act(ag *Agent) {
case Disappear: case Disappear:
ag.env.RemoveAgent(ag) ag.env.RemoveAgent(ag)
case Expel: //Expel case Expel: //Expel
agt_face_id := AgentID(c.faceCase) //id de l'agent qui se trouve devant le controleur agt_face_id := AgentID(c.faceCase) //id de l'agent qui se trouve devant le controleur
fmt.Print("L'agent ", agt_face_id, " a été expulsé \n") //TODELETEfmt.Print("L'agent ", agt_face_id, " a été expulsé \n")
ag.env.controlledAgents[agt_face_id] = true // l'agent qui se trouve devant le controleur est controlé ag.env.controlledAgents[agt_face_id] = true // l'agent qui se trouve devant le controleur est controlé
ag.env.agentsChan[agt_face_id] <- *req.NewRequest(ag.env.agentsChan[ag.id], ag.decision) // envoie la decision du controleur à l'agent qui se trouve devant lui ag.env.agentsChan[agt_face_id] <- *req.NewRequest(ag.env.agentsChan[ag.id], ag.decision) // envoie la decision du controleur à l'agent qui se trouve devant lui
//time.Sleep(500 * time.Millisecond) //time.Sleep(500 * time.Millisecond)
......
package simulation package simulation
import ( import (
"fmt"
alg "metrosim/internal/algorithms" alg "metrosim/internal/algorithms"
req "metrosim/internal/request" req "metrosim/internal/request"
"sync" "sync"
...@@ -49,7 +48,7 @@ func NewEnvironment(ags []Agent, carte [50][50]string, metros []Metro, newAgtCh ...@@ -49,7 +48,7 @@ func NewEnvironment(ags []Agent, carte [50][50]string, metros []Metro, newAgtCh
gates := make([]alg.Coord, 0) gates := make([]alg.Coord, 0)
for _, metro := range metros { for _, metro := range metros {
fmt.Println(metro.way.gates) //TODELETEfmt.Println(metro.way.gates)
for _, gate := range metro.way.gates { for _, gate := range metro.way.gates {
gates = append(gates, gate) gates = append(gates, gate)
} }
...@@ -151,11 +150,11 @@ func (env *Environment) RemoveAgent(agt *Agent) { ...@@ -151,11 +150,11 @@ func (env *Environment) RemoveAgent(agt *Agent) {
for i := borneInfRow; i < borneSupRow; i++ { for i := borneInfRow; i < borneSupRow; i++ {
for j := borneInfCol; j < borneSupCol; j++ { for j := borneInfCol; j < borneSupCol; j++ {
if len(env.station[i][j])>1{ if len(env.station[i][j]) > 1 {
env.station[i][j] = agt.isOn[alg.Coord{i, j}] env.station[i][j] = agt.isOn[alg.Coord{i, j}]
} }
alg.RemoveCoord(alg.Coord{i, j}, agt.isOn) alg.RemoveCoord(alg.Coord{i, j}, agt.isOn)
} }
} }
} }
...@@ -177,8 +176,6 @@ func (env *Environment) writeAgent(agt *Agent) { ...@@ -177,8 +176,6 @@ func (env *Environment) writeAgent(agt *Agent) {
} }
func (env *Environment) getNbAgentsAround(pos alg.Coord) int { func (env *Environment) getNbAgentsAround(pos alg.Coord) int {
//pos est la position de la porte //pos est la position de la porte
way := env.getWay(pos) way := env.getWay(pos)
...@@ -253,7 +250,6 @@ func (env *Environment) Station() [50][50]string { ...@@ -253,7 +250,6 @@ func (env *Environment) Station() [50][50]string {
return env.station return env.station
} }
func (env *Environment) getNearGateFromGate(gate Gate) []alg.Coord { func (env *Environment) getNearGateFromGate(gate Gate) []alg.Coord {
/* /*
* Renvoie les portes proches de la porte passée en paramètre * Renvoie les portes proches de la porte passée en paramètre
...@@ -268,4 +264,3 @@ func (env *Environment) getNearGateFromGate(gate Gate) []alg.Coord { ...@@ -268,4 +264,3 @@ func (env *Environment) getNearGateFromGate(gate Gate) []alg.Coord {
nearGates = append(nearGates, gate.Position) nearGates = append(nearGates, gate.Position)
return nearGates return nearGates
} }
...@@ -2,7 +2,6 @@ package simulation ...@@ -2,7 +2,6 @@ package simulation
import ( import (
"fmt" "fmt"
"log"
"math/rand" "math/rand"
alg "metrosim/internal/algorithms" alg "metrosim/internal/algorithms"
req "metrosim/internal/request" req "metrosim/internal/request"
...@@ -38,7 +37,7 @@ func NewMetro(freq time.Duration, stopT time.Duration, capacity, freeS int, way ...@@ -38,7 +37,7 @@ func NewMetro(freq time.Duration, stopT time.Duration, capacity, freeS int, way
func (metro *Metro) Start() { func (metro *Metro) Start() {
// Début de la simulation du métro // Début de la simulation du métro
log.Printf("Metro starting...\n") //TODELETElog.Printf("Metro starting...\n")
refTime := time.Now() refTime := time.Now()
//var step int //var step int
// affichage des portes au départ // affichage des portes au départ
...@@ -86,12 +85,12 @@ func (metro *Metro) pickUpGate(gate *alg.Coord, endTime time.Time, force bool) { ...@@ -86,12 +85,12 @@ func (metro *Metro) pickUpGate(gate *alg.Coord, endTime time.Time, force bool) {
agent := metro.findAgent(AgentID(gate_cell)) agent := metro.findAgent(AgentID(gate_cell))
if agent != nil && (((!force && agent.width*agent.height <= metro.freeSpace) && alg.EqualCoord(&agent.destination, gate)) || force) { if agent != nil && (((!force && agent.width*agent.height <= metro.freeSpace) && alg.EqualCoord(&agent.destination, gate)) || force) {
fmt.Println("agent entering metro : ", agent.id, "at gate ", gate) //TODELETEfmt.Println("agent entering metro : ", agent.id, "at gate ", gate)
metro.way.env.agentsChan[agent.id] <- *req.NewRequest(metro.comChannel, EnterMetro) metro.way.env.agentsChan[agent.id] <- *req.NewRequest(metro.comChannel, EnterMetro)
select { select {
case <-metro.comChannel: case <-metro.comChannel:
metro.freeSpace = metro.freeSpace - agent.width*agent.height metro.freeSpace = metro.freeSpace - agent.width*agent.height
fmt.Println("agent entered metro : ", agent.id, "at gate ", gate) //TODELETEfmt.Println("agent entered metro : ", agent.id, "at gate ", gate)
case <-time.After(2 * time.Second): case <-time.After(2 * time.Second):
// Si l'agent prend trop de temps à répondre, on le supprime "manuellement" // Si l'agent prend trop de temps à répondre, on le supprime "manuellement"
if metro.findAgent(agent.id) != nil { if metro.findAgent(agent.id) != nil {
......
...@@ -5,7 +5,6 @@ package simulation ...@@ -5,7 +5,6 @@ package simulation
*/ */
import ( import (
"fmt"
"math/rand" "math/rand"
alg "metrosim/internal/algorithms" alg "metrosim/internal/algorithms"
req "metrosim/internal/request" req "metrosim/internal/request"
...@@ -41,14 +40,14 @@ func (mr *MobiliteReduite) Deliberate(ag *Agent) { ...@@ -41,14 +40,14 @@ func (mr *MobiliteReduite) Deliberate(ag *Agent) {
ag.decision = Expel ag.decision = Expel
return return
case Disappear: case Disappear:
fmt.Println("[Deliberate]", ag.id, "Disappear cond 1 (requete)") //TODELETEfmt.Println("[Deliberate]", ag.id, "Disappear cond 1 (requete)")
ag.decision = Disappear ag.decision = Disappear
return return
case Wait: case Wait:
ag.decision = Wait ag.decision = Wait
return return
case EnterMetro: case EnterMetro:
fmt.Println("[MobiliteReduite, Deliberate] EnterMetro") //TODELETEfmt.Println("[MobiliteReduite, Deliberate] EnterMetro")
ag.decision = EnterMetro ag.decision = EnterMetro
return return
case YouHaveToMove: case YouHaveToMove:
...@@ -100,7 +99,7 @@ func (mr *MobiliteReduite) Act(ag *Agent) { ...@@ -100,7 +99,7 @@ func (mr *MobiliteReduite) Act(ag *Agent) {
//mr.MoveMR(ag) //mr.MoveMR(ag)
ag.MoveAgent() ag.MoveAgent()
case EnterMetro: case EnterMetro:
fmt.Printf("[MobiliteReduite, Act %s] EnterMetro \n", ag.id) //TODELETEfmt.Printf("[MobiliteReduite, Act %s] EnterMetro \n", ag.id)
ag.env.RemoveAgent(ag) ag.env.RemoveAgent(ag)
mr.req.Demandeur() <- *req.NewRequest(ag.env.agentsChan[ag.id], ACK) mr.req.Demandeur() <- *req.NewRequest(ag.env.agentsChan[ag.id], ACK)
} }
......
...@@ -223,15 +223,15 @@ func (simu *Simulation) Print() [][]string { ...@@ -223,15 +223,15 @@ func (simu *Simulation) Print() [][]string {
element := simu.env.station[i][j] element := simu.env.station[i][j]
if len(element) > 1 { if len(element) > 1 {
result[i][j] = element[:1] // Stocker le premier caractère si la longueur est supérieure à 1 result[i][j] = element[:1] // Stocker le premier caractère si la longueur est supérieure à 1
fmt.Print(result[i][j] + " ") //fmt.Print(result[i][j] + " ")
} else { } else {
result[i][j] = element result[i][j] = element
fmt.Print(result[i][j] + " ") //fmt.Print(result[i][j] + " ")
} }
} }
fmt.Println() //TODELETEfmt.Println()
} }
fmt.Println() //TODELETEfmt.Println()
time.Sleep(200 * time.Millisecond) // 1 fps ! time.Sleep(200 * time.Millisecond) // 1 fps !
return result return result
} }
...@@ -246,7 +246,7 @@ func (simu *Simulation) ActivateFlow() { ...@@ -246,7 +246,7 @@ func (simu *Simulation) ActivateFlow() {
for { for {
ag := &Agent{} ag := &Agent{}
ag = nil ag = nil
fmt.Println(probability) //TODELETEfmt.Println(probability)
switch { switch {
case probability < 0.1: // 10% de probabilité case probability < 0.1: // 10% de probabilité
ag = NewAgent("Normal"+fmt.Sprint(simu.env.agentCount), &simu.env, make(chan int), 200, true, &UsagerNormal{}, simu.env.entries[rand.Intn(len(simu.env.entries))], simu.env.gates[rand.Intn(len(simu.env.gates))], 1, 1) ag = NewAgent("Normal"+fmt.Sprint(simu.env.agentCount), &simu.env, make(chan int), 200, true, &UsagerNormal{}, simu.env.entries[rand.Intn(len(simu.env.entries))], simu.env.gates[rand.Intn(len(simu.env.gates))], 1, 1)
......
package simulation package simulation
import ( import (
"fmt"
"math/rand" "math/rand"
alg "metrosim/internal/algorithms" alg "metrosim/internal/algorithms"
req "metrosim/internal/request" req "metrosim/internal/request"
...@@ -22,7 +21,7 @@ func (ul *UsagerLambda) Percept(ag *Agent) { ...@@ -22,7 +21,7 @@ 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()) //TODELETEfmt.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:
...@@ -45,7 +44,7 @@ func (ul *UsagerLambda) Deliberate(ag *Agent) { ...@@ -45,7 +44,7 @@ func (ul *UsagerLambda) Deliberate(ag *Agent) {
ag.decision = Disappear ag.decision = Disappear
return return
case EnterMetro: case EnterMetro:
fmt.Println("[UsagerLambda, Deliberate] EnterMetro %s", ag.id) //TODELETEfmt.Println("[UsagerLambda, Deliberate] EnterMetro %s", ag.id)
ag.decision = EnterMetro ag.decision = EnterMetro
return return
case Wait: case Wait:
...@@ -90,12 +89,12 @@ func (ul *UsagerLambda) Act(ag *Agent) { ...@@ -90,12 +89,12 @@ func (ul *UsagerLambda) Act(ag *Agent) {
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]) //TODELETEfmt.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]) //TODELETEfmt.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]) //TODELETEfmt.Printf("[UsagerLambda, Act] J'ai bougé %s , ma position = (%d , %d)\n", ag.id, ag.position[0], ag.position[1])
case TryToMove: case TryToMove:
//fmt.Printf("Je suis %s est-ce que j'ai bougé? %t \n", ag.id, movement) //fmt.Printf("Je suis %s est-ce que j'ai bougé? %t \n", ag.id, movement)
if ag.ShiftAgent() { if ag.ShiftAgent() {
......
...@@ -7,7 +7,6 @@ package simulation ...@@ -7,7 +7,6 @@ package simulation
*/ */
import ( import (
"fmt"
"math" "math"
"math/rand" "math/rand"
alg "metrosim/internal/algorithms" alg "metrosim/internal/algorithms"
...@@ -58,11 +57,11 @@ func (un *UsagerNormal) Deliberate(ag *Agent) { ...@@ -58,11 +57,11 @@ func (un *UsagerNormal) Deliberate(ag *Agent) {
ag.decision = Move ag.decision = Move
return return
case YouHaveToMove: case YouHaveToMove:
fmt.Println("[AgentNormal, Deliberate] J'essaye de bouger ", ag.id) //TODELETEfmt.Println("[AgentNormal, Deliberate] J'essaye de bouger ", ag.id)
movement := ag.MoveAgent() movement := ag.MoveAgent()
//fmt.Printf("Je suis agent %s Resultat du mouvement de la personne %t \n", ag.id, movement) //fmt.Printf("Je suis agent %s Resultat du mouvement de la personne %t \n", ag.id, movement)
if movement { if movement {
fmt.Println("[AgentNormal, Deliberate] J'ai bougé ", ag.id) //TODELETEfmt.Println("[AgentNormal, Deliberate] J'ai bougé ", ag.id)
ag.decision = Done ag.decision = Done
} else { } else {
ag.decision = Noop ag.decision = Noop
...@@ -92,14 +91,14 @@ func (un *UsagerNormal) Act(ag *Agent) { ...@@ -92,14 +91,14 @@ func (un *UsagerNormal) Act(ag *Agent) {
//fmt.Printf("[UsagerLambda, Act] agent %s est disparu \n",ag.id) //fmt.Printf("[UsagerLambda, Act] agent %s est disparu \n",ag.id)
ag.env.RemoveAgent(ag) ag.env.RemoveAgent(ag)
case EnterMetro: case EnterMetro:
fmt.Printf("[UsagerNormal, Act] agent %s entre dans le Metro \n", ag.id) //TODELETEfmt.Printf("[UsagerNormal, Act] agent %s entre dans le Metro \n", ag.id)
ag.env.RemoveAgent(ag) ag.env.RemoveAgent(ag)
//fmt.Printf("Demandeur d'entrer le metro : %s \n",un.req.Demandeur()) //fmt.Printf("Demandeur d'entrer le metro : %s \n",un.req.Demandeur())
un.req.Demandeur() <- *req.NewRequest(ag.env.agentsChan[ag.id], ACK) un.req.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("[UsagerNormal, Act] destination de l'agent %s = %s \n", ag.id, ag.destination) //TODELETEfmt.Printf("[UsagerNormal, Act] destination de l'agent %s = %s \n", ag.id, ag.destination)
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()
...@@ -113,7 +112,7 @@ func (un *UsagerNormal) Act(ag *Agent) { ...@@ -113,7 +112,7 @@ func (un *UsagerNormal) Act(ag *Agent) {
un.req.Demandeur() <- *req.NewRequest(ag.env.agentsChan[ag.id], Done) un.req.Demandeur() <- *req.NewRequest(ag.env.agentsChan[ag.id], Done)
case TryToMove: case TryToMove:
movement := ag.MoveAgent() movement := ag.MoveAgent()
fmt.Printf("Je suis %s est-ce que j'ai bougé? %t \n", ag.id, movement) //TODELETEfmt.Printf("Je suis %s est-ce que j'ai bougé? %t \n", ag.id, movement)
if movement { if movement {
un.req.Demandeur() <- *req.NewRequest(ag.env.agentsChan[ag.id], Done) un.req.Demandeur() <- *req.NewRequest(ag.env.agentsChan[ag.id], Done)
} else { } else {
...@@ -130,7 +129,7 @@ func (un *UsagerNormal) SetUpDestination(ag *Agent) { ...@@ -130,7 +129,7 @@ func (un *UsagerNormal) SetUpDestination(ag *Agent) {
choix_voie := rand.Intn(len(ag.env.metros)) // choix de la voie de métro aléatoire choix_voie := rand.Intn(len(ag.env.metros)) // choix de la voie de métro aléatoire
dest_porte := (un.findBestGate(ag, ag.env.metros[choix_voie].way.gates)) dest_porte := (un.findBestGate(ag, ag.env.metros[choix_voie].way.gates))
ag.destination = dest_porte ag.destination = dest_porte
fmt.Println("[UsagerNormal, setUpDestination] destination de l'agent ", ag.id, " = ", ag.destination, " son position = ", ag.position) //TODELETEfmt.Println("[UsagerNormal, setUpDestination] destination de l'agent ", ag.id, " = ", ag.destination, " son position = ", ag.position)
} }
func (un *UsagerNormal) findBestGate(ag *Agent, gates []alg.Coord) alg.Coord { func (un *UsagerNormal) findBestGate(ag *Agent, gates []alg.Coord) alg.Coord {
...@@ -156,7 +155,7 @@ func (un *UsagerNormal) findBestGate(ag *Agent, gates []alg.Coord) alg.Coord { ...@@ -156,7 +155,7 @@ func (un *UsagerNormal) findBestGate(ag *Agent, gates []alg.Coord) alg.Coord {
//fmt.Println("[findBestGate] agent Position : ",ag.position) //fmt.Println("[findBestGate] agent Position : ",ag.position)
//fmt.Println("[findBestGate] gates non normalisé : ",gatesDistances) //fmt.Println("[findBestGate] gates non normalisé : ",gatesDistances)
normalizedGates, _, _ := normalizeGates(gatesDistances) normalizedGates, _, _ := normalizeGates(gatesDistances)
fmt.Println("[findBestGate, %s] gates normalisé : ",ag.id ,normalizedGates) //TODELETEfmt.Println("[findBestGate, %s] gates normalisé : ",ag.id ,normalizedGates)
bestGates := gates_with_lowest_score(normalizedGates) bestGates := gates_with_lowest_score(normalizedGates)
bestGate := bestGates[0] bestGate := bestGates[0]
......