1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

add human readable reason

This commit is contained in:
oblonski 2017-11-21 19:59:26 +01:00
parent 9144a05886
commit fb78e1574b
No known key found for this signature in database
GPG key ID: 179DE487285680D1

View file

@ -29,8 +29,11 @@ import java.util.*;
*/
public class UnassignedJobReasonTracker implements JobUnassignedListener {
private final static String NO_REASON = "cannot determine a particular reason";
public static String getMostLikelyFailedConstraintName(Frequency failedConstraintNamesFrequency) {
if (failedConstraintNamesFrequency == null) return "no reason found";
if (failedConstraintNamesFrequency == null || failedConstraintNamesFrequency.getUniqueCount() == 0)
return NO_REASON;
Iterator<Map.Entry<Comparable<?>, Long>> entryIterator = failedConstraintNamesFrequency.entrySetIterator();
long maxCount = 0;
String mostLikely = null;
@ -54,6 +57,7 @@ public class UnassignedJobReasonTracker implements JobUnassignedListener {
Set<String> failedConstraintNamesToBeIgnored = new HashSet<>();
public UnassignedJobReasonTracker() {
codesToHumanReadableReason.put(-1, NO_REASON);
codesToHumanReadableReason.put(1, "cannot serve required skill");
codesToHumanReadableReason.put(2, "cannot be visited within time window");
codesToHumanReadableReason.put(3, "does not fit into any vehicle due to capacity");
@ -165,8 +169,9 @@ public class UnassignedJobReasonTracker implements JobUnassignedListener {
* @return
*/
public String getMostLikelyReason(String jobId) {
if (!this.failedConstraintNamesFrequencyMapping.containsKey(jobId)) return "no reason found";
if (!this.failedConstraintNamesFrequencyMapping.containsKey(jobId)) return codesToHumanReadableReason.get(-1);
Frequency reasons = this.failedConstraintNamesFrequencyMapping.get(jobId);
String mostLikelyReason = getMostLikelyFailedConstraintName(reasons);
int code = toCode(mostLikelyReason);
if (code == -1) return mostLikelyReason;