Optaplanner约束提供者

发布于 2025-02-09 10:09:25 字数 1724 浏览 0 评论 0原文

我创建了一个小型项目,下面是用户酶

用例:

  • 我们有迪克斯 - 可以处理80/40/20 ..每小时容器。 Docatorards将在卡车上放置集装箱

  • 我们有卡车 - 可以携带10/20/6 ..容器容量。

问题解决方案: 我们需要计划哪个卡车在哪个时间基于集装箱容量的时间到哪个迪士特。

示例:

如果Dododard具有40个容量 我们可以在8:00-9:00时段发送两辆具有容量25、15的卡车(与Dicyard容量匹配),

如果Docyard拥有10个容量 我们只能在9:00-10:00 timeslot上发送一辆具有容量> 10的卡车(与Dicyard容量匹配),

我在下面创建了一个限制,以解决我遇到的问题

    Constraint requiredCapacityConstraint(ConstraintFactory constraintFactory) {
    return constraintFactory.forEach(Truck.class)
            .groupBy(Truck::getDocYard, Truck::getTruckCapacity)
            .filter((docYard, reqCapacity) -> reqCapacity > docYard.getCapacity())
            .penalize("requiredCapacityTotal",
                    HardSoftScore.ONE_HARD,
                    (docYard, truckCapacity) -> truckCapacity - docYard.getCapacity());
}

以下,这是错误的 - 因为它正在分配。卡车更大的能力

|            |DocYard-A-40|DocYard-B-20|DocYard-C-10|
|------------|------------|------------|------------|
| 08:00      | T40        | T19        | T10        |
|------------|------------|------------|------------|
| 09:00      | T15,T30    | T11,T12    | T03        |
|------------|------------|------------|------------|
| 10:00      | T22        | T20        | T05        |
|------------|------------|------------|------------|
here number after alphabet is CAPACITY of that Truck / DocYard

可以帮助我帮助我出了什么问题&我该如何解决?

在上述问题的github回购

github link

I have created a small project resolve below usecase

Use Case:

  • We have DocYards – which can handle 80/40/20.. containers per hour. DocYards will place containers on Trucks

  • We have Trucks – which can Carry 10/20/6.. containers capacity.

Problem Solution :
We need to plan which Truck goes to which DocYard at what time, based up on container capacities.

Example:

If DocYard having 40 Capacity
We can send Two Trucks with Capacity 25, 15 (matched or less to DicYard Capacity) at 8:00 - 9:00 timeslot

If DocYard having 10 Capacity
We can only send one Truck with Capacity >10 (matched or less to DicYard Capacity) at 9:00 - 10:00 timeslot

i have created below constraint to solve the problem

    Constraint requiredCapacityConstraint(ConstraintFactory constraintFactory) {
    return constraintFactory.forEach(Truck.class)
            .groupBy(Truck::getDocYard, Truck::getTruckCapacity)
            .filter((docYard, reqCapacity) -> reqCapacity > docYard.getCapacity())
            .penalize("requiredCapacityTotal",
                    HardSoftScore.ONE_HARD,
                    (docYard, truckCapacity) -> truckCapacity - docYard.getCapacity());
}

i got below output , which is wrong - because it is assigning trucks greaterthan its capacity

|            |DocYard-A-40|DocYard-B-20|DocYard-C-10|
|------------|------------|------------|------------|
| 08:00      | T40        | T19        | T10        |
|------------|------------|------------|------------|
| 09:00      | T15,T30    | T11,T12    | T03        |
|------------|------------|------------|------------|
| 10:00      | T22        | T20        | T05        |
|------------|------------|------------|------------|
here number after alphabet is CAPACITY of that Truck / DocYard

Can someone help me what's wrong & how can i resolve this ?

attching github repo of above problem

Github Link

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终弃我 2025-02-16 10:09:25

主要问题是groupby(卡车:: getDocyard,truck :: getTruckcapacity)仅分组卡车,而不是总结。此外,它没有考虑到卡车的时隙。要计算特定时段期间使用的容量,需要与condercaintCollector.sum一起使用第二个GroupBy密钥来计算总和:

Constraint requiredCapacityConstraint(ConstraintFactory constraintFactory) {
    return constraintFactory.forEach(Truck.class)
        .groupBy(Truck::getDocYard, Truck::getTimeslot, ConstraintCollectors.sum(Truck::getTruckCapacity))
        .filter((docYard, timeslot, reqCapacity) -> reqCapacity > docYard.getCapacity())
        .penalize("requiredCapacityTotal",
                HardSoftScore.ONE_HARD,
                (docYard, timeslot, truckCapacity) -> truckCapacity - docYard.getCapacity());
}

The main problem is groupBy(Truck::getDocYard, Truck::getTruckCapacity) only groups the trucks, not sum them. In addition, it does not take into account the Truck's timeslot. To calculate capacity used during a particular timeslot, a second groupBy key need to be used, along with ConstraintCollector.sum to calculate the sum:

Constraint requiredCapacityConstraint(ConstraintFactory constraintFactory) {
    return constraintFactory.forEach(Truck.class)
        .groupBy(Truck::getDocYard, Truck::getTimeslot, ConstraintCollectors.sum(Truck::getTruckCapacity))
        .filter((docYard, timeslot, reqCapacity) -> reqCapacity > docYard.getCapacity())
        .penalize("requiredCapacityTotal",
                HardSoftScore.ONE_HARD,
                (docYard, timeslot, truckCapacity) -> truckCapacity - docYard.getCapacity());
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文