Optaplanner约束提供者
我创建了一个小型项目,下面是用户酶
用例:
我们有迪克斯 - 可以处理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回购
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
主要问题是
groupby(卡车:: getDocyard,truck :: getTruckcapacity)
仅分组卡车,而不是总结。此外,它没有考虑到卡车的时隙。要计算特定时段期间使用的容量,需要与condercaintCollector.sum
一起使用第二个GroupBy密钥来计算总和: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 withConstraintCollector.sum
to calculate the sum: