Skip to content
Snippets Groups Projects
Commit 58dbb9d3 authored by Yousra Hassan's avatar Yousra Hassan
Browse files

phase test

parent 617eaadc
No related branches found
No related tags found
1 merge request!14Merge v2
......@@ -6,7 +6,7 @@ import (
)
func main() {
s := simulation.NewSimulation(10, -1, 600*time.Second)
s := simulation.NewSimulation(4, -1, 600*time.Second)
//go simulation.StartAPI(s)
s.Run()
}
......@@ -9,6 +9,7 @@ package simulation
*/
import (
"fmt"
"log"
"math/rand"
alg "metrosim/internal/algorithms"
......@@ -257,15 +258,18 @@ func (ag *Agent) MoveAgent() bool {
for !accept && i < 3 {
//Demande à l'agent qui bloque de se pousser (réitère trois fois s'il lui dit pas possible)
i += 1
fmt.Printf("You have to move %s for the %d time \n", blockingAgentID, i)
reqToBlockingAgent = NewRequest(ag.env.agentsChan[ag.id], YouHaveToMove) //Création "Hello, je suis ag.id, move."
ag.env.agentsChan[blockingAgentID] <- *reqToBlockingAgent //Envoi requête
repFromBlockingAgent = <-ag.env.agentsChan[blockingAgentID] //Attend la réponse
if repFromBlockingAgent.decision == 5 { //BlockingAgent lui a répondu Done, il s'est donc poussé
fmt.Printf("okay i will move agent %s \n", ag.id)
accept = true
}
}
if !accept {
fmt.Printf("i can't move agent %s \n", ag.id)
return false //il ne peut pas bouger, il s'arrête
}
}
......
......@@ -99,15 +99,12 @@ func NewSimulation(agentCount int, maxStep int, maxDuration time.Duration) (simu
// création des agents et des channels
for i := 0; i < agentCount; i++ {
// création de l'agent
syncChan := make(chan int)
//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{18, 4}, Coord{0, 8}, 2, 1)
id := fmt.Sprintf("Agent%d", i)
ag := &Agent{}
if i%2 == 0 { //Type Agent
/*if i%2 == 0 { //Type Agent
id := fmt.Sprintf("Agent%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, false, &UsagerLambda{}, Coord{18, 4}, Coord{13, 4}, 1, 1)
......@@ -116,9 +113,13 @@ func NewSimulation(agentCount int, maxStep int, maxDuration time.Duration) (simu
id := fmt.Sprintf("Agent%d", i)
ag = NewAgent(id, &simu.env, syncChan, 200, 0, true, &UsagerLambda{}, Coord{1, 8}, Coord{8, 5}, 1, 1)
//ag = NewAgent(id, &simu.env, syncChan, 1000, 0, true, &Controleur{}, Coord{18, 12}, Coord{18, 4}, 1, 1)
}
}*/
//ag := NewAgent(id, &simu.env, syncChan, 1000, 0, true, &UsagerLambda{}, Coord{19, 12}, Coord{0, 8}, 2, 1)
if i != 2 {
ag = NewAgent(id, &simu.env, syncChan, 200, 0, false, &UsagerLambda{}, Coord{18, 4}, Coord{13, 4}, 1, 1)
} else {
ag = NewAgent(id, &simu.env, syncChan, 200, 0, true, &UsagerLambda{}, Coord{18, 4}, Coord{13, 4}, 1, 1)
}
// ajout de l'agent à la simulation
simu.agents = append(simu.agents, *ag)
......
......@@ -15,7 +15,7 @@ type UsagerLambda struct {
func (ul *UsagerLambda) Percept(ag *Agent) {
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")
print("Requete recue par %d : %d", ag.id, ag.request.decision, "\n")
ul.req = *ag.request
default:
ag.stuck = ag.isStuck()
......@@ -38,11 +38,13 @@ func (ul *UsagerLambda) Deliberate(ag *Agent) {
} else if ul.req.decision == Wait {
ag.decision = Wait
} else if ul.req.decision == YouHaveToMove {
fmt.Println("J'essaye de bouger")
movement := ag.MoveAgent()
fmt.Printf("Je suis agent %s Resultat du mouvement de la personne %t \n", ag.id, movement)
if movement {
ag.decision = 5
ag.decision = Done
} else {
ag.decision = 0
ag.decision = Noop
}
} else {
ag.decision = Move
......
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