I don’t understand that how does the SoftConstraint work and how do i make sure the SoftConstraint working?
Generally, soft constraints can be reagarded as optional business rules which would or would not be honored by the solution. It has impact on the total cost only: adding penalties when the constraint is violated.
This holds the answer to the second part of your question: the constraint to work, you have to choose the cost penalties wisely. If you choose too low values, the constraint will be easily ignored. If you choose the values too high, the costraint will become a quasi-hard constraint (the “quasi” prefix is important: it will nevel ensure the constraint), depressing all other cost values.
As for the use of the soft constraints, you can find several examples in the code to start with. If you still have some more questions, please feel free to ask!
thank you! i have to see the source code.
soft constraints (or constraints in general) guide the insertion of individual jobs. you can refer to ServiceInsertionCalculator and ShipmentInsertionCalculator to see how soft constraint costs are added up and compared with bestCost in order to choose the best insertion position of the current job.
so, soft constraints “softly” control the generation of the solutions, and meanwhile you will need a custom objective function to select the best solution that is in line with your soft constraints, because, otherwise, you might not be able to get what you expect.