mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
get rid of google guava dep
This commit is contained in:
parent
6dbc35e350
commit
ab8741a335
3 changed files with 30 additions and 22 deletions
|
|
@ -18,22 +18,21 @@
|
|||
|
||||
package com.graphhopper.jsprit.core.util;
|
||||
|
||||
import com.google.common.collect.HashMultiset;
|
||||
import com.google.common.collect.Multiset;
|
||||
import com.graphhopper.jsprit.core.algorithm.recreate.listener.JobUnassignedListener;
|
||||
import com.graphhopper.jsprit.core.problem.job.Job;
|
||||
import org.apache.commons.math3.stat.Frequency;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by schroeder on 06/02/17.
|
||||
*/
|
||||
public class UnassignedJobReasonTracker implements JobUnassignedListener {
|
||||
|
||||
Map<String, Multiset<String>> reasons = new HashMap<>();
|
||||
Map<String, Frequency> reasons = new HashMap<>();
|
||||
|
||||
Map<Integer, String> codesToReason = new HashMap<>();
|
||||
|
||||
|
|
@ -56,11 +55,10 @@ public class UnassignedJobReasonTracker implements JobUnassignedListener {
|
|||
@Override
|
||||
public void informJobUnassigned(Job unassigned, Collection<String> failedConstraintNames) {
|
||||
if (!this.reasons.containsKey(unassigned.getId())) {
|
||||
Multiset<String> ms = HashMultiset.create();
|
||||
this.reasons.put(unassigned.getId(), ms);
|
||||
this.reasons.put(unassigned.getId(), new Frequency());
|
||||
}
|
||||
for (String r : failedConstraintNames) {
|
||||
this.reasons.get(unassigned.getId()).add(r);
|
||||
this.reasons.get(unassigned.getId()).addValue(r);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -83,13 +81,13 @@ public class UnassignedJobReasonTracker implements JobUnassignedListener {
|
|||
* @return
|
||||
*/
|
||||
public int getCode(String jobId) {
|
||||
Multiset<String> reasons = this.reasons.get(jobId);
|
||||
Frequency reasons = this.reasons.get(jobId);
|
||||
String mostLikelyReason = getMostLikely(reasons);
|
||||
return toCode(mostLikelyReason);
|
||||
}
|
||||
|
||||
public String getReason(String jobId) {
|
||||
Multiset<String> reasons = this.reasons.get(jobId);
|
||||
Frequency reasons = this.reasons.get(jobId);
|
||||
String mostLikelyReason = getMostLikely(reasons);
|
||||
int code = toCode(mostLikelyReason);
|
||||
if (code == -1) return mostLikelyReason;
|
||||
|
|
@ -102,15 +100,15 @@ public class UnassignedJobReasonTracker implements JobUnassignedListener {
|
|||
else return -1;
|
||||
}
|
||||
|
||||
private String getMostLikely(Multiset<String> reasons) {
|
||||
Set<String> set = reasons.elementSet();
|
||||
private String getMostLikely(Frequency reasons) {
|
||||
Iterator<Map.Entry<Comparable<?>, Long>> entryIterator = reasons.entrySetIterator();
|
||||
int maxCount = 0;
|
||||
String mostLikely = null;
|
||||
for (String r : set) {
|
||||
int count = reasons.count(r);
|
||||
if (count > maxCount) {
|
||||
mostLikely = r;
|
||||
maxCount = count;
|
||||
while (entryIterator.hasNext()) {
|
||||
Map.Entry<Comparable<?>, Long> entry = entryIterator.next();
|
||||
if (entry.getValue() > maxCount) {
|
||||
Comparable<?> key = entry.getKey();
|
||||
mostLikely = key.toString();
|
||||
}
|
||||
}
|
||||
return mostLikely;
|
||||
|
|
|
|||
|
|
@ -34,11 +34,13 @@ import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
|||
import com.graphhopper.jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.VehicleType;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||
import org.apache.commons.math3.stat.Frequency;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
|
@ -137,4 +139,18 @@ public class UnassignedJobReasonTrackerTest {
|
|||
Assert.assertEquals(1, solution.getUnassignedJobs().size());
|
||||
Assert.assertEquals(4, reasonTracker.getCode(solution.getUnassignedJobs().iterator().next().getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFreq() {
|
||||
Frequency frequency = new Frequency();
|
||||
frequency.addValue("VehicleDependentTimeWindowHardActivityConstraint");
|
||||
frequency.addValue("b");
|
||||
frequency.addValue("VehicleDependentTimeWindowHardActivityConstraint");
|
||||
|
||||
Iterator<Map.Entry<Comparable<?>, Long>> entryIterator = frequency.entrySetIterator();
|
||||
while (entryIterator.hasNext()) {
|
||||
Map.Entry<Comparable<?>, Long> e = entryIterator.next();
|
||||
System.out.println(e.getKey().toString() + " " + e.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue