Reputation: 1
I am wanting to set two Constraints in my OptaPlanner example:
How can I achieve this? Here is one constraint I have tried but doesn't work for me (Shopify is my Orders table):
Constraint productSKU(ConstraintFactory constraintFactory) {
return constraintFactory
.from(Shopify.class).join(Shopify.class, Joiners.equal(Shopify::getProductSKU),
Joiners.equal(Shopify::getStockLocation))
.filter((shopify, stockLocation) ->
stockLocation.getStockLocation().getProductSKU() == shopify.getProductSKU())
.reward("Correct Allocated SKU", HardSoftScore.ONE_SOFT);
}
Also it takes over 10 minutes to solve, how can i speed up solving time?
Any help is appreciated!
Upvotes: 0
Views: 140
Reputation: 1029
Assuming you always want the Product SKU
to match, I would rather penalize by a hard score level if it doesn't, as such a solution is most likely not feasible.
Now, further assuming that Shopify
is your @PlanningEntity
, the constraint might be simplified in the following way:
return constraintFactory
.from(Shopify.class)
.filter((shopify) ->
!Objects.equals(shopify.getStockLocation().getProductSKU()), shopify.getProductSKU()))
.penalize("Correct Allocated SKU", HardSoftScore.ONE_HARD);
Please note that the code excerpt above is just for an illustration and may not be compatible with your domain classes.
The second constraint you described could be implemented as penalizing by how much any StockLocation
exceeds the limit of 30 orders. From the description, it's not clear to me whether this constraint should be hard or soft (is it a must-have or rather an attempt to balance orders across stock locations?).
As for speeding up the solving, please submit a separate question providing more information about the issue, e.g. INFO logging output, solver configuration, or (estimated) number of @PlanninEntity
instances and corresponding value instances.
Upvotes: 1