You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/interfaces.jl
+29-22Lines changed: 29 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -1,28 +1,33 @@
1
1
abstract type AbstractProperty end
2
2
3
3
"""
4
-
SizeMax <: AbstractProperty
5
-
SizeMax()
4
+
SizeMax{K} <: AbstractProperty
5
+
SizeMax(k::Int)
6
6
7
-
The maximum set size. e.g. the largest size of the [`IndependentSet`](@ref) problem is also know as the independence number.
7
+
The maximum-K set sizes. e.g. the largest size of the [`IndependentSet`](@ref) problem is also know as the independence number.
8
8
9
-
* The corresponding tensor element type is max-plus tropical number [`Tropical`](@ref).
9
+
* The corresponding tensor element type are max-plus tropical number [`Tropical`](@ref) for `K == 1` and [`ExtendedTropical`](@ref) for `K > 1`.
10
10
* It is compatible with weighted graph problems.
11
-
* BLAS (on CPU) and GPU are supported,
11
+
* BLAS (on CPU) and GPU are supported only for `K == 1`,
12
12
"""
13
-
struct SizeMax <:AbstractPropertyend
13
+
struct SizeMax{K} <:AbstractPropertyend
14
+
SizeMax(k::Int=1) =SizeMax{k}()
15
+
max_k(::SizeMax{K}) where K = K
14
16
15
17
"""
16
-
SizeMin <: AbstractProperty
17
-
SizeMin()
18
+
SizeMin{K} <: AbstractProperty
19
+
SizeMin(k::Int)
18
20
19
-
The maximum set size. e.g. the smallest size ofthe [`MaximalIS`](@ref) problem is also known as the independent domination number.
21
+
The minimum-K set sizes. e.g. the smallest size ofthe [`MaximalIS`](@ref) problem is also known as the independent domination number.
20
22
21
-
* The corresponding tensor element type inverted max-plus tropical number [`Tropical`](@ref), which is equivalent to the min-plus tropical number.
23
+
* The corresponding tensor element type are inverted max-plus tropical number [`Tropical`](@ref) for `K == 1` and inverted [`ExtendedTropical`](@ref) for `K > 1`.
24
+
The inverted Tropical number emulates the min-plus tropical number.
22
25
* It is compatible with weighted graph problems.
23
-
* BLAS (on CPU) and GPU are supported,
26
+
* BLAS (on CPU) and GPU are supported only for `K == 1`,
24
27
"""
25
-
struct SizeMin <:AbstractPropertyend
28
+
struct SizeMin{K} <:AbstractPropertyend
29
+
SizeMin(k::Int=1) =SizeMin{k}()
30
+
max_k(::SizeMin{K}) where K = K
26
31
27
32
"""
28
33
CountingAll <: AbstractProperty
@@ -226,10 +231,14 @@ function solve(gp::GraphProblem, property::AbstractProperty; T=Float64, usecuda=
226
231
if!_solvable(gp, property)
227
232
throw(ArgumentError("Graph property `$(typeof(property))` is not computable for graph problem of type `$(typeof(gp))`."))
(CountingTropical(5.0, ConfigEnumerator([StaticBitVector(rand(Bool, 10)) for j=1:3])), CountingTropical(3.0, ConfigEnumerator([StaticBitVector(rand(Bool, 10)) for j=1:4])), CountingTropical(-3.0, ConfigEnumerator([StaticBitVector(rand(Bool, 10)) for j=1:5]))),
@@ -97,6 +98,14 @@ end
97
98
x =ConfigSampler(bv"00111")
98
99
@test x ^0==one(x)
99
100
@test x ^2.0== x
101
+
102
+
x =ExtendedTropical{3}([1.0, 2.0, 3.0])
103
+
@test x ^1== x
104
+
@test x ^0==one(x)
105
+
@test x ^1.0== x
106
+
@test x ^0.0==one(x)
107
+
@test x ^2==ExtendedTropical{3}([2.0, 4.0, 6.0])
108
+
@test x ^2.0==ExtendedTropical{3}([2.0, 4.0, 6.0])
100
109
end
101
110
102
111
@testset"push coverage"begin
@@ -113,4 +122,32 @@ end
113
122
@testcopy(y) !== y
114
123
@test!iszero(y)
115
124
println((x * x) *zero(x))
125
+
end
126
+
127
+
@testset"Truncated Tropical"begin
128
+
# +
129
+
a =ExtendedTropical{3}([1,2,3])
130
+
b =ExtendedTropical{3}([4,5,6])
131
+
c =ExtendedTropical{3}([0,1,2])
132
+
@test a + b ==ExtendedTropical{3}([4,5,6])
133
+
@test b + a ==ExtendedTropical{3}([4,5,6])
134
+
@test c + a ==ExtendedTropical{3}([2,2,3])
135
+
@test a + c ==ExtendedTropical{3}([2,2,3])
136
+
137
+
# *
138
+
functionnaive_mul(a, b)
139
+
K =length(a)
140
+
returnsort!(vec([x+y for x in a, y in b]))[end-K+1:end]
141
+
end
142
+
d =ExtendedTropical{3}([0,1,20])
143
+
@testnaive_mul(a.orders, b.orders) == (a * b).orders
0 commit comments