public static void main(String[] args) {
String t = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<solver>"
+ " <solutionClass>com.swa.planner.domain.Distributor</solutionClass>"
+ " <planningEntityClass>com.swa.planner.domain.Engineer</planningEntityClass>"
+ " <scoreDirectorFactory>"
+ " <scoreDefinitionType>HARD_AND_SOFT</scoreDefinitionType>"
+ " <scoreDrl>/com/swa/planner/domain/rule/distributorScoreRules.drl</scoreDrl>"
+ " </scoreDirectorFactory>"
// + " <termination>"
// + " <maximumSecondsSpend>120</maximumSecondsSpend>"
// + " </termination>"
+ " <constructionHeuristic>"
+ " <constructionHeuristicType>FIRST_FIT_DECREASING</constructionHeuristicType>"
+ " <constructionHeuristicPickEarlyType>FIRST_LAST_STEP_SCORE_EQUAL_OR_IMPROVING</constructionHeuristicPickEarlyType>"
+ " </constructionHeuristic>"
+ " <localSearch>"
+ " <acceptor>"
+ " <planningEntityTabuSize>7</planningEntityTabuSize>"
+ " </acceptor>"
+ " <forager>"
+ " <minimalAcceptedSelection>1000</minimalAcceptedSelection>"
+ " </forager>" + " </localSearch>" + "</solver>";
byte b[] = t.getBytes();
ByteArrayInputStream bt = new ByteArrayInputStream(b);
SolverFactory solverFactory = new XmlSolverFactory().configure(bt);
Solver solver = solverFactory.buildSolver();
List<Engineer> engineerList = new ArrayList<Engineer>();
engineerList.add(new Engineer(1L, "Aladin", 8));
engineerList.add(new Engineer(2L, "Chuck Norris", 8));
engineerList.add(new Engineer(3L, "Rambo", 8));
engineerList.add(new Engineer(4L, "Mr. Miyagi", 8));
engineerList.add(new Engineer(5L, "Monkey D. Ruffy", 8));
List<WorkOrder> workOrderList = new ArrayList<WorkOrder>();
workOrderList.add(new WorkOrder(6L, 1, 2));
workOrderList.add(new WorkOrder(7L, 1, 6));
workOrderList.add(new WorkOrder(8L, 1, 3));
workOrderList.add(new WorkOrder(9L, 1, 3));
workOrderList.add(new WorkOrder(10L, 1, 2));
workOrderList.add(new WorkOrder(11L, 1, 8));
workOrderList.add(new WorkOrder(12L, 1, 8));
workOrderList.add(new WorkOrder(13L, 1, 2));
workOrderList.add(new WorkOrder(14L, 1, 2));
workOrderList.add(new WorkOrder(15L, 1, 4));
Distributor distributor = new Distributor();
distributor.setId(0L);
distributor.setEngineerList(engineerList);
distributor.setWorkOrderList(workOrderList);
solver.setPlanningProblem(distributor);
solver.solve();
Distributor solvedWorkOrderDistribution = (Distributor) solver.getBestSolution();
System.out.printf("\nSolved distribution with %d work orders and %d engineers:\n%s",
workOrderList.size(), engineerList.size(),
toDisplayString(solvedWorkOrderDistribution));
}
public static String toDisplayString(Distributor distributor) {
StringBuilder displayString = new StringBuilder();
for (Engineer engineer : distributor.getEngineerList()) {
WorkOrder order = engineer.getWorkOrder();
displayString.append(" ").append(engineer.getLabel()).append(" : ")
.append(order == null ? null : order.getLabel())
.append("\n");
}
return displayString.toString();
}