optaplanner无法找到带注释的规划变量

时间:2017-03-20 12:12:26

标签: optaplanner

当解算器解决我的患者入院解决方案时,我想删除或添加一些ProblemFacts到求解器。

在optaplanner的文档中,我可以添加一些关于solver.addProblemFactChange的一些ProblemFacs,但它在我的PAS示例中不起作用。

以下是PatientAdmissionScheduleGenerator的代码片段

public void addBedDesignation(final BedDesignation bedDesignation){
    this.solver.addProblemFactChange(scoreDirector -> {
        PatientAdmissionScheduleSolution patientAdmissionScheduleSolution = scoreDirector.getWorkingSolution();
        patientAdmissionScheduleSolution.getBedDesignationList().add(bedDesignation);
    });
}

public void deleteBedDesignation(final BedDesignation bedDesignation){
    // Neues Problem dem Solver zuführen
    this.solver.addProblemFactChange(scoreDirector -> {

        // Erstelle eine neue PAS-Solution auf Basis der gerade läuft
        PatientAdmissionScheduleSolution patientAdmissionScheduleSolution  = scoreDirector.getWorkingSolution();

        // Erstelle eine neue Bettzuweisung auf Basis der
        BedDesignation workingBedDesignation = scoreDirector.lookUpWorkingObject(bedDesignation);

       for(BedDesignation designation : patientAdmissionScheduleSolution.getBedDesignationList()){
           if(designation.equals(bedDesignation)){
               scoreDirector.beforeVariableChanged(designation, "Bed");
               designation = null;
               scoreDirector.afterVariableChanged(designation,"Bed");
           }
       }

       ArrayList<BedDesignation> bedDesignationArrayList = new ArrayList<>(patientAdmissionScheduleSolution.getBedDesignationList());
       patientAdmissionScheduleSolution.setBedDesignationList(bedDesignationArrayList);
       scoreDirector.beforeProblemFactRemoved(workingBedDesignation);
       bedDesignationArrayList.remove(workingBedDesignation);
       scoreDirector.afterProblemFactRemoved(workingBedDesignation);
       scoreDirector.triggerVariableListeners();
    });
}

以下是我更改的Object BedDesignation的片段

@PlanningVariable(nullable = true, valueRangeProviderRefs = {"bedRange"}, strengthComparatorClass = BedStrengthComparator.class)
    public Bed getBed() {
        return bed;
    }

当我想删除BedDesignation对象时,这是我的错误消息

Exception in thread "main" java.lang.IllegalArgumentException: The variableName (Bed) for entityClass (class pas.entity.domain.BedDesignation) exists as a property (getter/setter) on that class, but not as an annotated as a planning variable.

检查您的计划实体的getter是否具有注释PlanningVariable(或阴影变量注释)。

我有注释床作为PlanningVariable。有什么问题?

1 个答案:

答案 0 :(得分:0)

错误消息指责错误的原因。 I created a jira.

使用“床”代替“床”。