コード例 #1
0
//This function return orders the elevator should stop for
func Stop(myip string, mystate string) []Network.Request {
	var takerequest []Network.Request
	requestlist := Network.GetRequestList()
	for _, request := range requestlist {
		if (request.Direction == Elevator.BUTTON_COMMAND && request.Source == myip) || (request.Direction == Elevator.BUTTON_CALL_UP && mystate == "UP") || (request.Direction == Elevator.BUTTON_CALL_DOWN && mystate == "DOWN") {
			if request.Floor == Elevator.CurrentFloor() && Elevator.AtFloor() {
				takerequest = append(takerequest, request)
			}
		}
	}
	return takerequest
}
コード例 #2
0
// Nextrequest will provide the best elevator for each request, using the three above functions
func Nextrequest(localip string, Elevatorlist []extra.Elevator) Network.Request {
	var statelist = make(map[string]Network.Info)
	infolist := Network.GetInfoList()
	for host, info := range infolist {
		statelist[host] = info
	}
	requestlist := Network.GetRequestList()

loop:
	for _, request := range requestlist {
		if !InternalOrExternal(request) {
			go Externalrequest(localip, Elevatorlist, request)
			return externalrequest
			continue loop
		} else {
			go Internalrequest(localip, Elevatorlist, request)
			return internalrequest
			continue loop
		}
	}
	return Network.NoRequest[0]
}
コード例 #3
0
//This function does a BFS-search through all orders to find the most effective solution
func Nextrequest(myip string, Elevatorlist []misc.Elevator) Network.Request {
	var statelist = make(map[string]Network.Info)
	infolist := Network.GetInfoList()
	for host, info := range infolist {
		statelist[host] = info
	}
	requestlist := Network.GetRequestList()
insideloop:
	for _, request := range requestlist {
		if request.Direction != Elevator.BUTTON_COMMAND {
			continue insideloop
		}
		for _, elevator := range Elevatorlist {
			if info, ok := statelist[Elevator.Address]; ok {
				if ((info.State == "UP" || info.State == "IDLE") && info.LastFloor <= request.Floor) || ((info.State == "DOWN" || info.State == "IDLE") && info.LastFloor >= request.Floor) {
					if info.Source == request.Source {
						if info.Source == myip {
							return request
						} else {
							delete(statelist, Elevator.Address)
							continue insideloop
						}
					}
				}
			}
		}
		for _, elevator := range Elevatorlist {
			if info, ok := statelist[Elevator.Address]; ok {
				if (info.State == "UP" && info.LastFloor >= request.Floor) || (info.State == "DOWN" && info.LastFloor <= request.Floor) {
					if info.Source == request.Source {
						if info.Source == myip {
							return request
						} else {
							delete(statelist, Elevator.Address)
							continue insideloop
						}
					}
				}
			}
		}
	}
requestloop:
	for _, request := range requestlist {
		if request.Direction == Elevator.BUTTON_COMMAND {
			continue requestloop
		}
		for i := 0; i < Elevator.N_FLOORS; i++ {
			for _, elevator := range Elevatorlist {
				if info, ok := statelist[Elevator.Address]; ok {
					if i != 0 && (info.State == "UP" && info.LastFloor+i == request.Floor) || (info.State == "DOWN" && info.LastFloor-i == request.Floor) {
						if statelist[Elevator.Address].Source == myip {
							return request
						} else {
							delete(statelist, Elevator.Address)
							continue requestloop
						}
					}
				}
			}
			for _, elevator := range Elevatorlist {
				if info, ok := statelist[Elevator.Address]; ok {
					if info.State == "IDLE" && (info.LastFloor == request.Floor+i || info.LastFloor == request.Floor-i) {
						if statelist[Elevator.Address].Source == myip {
							return request
						} else {
							delete(statelist, Elevator.Address)
							continue requestloop
						}
					}
				}
			}
		}
	}
	return Network.EmptyRequest[0]
}