diff --git a/internal/simulation/agent.go b/internal/simulation/agent.go index 0b61831d04a8d8c5988ccb57f9ac1466df9f03c4..09a45169216bc3ef3a216a4d1b8dc217f0d22f63 100644 --- a/internal/simulation/agent.go +++ b/internal/simulation/agent.go @@ -30,7 +30,6 @@ const ( Expel // virer l'agent Stop // arreter l'agent GiveInfos - MoveAway // déplacer l'agent qui bloque le chemin de l'agent en mobilité réduite ) type Coord [2]int diff --git a/internal/simulation/mobiliteReduite.go b/internal/simulation/mobiliteReduite.go index 079f990fc2204b4eea95131eb494e9de8f6db7af..d0a9753038ddb1981b33e375f720551118b39653 100644 --- a/internal/simulation/mobiliteReduite.go +++ b/internal/simulation/mobiliteReduite.go @@ -1,7 +1,7 @@ package simulation import ( - //"fmt" + "fmt" "sync" "math/rand" "time" @@ -19,7 +19,9 @@ type MobiliteReduite struct { */ func (mr * MobiliteReduite) setUpPath(ag *Agent) { choix_voie := rand.Intn(2) // choix de la voie de départ aléatoire + fmt.Println("[MobiliteReduite, setUpPath] choix_voie = ",choix_voie) dest_porte := ag.findNearestGate(ag.env.metros[choix_voie].way.gates) + fmt.Println("[MobiliteReduite, setUpPath] dest_porte = ",dest_porte) ag.destination = dest_porte start, end := ag.generatePathExtremities() // Recherche d'un chemin si inexistant @@ -56,15 +58,14 @@ func (mr *MobiliteReduite) Deliberate(ag *Agent) { ag.decision = Expel mr.req = nil //demande traitée } - }else if ag.position == ag.destination && (ag.isOn[ag.position] == "W" || ag.isOn[ag.position] == "S") { - //fmt.Println(ag.id, "disapear") + }else if 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 - } else if mr.faceCase != "E" && mr.faceCase != "S" && mr.faceCase != "_" && mr.faceCase != "W" && mr.faceCase != "B"{ // si l'agent est arrivé à sa destination et qu'il est sur une sortie - //si il existe un agent qui bloque son chemin - ag.decision = MoveAway - } else { - ag.decision = Move - } + } else if ag.stuck{ // si l'agent est bloqué + ag.decision = Wait + }else { + ag.decision = Move + } } func (mr *MobiliteReduite) Act(ag *Agent) { @@ -72,16 +73,12 @@ func (mr *MobiliteReduite) Act(ag *Agent) { switch ag.decision { case Move: mr.MoveMR(ag) - case MoveAway: - agt_face_id := AgentID(mr.faceCase) //id de l'agent qui se trouve devant le controleur - //fmt.Print("L'agent ", agt_face_id, " a été expulsé\n") - ag.env.agentsChan[agt_face_id] <- *NewRequest(ag.env.agentsChan[ag.id], ag.decision) // envoie la decision du controleur à l'agent qui se trouve devant lui case Wait: n := rand.Intn(2) // temps d'attente aléatoire time.Sleep(time.Duration(n) * time.Second) case Disappear: RemoveAgent(&ag.env.station, ag) - default : //Expel + case Expel : //fmt.Println("[AgentLambda, Act] Expel") ag.destination = ag.findNearestExit() //fmt.Println("[AgentLambda, Act] destination = ",ag.destination) diff --git a/internal/simulation/simu.go b/internal/simulation/simu.go index 24aa1255145709fefc172d8a6e74387526a805fe..4d0041bc9287d0560de6b1c7e99df1560f51c925 100644 --- a/internal/simulation/simu.go +++ b/internal/simulation/simu.go @@ -96,6 +96,7 @@ func NewSimulation(agentCount int, maxStep int, maxDuration time.Duration) (simu metro1 := *NewMetro(10*time.Second, 5*time.Second, 2, &simu.env, NewWay(1, []Coord{{8, 5}})) metro2 := *NewMetro(10*time.Second, 5*time.Second, 2, &simu.env, NewWay(2, []Coord{{13, 4}})) simu.metros = []Metro{metro1, metro2} + simu.env.metros = []Metro{metro1, metro2} // création des agents et des channels for i := 0; i < agentCount; i++ { @@ -108,9 +109,9 @@ func NewSimulation(agentCount int, maxStep int, maxDuration time.Duration) (simu ag := &Agent{} if i%2 == 0 { //Type Agent - id := fmt.Sprintf("Fraudeur%d", i) + id := fmt.Sprintf("MR%d", i) //NewAgent(id string, env *Environment, syncChan chan int, vitesse time.Duration, force int, politesse bool, behavior Behavior, departure, destination Coord, width, height int) - ag = NewAgent(id, &simu.env, syncChan, 200, 0, true, &UsagerLambda{}, Coord{18, 4}, Coord{13, 4}, 1, 1) + ag = NewAgent(id, &simu.env, syncChan, 200, 0, true, &MobiliteReduite{}, Coord{18, 4}, Coord{13, 4}, 1, 1) } else { // Type Controleur //id := fmt.Sprintf("Controleur%d", i) id := fmt.Sprintf("Controleur%d", i)