OptaPlanner/TimeFold – FullAssert mode exception and constraint explanation

I am currently working on a project that requires scheduling tasks to resources while minimizing travel time between tasks assigned to the same resource. There are additional constraints, but this is the main objective.

I am running OptaPlanner in FULL_ASSERT mode and encountering the following exception:

Score corruption analysis:   The corrupted scoreDirector has 7 ConstraintMatch(s) which are in excess (and should not be there):
com.optimization.fm.policy.scheduler.infrastucture.constraint/First assignment as early as possible/[Task ID: d7e5f8a3-73b9-4f6c-9b12-96f4e13b70e0 | Res: 2 | Start: 2024-06-18T10:00 | End: 2024-06-18T12:00, [Task ID: d7e5f8a3-73b9-4f6c-9b12-96f4e13b70e0 | Res: 2 | Start: 2024-06-18T10:00 | End: 2024-06-18T12:00, Task ID: 731c791d-7ea6-476b-afc7-77c632e062c7 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:00, Task ID: 73abb022-924f-40ac-a848-2a73ee7a0ab4 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:30]]=0hard/0medium/-8100soft
com.optimization.fm.policy.scheduler.infrastucture.constraint/First assignment as early as possible/[Task ID: 731c791d-7ea6-476b-afc7-77c632e062c7 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:00, [Task ID: d7e5f8a3-73b9-4f6c-9b12-96f4e13b70e0 | Res: 2 | Start: 2024-06-18T10:00 | End: 2024-06-18T12:00, Task ID: 731c791d-7ea6-476b-afc7-77c632e062c7 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:00, Task ID: 73abb022-924f-40ac-a848-2a73ee7a0ab4 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:30]]=0hard/0medium/-8100soft
com.optimization.fm.policy.scheduler.infrastucture.constraint/First assignment as early as possible/[Task ID: 73abb022-924f-40ac-a848-2a73ee7a0ab4 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:30, [Task ID: d7e5f8a3-73b9-4f6c-9b12-96f4e13b70e0 | Res: 2 | Start: 2024-06-18T10:00 | End: 2024-06-18T12:00, Task ID: 731c791d-7ea6-476b-afc7-77c632e062c7 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:00, Task ID: 73abb022-924f-40ac-a848-2a73ee7a0ab4 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:30]]=0hard/0medium/-8100soft
com.optimization.fm.policy.scheduler.infrastucture.constraint/MatchSkill/[CheckPolicyCommand[assignmentId=73abb022-924f-40ac-a848-2a73ee7a0ab4, task=Task{id=73abb022-924f-40ac-a848-2a73ee7a0ab4}, resource=Resource{id=2}, interval=Interval[startDateTime=2024-06-18T09:30, endDateTime=2024-06-18T10:30], travelTime=TravelTime[startDateTime=2024-06-18T09:30, endDateTime=2024-06-18T09:30, duration=0], travelTimeToHomeBase=null, dependsOnAssignments=[]]]=-1hard/0medium/0soft
com.optimization.fm.policy.scheduler.infrastucture.constraint/Minimize resource travel time/[Task ID: d7e5f8a3-73b9-4f6c-9b12-96f4e13b70e0 | Res: 2 | Start: 2024-06-18T10:00 | End: 2024-06-18T12:00, [Task ID: d7e5f8a3-73b9-4f6c-9b12-96f4e13b70e0 | Res: 2 | Start: 2024-06-18T10:00 | End: 2024-06-18T12:00, Task ID: 731c791d-7ea6-476b-afc7-77c632e062c7 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:00, Task ID: 73abb022-924f-40ac-a848-2a73ee7a0ab4 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:30]]=0hard/0medium/-365soft
com.optimization.fm.policy.scheduler.infrastucture.constraint/Minimize resource travel time/[Task ID: 731c791d-7ea6-476b-afc7-77c632e062c7 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:00, [Task ID: d7e5f8a3-73b9-4f6c-9b12-96f4e13b70e0 | Res: 2 | Start: 2024-06-18T10:00 | End: 2024-06-18T12:00, Task ID: 731c791d-7ea6-476b-afc7-77c632e062c7 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:00, Task ID: 73abb022-924f-40ac-a848-2a73ee7a0ab4 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:30]]=0hard/0medium/-365soft
com.optimization.fm.policy.scheduler.infrastucture.constraint/Minimize resource travel time/[Task ID: 73abb022-924f-40ac-a848-2a73ee7a0ab4 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:30, [Task ID: d7e5f8a3-73b9-4f6c-9b12-96f4e13b70e0 | Res: 2 | Start: 2024-06-18T10:00 | End: 2024-06-18T12:00, Task ID: 731c791d-7ea6-476b-afc7-77c632e062c7 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:00, Task ID: 73abb022-924f-40ac-a848-2a73ee7a0ab4 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:30]]=0hard/0medium/-365soft   The corrupted scoreDirector has 7 ConstraintMatch(s) which are missing:
com.optimization.fm.policy.scheduler.infrastucture.constraint/First assignment as early as possible/[Task ID: d7e5f8a3-73b9-4f6c-9b12-96f4e13b70e0 | Res: 2 | Start: 2024-06-18T10:00 | End: 2024-06-18T12:00, [Task ID: 73abb022-924f-40ac-a848-2a73ee7a0ab4 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:30, Task ID: d7e5f8a3-73b9-4f6c-9b12-96f4e13b70e0 | Res: 2 | Start: 2024-06-18T10:00 | End: 2024-06-18T12:00, Task ID: 731c791d-7ea6-476b-afc7-77c632e062c7 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:00]]=0hard/0medium/-8100soft
com.optimization.fm.policy.scheduler.infrastucture.constraint/First assignment as early as possible/[Task ID: 731c791d-7ea6-476b-afc7-77c632e062c7 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:00, [Task ID: 73abb022-924f-40ac-a848-2a73ee7a0ab4 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:30, Task ID: d7e5f8a3-73b9-4f6c-9b12-96f4e13b70e0 | Res: 2 | Start: 2024-06-18T10:00 | End: 2024-06-18T12:00, Task ID: 731c791d-7ea6-476b-afc7-77c632e062c7 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:00]]=0hard/0medium/-8100soft
com.optimization.fm.policy.scheduler.infrastucture.constraint/First assignment as early as possible/[Task ID: 73abb022-924f-40ac-a848-2a73ee7a0ab4 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:30, [Task ID: 73abb022-924f-40ac-a848-2a73ee7a0ab4 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:30, Task ID: d7e5f8a3-73b9-4f6c-9b12-96f4e13b70e0 | Res: 2 | Start: 2024-06-18T10:00 | End: 2024-06-18T12:00, Task ID: 731c791d-7ea6-476b-afc7-77c632e062c7 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:00]]=0hard/0medium/-8100soft
com.optimization.fm.policy.scheduler.infrastucture.constraint/MatchSkill/[CheckPolicyCommand[assignmentId=73abb022-924f-40ac-a848-2a73ee7a0ab4, task=Task{id=73abb022-924f-40ac-a848-2a73ee7a0ab4}, resource=Resource{id=2}, interval=Interval[startDateTime=2024-06-18T09:30, endDateTime=2024-06-18T10:30], travelTime=TravelTime[startDateTime=2024-06-18T09:30, endDateTime=2024-06-18T09:30, duration=0], travelTimeToHomeBase=null, dependsOnAssignments=[]]]=-1hard/0medium/0soft
com.optimization.fm.policy.scheduler.infrastucture.constraint/Minimize resource travel time/[Task ID: d7e5f8a3-73b9-4f6c-9b12-96f4e13b70e0 | Res: 2 | Start: 2024-06-18T10:00 | End: 2024-06-18T12:00, [Task ID: 73abb022-924f-40ac-a848-2a73ee7a0ab4 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:30, Task ID: d7e5f8a3-73b9-4f6c-9b12-96f4e13b70e0 | Res: 2 | Start: 2024-06-18T10:00 | End: 2024-06-18T12:00, Task ID: 731c791d-7ea6-476b-afc7-77c632e062c7 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:00]]=0hard/0medium/-295soft
com.optimization.fm.policy.scheduler.infrastucture.constraint/Minimize resource travel time/[Task ID: 731c791d-7ea6-476b-afc7-77c632e062c7 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:00, [Task ID: 73abb022-924f-40ac-a848-2a73ee7a0ab4 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:30, Task ID: d7e5f8a3-73b9-4f6c-9b12-96f4e13b70e0 | Res: 2 | Start: 2024-06-18T10:00 | End: 2024-06-18T12:00, Task ID: 731c791d-7ea6-476b-afc7-77c632e062c7 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:00]]=0hard/0medium/-295soft
com.optimization.fm.policy.scheduler.infrastucture.constraint/Minimize resource travel time/[Task ID: 73abb022-924f-40ac-a848-2a73ee7a0ab4 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:30, [Task ID: 73abb022-924f-40ac-a848-2a73ee7a0ab4 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:30, Task ID: d7e5f8a3-73b9-4f6c-9b12-96f4e13b70e0 | Res: 2 | Start: 2024-06-18T10:00 | End: 2024-06-18T12:00, Task ID: 731c791d-7ea6-476b-afc7-77c632e062c7 | Res: 2 | Start: 2024-06-18T09:30 | End: 2024-06-18T10:00]]=0hard/0medium/-295soft
Maybe there is a bug in the score constraints of those ConstraintMatch(s).   
Maybe a score constraint doesn't select all the entities it depends on, but finds some through a reference in a selected entity. This corrupts incremental score calculation, because the constraint is not re-evaluated if such a non-selected entity changes. Shadow variable corruption in the corrupted scoreDirector:   None

Here are the constraints mentioned:

public Constraint firstAssignmentAsEarlyAsPossible(ConstraintFactory constraintFactory) {
return constraintFactory.forEachIncludingNullVars(OPTask.class)
    .filter(OPTask::isResourcePresent)
    .join(OPTask.class)
    .filter(
        (task1, task2) -> task1.getResourceId().equals(task2.getResourceId()))
    .groupBy((firstTask, secondTask) -> firstTask,
        ConstraintCollectors.toList((firstTask, secondTask) -> secondTask))
    .penalizeConfigurable((task, list) -> (int) Math.pow(
        getUnassignedPeriodAfterBeginning(task.getResource().getAvailabilityCalendarId(), list),2))
    .asConstraint("First assignment as early as possible");
}

public Constraint minimizeResourceTravelTime(ConstraintFactory constraintFactory) {
return constraintFactory.forEachIncludingNullVars(OPTask.class)
    .filter(OPTask::isResourcePresent)
    .join(OPTask.class)
    .filter(
        (task1, task2) -> task1.getResourceId().equals(task2.getResourceId()))
    .groupBy((firstTask, secondTask) -> firstTask,
        ConstraintCollectors.toList((firstTask, secondTask) -> secondTask))
    .penalizeConfigurable((task, list) -> sumOfTravelTime(task.getResourceId(), list))
    .asConstraint("Minimize resource travel time");
}

public Constraint matchSkill(ConstraintFactory constraintFactory) {

    var matchSkillRule = OPRuleCache.getRule(RuleType.MATCH_SKILL);
    
    return constraintFactory.forEach(OPTask.class)
        .filter(task -> task.isResourcePresent() && task.isNewTask())
        .map(task -> OPRuleCache.createCheckPolicyCommand(task, task.getResource()))
        .filter(matchSkillRule::isViolated)
        .penalizeConfigurable()
        .asConstraint("MatchSkill");

}

When I switch to FAST_ASSERT mode, the exception does not occur, and a good solution is generated. However, I am unable to understand the issue in FULL_ASSERT mode.

The exception indicates the presence of expected and excess constraints, leading me to believe there might be a problem in the data grouping for constraint checks. However, I am unsure how to resolve this.

I suspect my understanding of FULL_ASSERT mode and Constraint Streams might be lacking.
I am seeking advice on how to resolve the score corruption issue. Is there a potential bug in the constraints’ implementation, or could it be related to the scoreDirector’s incremental score calculation? Any explanations, instructions, documentation, or tutorials that could help me understand and fix this issue would be greatly appreciated.

Thank you for your time.

Best regards.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật