diff --git a/internal/simulation/agent.go b/internal/simulation/agent.go index 20d6871c49227c7492bcde4122cc439879bd54ac..a9af413195bb30620b1b8d6dad33f642508dcf03 100644 --- a/internal/simulation/agent.go +++ b/internal/simulation/agent.go @@ -13,6 +13,7 @@ import ( //"fmt" //"fmt" "log" + "math/rand" //"math" //"math/rand" @@ -216,12 +217,12 @@ func (ag *Agent) MoveAgent() { // ================== Etude de faisabilité ======================= if IsAgentBlocking(ag.path, ag, ag.env) { // TODO:voir comment gérer les situations de blocage - // start, end := ag.generatePathExtremities() - // // 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 := alg.FindPath(ag.env.station, start, end, ag.path[0], false) - // time.Sleep(time.Second) - // ag.path = path + start, end := ag.generatePathExtremities() + // 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 := alg.FindPath(ag.env.station, start, end, ag.path[0], false) + time.Sleep(time.Second) + ag.path = path } safe, or := IsMovementSafe(ag.path, ag, ag.env) if safe { diff --git a/internal/simulation/simu.go b/internal/simulation/simu.go index 965f6a6821487a33c9b8535ca8aff28e04f4128d..b0e50637551c5cec93a2edc76118dd150909b94f 100644 --- a/internal/simulation/simu.go +++ b/internal/simulation/simu.go @@ -151,7 +151,7 @@ func NewSimulation(agentCount int, maxStep int, maxDuration time.Duration) (simu //ag := NewAgent(id, &simu.env, syncChan, time.Duration(time.Second), 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, 1000, 0, true, &UsagerLambda{}, Coord{3, 4}, Coord{18, 12}, 2, 1) - ag := NewAgent(id, &simu.env, syncChan, 1000, 0, true, &UsagerLambda{}, Coord{18, 4}, Coord{1, 8}, 2, 1) + ag := NewAgent(id, &simu.env, syncChan, 1000, 0, true, &UsagerLambda{}, Coord{18, 4}, Coord{1, 8}, 1, 1) //ag := NewAgent(id, &simu.env, syncChan, 1000, 0, true, &UsagerLambda{}, Coord{1, 17}, Coord{0, 0}, 2, 1) // ajout de l'agent à la simulation