func add_order_to_best_elev(rcvList map[rcvOrder][]rcvCost, newOrder rcvOrder) {
	if this_elevator_has_the_lowest_cost(rcvList[newOrder]) {
		//fmt.Printf("%sNew order added to floor = %d with cost = %d\n%s",def.ColB,helpFunc.Order_dir(newOrder.floor,newOrder.button),Cost(queue.Get_Orders(),helpFunc.Order_dir(newOrder.floor,newOrder.button)),def.ColN)
		queue.Set_Orders(queue.Update_orderlist(queue.Get_Orders(), queue.Order_direction(newOrder.floor, newOrder.button)))
		//fmt.Printf("%sUpdated orders = %v\n%s\n",def.ColB,queue.Get_Orders(),def.ColN)
		queue.Save_backup_to_file()
	}
}
Beispiel #2
0
func handle_new_order(buttontype, floor int, outgoingMsg chan def.Message) {
	if external_order(buttontype) && ImConnected {
		msg := def.Message{Category: def.NewOrder, Floor: floor, Button: buttontype, Cost: -1}
		outgoingMsg <- msg
	} else if !external_order(buttontype) {
		// Internal orders: if the desired floor is under the elevator it is set as a order down
		if floor == driver.Get_cur_floor() && driver.Get_dir() == 1 {
			queue.Set_Orders(queue.Update_orderlist(queue.Get_Orders(), -floor))
		} else if floor < driver.Get_cur_floor() {
			queue.Set_Orders(queue.Update_orderlist(queue.Get_Orders(), -floor))
		} else if floor == def.NumFloors-1 {
			queue.Set_Orders(queue.Update_orderlist(queue.Get_Orders(), -floor))
		} else {
			queue.Set_Orders(queue.Update_orderlist(queue.Get_Orders(), floor))
		}

		queue.Save_backup_to_file()
	}
}