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

removeMoveAway, add metros to env

parent dd47e304
No related branches found
No related tags found
1 merge request!14Merge v2
......@@ -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
......
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)
......
......@@ -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)
......
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