forked from hugegraph/hugegraph-sync
fix weighted shortest path result not stable (#1280)
Change-Id: Ic97d8c92bd97d6203b7b366a2c6e2f661932e05f
This commit is contained in:
parent
9bc985c067
commit
eb062b2b02
|
|
@ -287,7 +287,10 @@ public class JsonSerializer implements Serializer {
|
|||
@Override
|
||||
public String writeWeightedPaths(WeightedPaths paths,
|
||||
Iterator<Vertex> vertices) {
|
||||
return JsonUtil.toJson(ImmutableMap.of("paths", paths.toMap(),
|
||||
Map<Id, Map<String, Object>> pathMap = paths == null ?
|
||||
ImmutableMap.of() :
|
||||
paths.toMap();
|
||||
return JsonUtil.toJson(ImmutableMap.of("paths", pathMap,
|
||||
"vertices", vertices));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
|
@ -36,6 +37,7 @@ import com.baidu.hugegraph.structure.HugeEdge;
|
|||
import com.baidu.hugegraph.type.define.Directions;
|
||||
import com.baidu.hugegraph.util.CollectionUtil;
|
||||
import com.baidu.hugegraph.util.E;
|
||||
import com.baidu.hugegraph.util.InsertionOrderUtil;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
|
|
@ -168,7 +170,7 @@ public class SingleSourceShortestPathTraverser extends HugeTraverser {
|
|||
Map<Id, NodeWithWeight> sorted = CollectionUtil.sortByValue(
|
||||
this.findingNodes, true);
|
||||
double minWeight = 0;
|
||||
Set<NodeWithWeight> newSources = new HashSet<>();
|
||||
Set<NodeWithWeight> newSources = InsertionOrderUtil.newSet();
|
||||
for (Map.Entry<Id, NodeWithWeight> entry : sorted.entrySet()) {
|
||||
Id id = entry.getKey();
|
||||
NodeWithWeight wn = entry.getValue();
|
||||
|
|
@ -265,7 +267,7 @@ public class SingleSourceShortestPathTraverser extends HugeTraverser {
|
|||
}
|
||||
}
|
||||
|
||||
public static class WeightedPaths extends HashMap<Id, NodeWithWeight> {
|
||||
public static class WeightedPaths extends LinkedHashMap<Id, NodeWithWeight> {
|
||||
|
||||
private static final long serialVersionUID = -313873642177730993L;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue