Job scheduling using standard Java libraries
As mentioned in the tags, this is homework, using only standard java libraries.
The task is to create a program that schedules orders (which consist of pizzas) to开发者_JAVA技巧 be cooked in different ovens. Orders have a dealine, which must be met and pizzas have a cook time and a cooldown time, inherently all pizzas must be cooked by the deadline but cannot be cooked so early that their time out of the oven exceeds the cooldown time. If it is determined that it is not possible to fulfil the order by the deadline an exception is thrown. The main problem I cannot get my head around is how would I make the program reschedule the ovens to fit a new order in.
I cannot think of how to start this and would really appreciate any help!
A good place to start is to turn that middle paragraph into objects with behavior and state defied, eg
class Order
List<Pizza> pizzas;
class Oven
int maxPizzas;
List<Pizza> cooking;
cook(pizza: Pizza);
class Pizza
int cookTimeMins;
int coolTimeMins;
long cookTimeStart;
class PizzaShop
List<Oven> ovens;
List<Order> orders;
scheduleOrder(order: Order) throws Exception
From there start pseudo coding what you want to happen in the various methods. Start with those building blocks and you will find the problem becomes easier to solve when not looking at the problem as a whole, but in small chunks.
You can start reading earliest deadline first scheduling.
It seem that your pizza processing time (cook + cool + etc.) can be calculated beforehand, so PriorityQueue could be helpful. The PizzaOrder would implement Comparable interface, which compares the deadline of the order.
It is hard to know with the information you provide, but it seems it could be a good scenario to use a rule engine such as JBoss Rules (Drools), if you want to experiment with it.
精彩评论