Skip to content

Commit

Permalink
fix reassignment to stuck elevator
Browse files Browse the repository at this point in the history
  • Loading branch information
haavardsyslak committed Mar 9, 2024
1 parent 140afef commit 69e8f52
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Network-go
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func main() {
elevatorToNetworkCh := make(chan elevator.Elevator, 1000)
elevatorFromNetworkCh := make(chan elevator.Elevator, 1000)


go packethandler.HandleElevatorPackets(id,
elevatorToNetworkCh,
elevatorFromNetworkCh,
Expand All @@ -44,8 +45,8 @@ func main() {
go bcast.Transmitter(16569, elevatorTxCh)
go bcast.Receiver(16569, elevatorRxCh)

go peers.PeerUpdateListener(peerUpdateCh, connectedPeersCh, lostPeersCh)

go peers.PeerUpdateListener(peerUpdateCh, connectedPeersCh, lostPeersCh)


e := elevator.New(id)
Expand Down
11 changes: 4 additions & 7 deletions packethandler/packethandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,13 @@ func HandleElevatorPackets(thisId string,
continue
}

elevators[packet.Elevator.Id] = packet.Elevator

if packet.SenderID == thisId && len(connectedPeers) <= 1 {
elevatorUpdateFromNetworkCh <- elevator
} else if packet.SenderID != thisId && isElevatorAlive(connectedPeers, packet.Elevator.Id) {
elevators[packet.Elevator.Id] = elevator
if (packet.Elevator.Id == thisId || isElevatorAlive(connectedPeers, packet.Elevator.Id)) && packet.SenderID != thisId {
elevatorUpdateFromNetworkCh <- elevator
}
case connectedPeers = <- connectedPeersCh:
}
}
}
}
}

func isElevatorAlive(elevators []string, elevatorId string) bool {
Expand Down
20 changes: 10 additions & 10 deletions request_assigner/request_assigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,16 @@ func DistributeRequests(thisElevator elevator.Elevator,
elevatorToNetwork <- e

case e := <-elevatorFromNetwork:
if e.Id == thisId {
requestUpdateCh <- e.Requests
}
elevators[e.Id] = e
e.Requests = requests.MergeHallRequests(elevators)
elevator.SetHallLights(e)
if len(elevators) == 1 {
requestUpdateCh <- e.Requests
}
fmt.Println("mau")
if e.Id == thisId {
requestUpdateCh <- e.Requests
}
elevators[e.Id] = e
e.Requests = requests.MergeHallRequests(elevators)
elevator.SetHallLights(e)
if len(elevators) == 1 {
requestUpdateCh <- e.Requests
}

case lostElevators := <- lostElevatorsCh:
// Reassign the lost elevators requests
Expand Down Expand Up @@ -178,7 +179,6 @@ func TimeToIdle(e_sim elevator.Elevator) float32 {
func AssignRequest(elevators map[string]elevator.Elevator,
order elevator.Order) elevator.Elevator {
if order.Type == elevio.BT_Cab {
fmt.Println("CAB REQ")
e := elevators[thisId]
e.Requests = requests.UpdateRequests(order, e.Requests)
return e
Expand Down

0 comments on commit 69e8f52

Please sign in to comment.