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

corriger_dest_usager_lambda

parent a378b9da
No related branches found
No related tags found
1 merge request!14Merge v2
......@@ -86,6 +86,7 @@ func (metro *Metro) pickUpGate(gate *alg.Coord, endTime time.Time) {
gate_cell := metro.way.env.station[gate[0]][gate[1]]
if len(gate_cell) > 1 {
agent := metro.findAgent(AgentID(gate_cell))
if agent != nil && agent.width*agent.height <= metro.freeSpace && alg.EqualCoord(&agent.destination, gate) {
fmt.Println("agent entering metro : ", agent.id, "at gate ", gate)
metro.way.env.agentsChan[agent.id] <- *req.NewRequest(metro.comChannel, EnterMetro)
......
......@@ -7,15 +7,16 @@ import (
alg "metrosim/internal/algorithms"
req "metrosim/internal/request"
"time"
//"sync"
"sync"
)
type UsagerLambda struct {
req *req.Request
once sync.Once
}
func (ul *UsagerLambda) Percept(ag *Agent) {
//ul.once.Do(func(){ul.setUpDestination(ag)}) // la fonction setUp est executé à la premiere appel de la fonction Percept()
ul.once.Do(func(){ul.setUpAleaDestination(ag)}) // la fonction setUp est executé à la premiere appel de la fonction Percept()
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
//print("Requete recue par l'agent lambda : ", ag.request.decision, "\n")
......@@ -40,6 +41,7 @@ func (ul *UsagerLambda) Deliberate(ag *Agent) {
case Disappear :
ag.decision = Disappear
case EnterMetro :
fmt.Println("[UsagerLambda, Deliberate] EnterMetro")
ag.decision = EnterMetro
case Wait :
ag.decision = Wait
......@@ -58,6 +60,7 @@ func (ul *UsagerLambda) Deliberate(ag *Agent) {
ag.decision = Move
}
ul.req = nil //demande traitée
}else if (ag.position != ag.departure && 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
......@@ -81,7 +84,9 @@ func (ul *UsagerLambda) Act(ag *Agent) {
case Disappear:
ag.env.RemoveAgent(ag)
case EnterMetro :
fmt.Printf("[UsagerLambda, Act] agent %s entre dans le Metro \n",ag.id)
ag.env.RemoveAgent(ag)
fmt.Printf("Demandeur d'entrer le metro : %s \n",ag.request.Demandeur())
ul.req.Demandeur() <- *req.NewRequest(ag.env.agentsChan[ag.id], ACK)
case Expel :
//fmt.Println("[AgentLambda, Act] Expel")
......@@ -109,3 +114,9 @@ func (ul *UsagerLambda) Act(ag *Agent) {
}
}
func (ul *UsagerLambda)setUpAleaDestination(ag *Agent){
choix_voie := rand.Intn(2) // choix de la voie de métro aléatoire
dest_porte := rand.Intn(len(ag.env.metros[choix_voie].way.gates)) // choix de la porte de métro aléatoire
ag.destination = ag.env.metros[choix_voie].way.gates[dest_porte]
}
\ 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