Skip to content
Snippets Groups Projects
Commit a5d3eb7d authored by julienpillis's avatar julienpillis
Browse files

ajout passages multiples

parent fc8060d4
No related branches found
No related tags found
3 merge requests!14Merge v2,!12Metro,!11Metro
......@@ -2,6 +2,7 @@ package simulation
import (
"log"
"math/rand"
"time"
)
......@@ -12,9 +13,10 @@ type Metro struct {
gates []Coord //listes des portes du métro
env *Environment
comChannel chan Request
way WayID
}
func NewMetro(freq time.Duration, stopT time.Duration, freeS int, gates []Coord, env *Environment) *Metro {
func NewMetro(freq time.Duration, stopT time.Duration, freeS int, gates []Coord, env *Environment, wayNumber WayID) *Metro {
return &Metro{
frequency: freq,
stopTime: stopT,
......@@ -22,6 +24,7 @@ func NewMetro(freq time.Duration, stopT time.Duration, freeS int, gates []Coord,
gates: gates,
env: env,
comChannel: make(chan Request),
way: wayNumber,
}
}
......@@ -33,8 +36,8 @@ func (metro *Metro) Start() {
for {
//step = <-metro.syncChan
if refTime.Add(metro.frequency).Before(time.Now()) {
//defer func() { refTime = time.Now() }()
go metro.pickUpUsers()
metro.freeSpace = rand.Intn(5)
//go metro.dropUsers()
refTime = time.Now()
}
......@@ -61,7 +64,7 @@ func (metro *Metro) pickUpGate(gate *Coord) {
gate_cell := metro.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 {
if agent != nil && agent.width*agent.height <= metro.freeSpace && agent.destination == *gate {
metro.env.agentsChan[agent.id] <- *NewRequest(metro.comChannel, Disappear)
metro.freeSpace--
}
......
......@@ -87,9 +87,13 @@ func NewSimulation(agentCount int, maxStep int, maxDuration time.Duration) (simu
// Communication entre agents
mapChan := make(map[AgentID]chan Request)
// Création de l'environement
simu.env = *NewEnvironment([]Agent{}, carte, mapChan)
//simu.env = *NewEnvironment([]Agent{}, playground, mapChan)
simu.metro = *NewMetro(10*time.Second, 5*time.Second, 2, []Coord{{8, 5}}, &simu.env)
// Création du métro
simu.metro = *NewMetro(10*time.Second, 5*time.Second, 2, []Coord{{8, 5}}, &simu.env, 1)
// création des agents et des channels
for i := 0; i < agentCount; i++ {
......
package simulation
type Way struct {
id WayID
gates []Coord //listes des portes du métro
}
type WayID int
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