Hi all,
I am new bee to drool planner, and I am able to run couldbalancing
example,and now i am try to develop my own example.
Problem::::
I have shift and employee i would like to employee whose prefferdShift is
equal to the shiftType.So that I was create domain classes as follow
Shift--------planning entity class
Employee
EmployeeRoster -----Solution class
=====================================Shift.java====================
package com.drools.planner.domain;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.drools.planner.api.domain.entity.PlanningEntity;
import org.drools.planner.api.domain.solution.PlanningEntityProperty;
import org.drools.planner.api.domain.variable.PlanningVariable;
import org.drools.planner.api.domain.variable.ValueRange;
import org.drools.planner.api.domain.variable.ValueRangeType;
import com.drools.planner.comparator.EmployeeStrenghtComparator;
import com.drools.planner.comparator.ShiftDifficultyComparator;
@PlanningEntity(difficultyComparatorClass = ShiftDifficultyComparator.class)
public class Shift {
private int id;
private String shiftType;
//employee is plannign entity variable
private Employee employee;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getShiftType() {
return shiftType;
}
public void setShiftType(String shiftType) {
this.shiftType = shiftType;
}
public String getPrefferdShift()
{
return employee.getPrefferedShift();
}
@SuppressWarnings("restriction")
@PlanningVariable(strengthComparatorClass=EmployeeStrenghtComparator.class)
@ValueRange(type=ValueRangeType.FROM_SOLUTION_PROPERTY,solutionProperty="employeeList")
public Employee getEmployee() {
return employee;
}
public void setEmployee(Employee employee) {
this.employee = employee;
}
public Shift clone()
{
Shift clone=new Shift();
clone.employee=employee;
clone.id=id;
clone.shiftType=shiftType;
return clone;
}
public boolean SolutionEquals(Object o)
{
if(this==o)
{
return true;
}else if(this instanceof Shift)
{
Shift other =new Shift();
return new EqualsBuilder()
.append(id, other.id)
.append(employee, other.employee)
.append(shiftType,other.shiftType).isEquals();
}else
{
return false;
}
}
public int solutionHashCode() {
return new HashCodeBuilder()
.append(id)
.append(employee)
.toHashCode();
}
}
===============================Employee.java===================
package com.drools.planner.domain;
public class Employee {
private int id;
private String name;
private String prefferedShift;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPrefferedShift() {
return prefferedShift;
}
public void setPrefferedShift(String prefferedShift) {
this.prefferedShift = prefferedShift;
}
}
=================================EmployeeRoster.java==========================
package com.drools.planner.domain;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import
org.drools.planner.api.domain.solution.PlanningEntityCollectionProperty;
import org.drools.planner.core.score.buildin.hardandsoft.HardAndSoftScore;
import org.drools.planner.core.solution.Solution;
public class EmployeeRoster implements Solution<HardAndSoftScore> {
private int id;
private List<Shift> shiftList;
private List<Employee> employeeList;
private HardAndSoftScore score;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@PlanningEntityCollectionProperty
public List<Shift> getShiftList() {
return shiftList;
}
public void setShiftList(List<Shift> shiftList) {
this.shiftList = shiftList;
}
public List<Employee> getEmployeeList() {
return employeeList;
}
public void setEmployeeList(List<Employee> employeeList) {
this.employeeList = employeeList;
}
@Override
public EmployeeRoster cloneSolution() {
EmployeeRoster employeeRoster=new EmployeeRoster();
employeeRoster.id=id;
employeeRoster.shiftList=shiftList;
employeeRoster.employeeList=employeeList;
employeeRoster.score=score;
return employeeRoster;
}
@Override
public Collection<? extends Object> getProblemFacts() {
ArrayList face=new ArrayList();
face.add(shiftList);
return face;
}
@Override
public HardAndSoftScore getScore() {
return score;
}
@Override
public void setScore(HardAndSoftScore score) {
this.score=score;
}
}
========================my rule file is====================
//created on: Aug 31, 2012
package com.drool.planner.resourse
//list any import classes here.
dialect "java"
import
org.drools.planner.core.score.buildin.hardandsoft.HardAndSoftScoreHolder;
import org.drools.planner.core.score.constraint.IntConstraintOccurrence;
import org.drools.planner.core.score.constraint.ConstraintType;
import com.drools.planner.domain.Shift;
import com.drools.planner.domain.Employee;
//declare any global variables here
global HardAndSoftScoreHolder scoreHolder;
rule "requireEmployeeShift"
when
$e:Employee($prefferedShift:prefferedShift)
exists Shift(employee==$e && shiftType==$prefferedShift)
then
insertLogical(new IntConstraintOccurrence("periodDurationTooShort",
ConstraintType.NEGATIVE_HARD,
1));
end
rule "hardConstraintsBroken"
salience -1 // Do the other rules first (optional, for performance)
when
$hardTotal : Number() from accumulate(
IntConstraintOccurrence(constraintType ==
ConstraintType.NEGATIVE_HARD, $weight : weight),
sum($weight) // Vote for
http://jira.jboss.com/jira/browse/JBRULES-1075
)
then
scoreHolder.setHardConstraintsBroken($hardTotal.intValue());
end
=======================================================================
when I run my application I dose not get proper output
Shift ID Shift Type Employee Preffered Shift
0 night sachin night
1 evening shahid morning
2 morning shahid morning
please give me some hint about this problem
--
View this message in context:
http://drools.46999.n3.nabble.com/Does-not-assign-employee-to-shift-in-dr...
Sent from the Drools: Developer (committer) mailing list mailing list archive at
Nabble.com.