Exemple #1
0
func set_direction(order, curFloor int) {
	if (math.Abs(float64(order)) - float64(curFloor)) != 0 {
		//difference between cur floor and desired floor divided with abs(difference) gives direction = -1 or 1
		dir := (math.Abs(float64(order)) - float64(curFloor)) / (float64(helpFunc.Difference_abs(order, curFloor)))
		driver.Set_motor_dir(int(dir))
		driver.Set_dir(int(dir))
	}
}
func Cost(orderlist []int, newOrder int) int {
	new_orderlist := queue.Update_orderlist(orderlist, newOrder)
	index := helpFunc.Get_index(new_orderlist, newOrder)

	// Cost is initially the distance to first floor in list
	var cost = helpFunc.Difference_abs(driver.Get_cur_floor(), newOrder)

	// For every order in orderlist, the difference between two orders is
	// added to the cost
	if len(orderlist) > 0 {
		cost = helpFunc.Difference_abs(driver.Get_cur_floor(), orderlist[0])
		for i := 0; i < index-1; i++ {
			cost += helpFunc.Difference_abs(orderlist[i], orderlist[i+1])
		}
	}
	// The cost is penalized by the number of orders in the queue
	return int(cost) + 2*len(queue.Get_Orders())
}