|
1 |
| -using Revise |
| 1 | +# using Revise |
| 2 | +using Neo4j |
2 | 3 | using DistributedFactorGraphs
|
| 4 | +using IncrementalInference |
| 5 | +using Test |
3 | 6 |
|
4 |
| -dfg = GraphsDFG{NoSolverParams}() |
5 |
| -v1 = DFGVariable(:a) |
6 |
| -v2 = DFGVariable(:b) |
7 |
| -v3 = DFGVariable(:c) |
8 |
| -f1 = DFGFactor{Int, :Symbol}(:f1) |
9 |
| -f2 = DFGFactor{Int, :Symbol}(:f2) |
10 |
| -addVariable!(dfg, v1) |
11 |
| -addVariable!(dfg, v2) |
12 |
| -addVariable!(dfg, v3) |
13 |
| -addFactor!(dfg, [v1, v2], f1) |
14 |
| -addFactor!(dfg, [:b, :c], f2) |
15 |
| -dfg |
16 |
| -dfg.g.inclist |
17 |
| -fieldnames(typeof(dfg.g)) |
18 |
| -dfg.g.vertices |
19 |
| -summ = getSummary(dfg) |
20 |
| -summaryGraph = getSummaryGraph(dfg) |
21 |
| -ls(summaryGraph) |
22 |
| -lsf(summaryGraph) |
23 |
| -getVariable(summaryGraph, :a) |
24 |
| -getFactor(summaryGraph, :f1) |
| 7 | +dfg = CloudGraphsDFG{SolverParams}("localhost", 7474, "neo4j", "test", |
| 8 | + "testUser", "testRobot", "testSession", |
| 9 | + nothing, |
| 10 | + nothing, |
| 11 | + IncrementalInference.decodePackedType, |
| 12 | + IncrementalInference.rebuildFactorMetadata!, |
| 13 | + solverParams=SolverParams()) |
| 14 | +clearRobot!!(dfg) |
| 15 | +v1 = addVariable!(dfg, :a, ContinuousScalar, labels = [:POSE]) |
| 16 | +v2 = addVariable!(dfg, :b, ContinuousScalar, labels = [:LANDMARK]) |
| 17 | +f1 = addFactor!(dfg, [:a; :b], LinearConditional(Normal(50.0,2.0)) ) |
| 18 | +v1 == deepcopy(v1) |
| 19 | + |
| 20 | +function al(a, b) |
| 21 | + a.label != b.label && return false |
| 22 | + a.timestamp != b.timestamp && return false |
| 23 | + a.tags != b.tags && return false |
| 24 | + symdiff(keys(a.estimateDict), keys(b.estimateDict)) != Set(Symbol[]) && return false |
| 25 | + for k in keys(a.estimateDict) |
| 26 | + a.estimateDict[k] != b.estimateDict[k] && return false |
| 27 | + end |
| 28 | + symdiff(keys(a.solverDataDict), keys(b.solverDataDict)) != Set(Symbol[]) && return false |
| 29 | + for k in keys(a.solverDataDict) |
| 30 | + a.solverDataDict[k] != b.solverDataDict[k] && return false |
| 31 | + end |
| 32 | + return true |
| 33 | +end |
| 34 | +al(a, b) |
| 35 | +a = v1 |
| 36 | +b = deepcopy(v1) |
| 37 | + |
| 38 | +a.smallData != b.smallData && return false |
| 39 | +a.bigData != b.bigData && return false |
| 40 | +a.ready != b.ready && return false |
| 41 | +a.backendset != b.backendset && return false |
| 42 | +a._internalId != b._internalId && return false |
| 43 | + |
| 44 | +T = typeof(dfg) |
| 45 | +if T <: CloudGraphsDFG |
| 46 | + dfg2 = CloudGraphsDFG{SolverParams}("localhost", 7474, "neo4j", "test", |
| 47 | + "testUser", "testRobot", "testSession2", |
| 48 | + nothing, |
| 49 | + nothing, |
| 50 | + IncrementalInference.decodePackedType, |
| 51 | + IncrementalInference.rebuildFactorMetadata!, |
| 52 | + solverParams=SolverParams()) |
| 53 | +else |
| 54 | + dfg2 = T() |
| 55 | +end |
| 56 | +iiffg = initfg() |
| 57 | +v1 = deepcopy(addVariable!(iiffg, :a, ContinuousScalar)) |
| 58 | +v2 = deepcopy(addVariable!(iiffg, :b, ContinuousScalar)) |
| 59 | +v3 = deepcopy(addVariable!(iiffg, :c, ContinuousScalar)) |
| 60 | +f1 = deepcopy(addFactor!(iiffg, [:a; :b], LinearConditional(Normal(50.0,2.0)) )) |
| 61 | +f2 = deepcopy(addFactor!(iiffg, [:b; :c], LinearConditional(Normal(10.0,1.0)) )) |
| 62 | + |
| 63 | +# @testset "Creating Graphs" begin |
| 64 | +@test addVariable!(dfg2, v1) |
| 65 | +@test addVariable!(dfg2, v2) |
| 66 | +@test_throws ErrorException updateVariable!(dfg2, v3) |
| 67 | +@test addVariable!(dfg2, v3) |
| 68 | +@test_throws ErrorException addVariable!(dfg2, v3) |
| 69 | +@test addFactor!(dfg2, [v1, v2], f1) |
| 70 | +@test_throws ErrorException addFactor!(dfg2, [v1, v2], f1) |
| 71 | +@test_throws ErrorException updateFactor!(dfg2, f2) |
| 72 | +@test addFactor!(dfg2, [:b, :c], f2) |
| 73 | + |
| 74 | +dv3 = deleteVariable!(dfg2, v3) |
| 75 | +#TODO write compare if we want to compare complete one, for now just label |
| 76 | +# @test dv3 == v3 |
| 77 | +@test dv3.label == v3.label |
| 78 | +@test_throws ErrorException deleteVariable!(dfg2, v3) |
| 79 | + |
| 80 | +@test symdiff(ls(dfg2),[:a,:b]) == [] |
| 81 | +df2 = deleteFactor!(dfg2, f2) |
| 82 | +#TODO write compare if we want to compare complete one, for now just label |
| 83 | +# @test df2 == f2 |
| 84 | +@test df2.label == f2.label |
| 85 | +@test_throws ErrorException deleteFactor!(dfg2, f2) |
| 86 | + |
| 87 | +@test lsf(dfg2) == [:abf1] |
| 88 | + |
| 89 | +@test length(ls(dfg)) == 2 |
| 90 | +@test length(lsf(dfg)) == 1 # Unless we add the prior! |
| 91 | +@test symdiff([:a, :b], getVariableIds(dfg)) == [] |
| 92 | +@test getFactorIds(dfg) == [:abf1] # Unless we add the prior! |
| 93 | +# |
| 94 | +@test lsf(dfg, :a) == [f1.label] |
| 95 | +# Tags |
| 96 | +@test ls(dfg, tags=[:POSE]) == [:a] |
| 97 | +@test symdiff(ls(dfg, tags=[:POSE, :LANDMARK]), ls(dfg, tags=[:VARIABLE])) == [] |
| 98 | +# Regexes |
| 99 | +@test ls(dfg, r"a") == [v1.label] |
| 100 | +# TODO: Check that this regular expression works on everything else! |
| 101 | +# it works with the . |
| 102 | +# REF: https://stackoverflow.com/questions/23834692/using-regular-expression-in-neo4j |
| 103 | +@test lsf(dfg, r"abf.*") == [f1.label] |
| 104 | + |
| 105 | +# Accessors |
| 106 | +@test getAddHistory(dfg) == [:a, :b] #, :abf1 |
| 107 | +@test getDescription(dfg) != nothing |
| 108 | +@test getLabelDict(dfg) != nothing |
| 109 | +# Existence |
| 110 | +@test exists(dfg, :a) == true |
| 111 | +@test exists(dfg, v1) == true |
| 112 | +@test exists(dfg, :nope) == false |
| 113 | +# Sorting of results |
| 114 | +# TODO - this function needs to be cleaned up |
| 115 | +unsorted = [:x1_3;:x1_6;:l1;:april1] #this will not work for :x1x2f1 |
| 116 | +@test sortDFG(unsorted) == sortVarNested(unsorted) |
| 117 | +@test_skip sortDFG([:x1x2f1, :x1l1f1]) == [:x1l1f1, :x1x2f1] |
| 118 | + |
| 119 | +@test getVariable(dfg, v1.label) == v1 |
| 120 | +@test getFactor(dfg, f1.label) == f1 |
| 121 | +@test_throws Exception getVariable(dfg, :nope) |
| 122 | +@test_throws Exception getVariable(dfg, "nope") |
| 123 | +@test_throws Exception getFactor(dfg, :nope) |
| 124 | +@test_throws Exception getFactor(dfg, "nope") |
| 125 | + |
| 126 | +# Sets |
| 127 | +v1Prime = deepcopy(v1) |
| 128 | +@test updateVariable!(dfg, v1Prime) != v1 |
| 129 | +f1Prime = deepcopy(f1) |
| 130 | +@test updateFactor!(dfg, f1Prime) != f1 |
| 131 | + |
| 132 | +# Accessors |
| 133 | +@test label(v1) == v1.label |
| 134 | +@test tags(v1) == v1.tags |
| 135 | +@test timestamp(v1) == v1.timestamp |
| 136 | +@test estimates(v1) == v1.estimateDict |
| 137 | +@test DistributedFactorGraphs.estimate(v1, :notfound) == nothing |
| 138 | +@test solverData(v1) === v1.solverDataDict[:default] |
| 139 | +@test getData(v1) === v1.solverDataDict[:default] |
| 140 | +@test solverData(v1, :default) === v1.solverDataDict[:default] |
| 141 | +@test solverDataDict(v1) == v1.solverDataDict |
| 142 | +@test internalId(v1) == v1._internalId |
| 143 | + |
| 144 | +@test label(f1) == f1.label |
| 145 | +@test tags(f1) == f1.tags |
| 146 | +@test solverData(f1) == f1.data |
| 147 | +# Deprecated functions |
| 148 | +@test data(f1) == f1.data |
| 149 | +@test getData(f1) == f1.data |
| 150 | +# Internal function |
| 151 | +@test internalId(f1) == f1._internalId |
| 152 | + |
| 153 | +@test getSolverParams(dfg) != nothing |
| 154 | +@test setSolverParams(dfg, getSolverParams(dfg)) == getSolverParams(dfg) |
| 155 | + |
| 156 | +#solver data is initialized |
| 157 | +@test !isInitialized(dfg, :a) |
| 158 | +@test !isInitialized(v2) |
| 159 | + |
| 160 | +@test !isInitialized(v2, key=:second) |
0 commit comments