Skip to content

Commit

Permalink
Upgrade to v0.7, drop v0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnimuc committed Jul 23, 2018
1 parent cb62a72 commit f344785
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 81 deletions.
34 changes: 24 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
# Documentation: http://docs.travis-ci.com/user/languages/julia/
## Documentation: http://docs.travis-ci.com/user/languages/julia/
language: julia
os:
- linux
- osx
julia:
- 0.6
- 0.7
- nightly
matrix:
allow_failures:
- julia: nightly
notifications:
email: false
#script: # use the default script which is equivalent to the following
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
# - julia -e 'Pkg.clone(pwd()); Pkg.build("BKMaxflow"); Pkg.test("BKMaxflow"; coverage=true)'
git:
depth: 99999999

## uncomment the following lines to allow failures on nightly julia
## (tests will run but not make your overall status red)
matrix:
allow_failures:
- julia: nightly

## uncomment and modify the following lines to manually install system packages
#addons:
# apt: # apt-get for linux
# packages:
# - gfortran
#before_script: # homebrew for mac
# - if [ $TRAVIS_OS_NAME = osx ]; then brew install gcc; fi

## uncomment the following lines to override the default test script
script:
- julia -e 'using Pkg; Pkg.instantiate(); Pkg.build("BKMaxflow"); Pkg.test("BKMaxflow"; coverage=true)'
after_success:
# push coverage results to Coveralls
- julia -e 'cd(Pkg.dir("BKMaxflow")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
- julia -e 'using Pkg; cd(Pkg.dir("BKMaxflow")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
# push coverage results to Codecov
- julia -e 'cd(Pkg.dir("BKMaxflow")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
- julia -e 'using Pkg; cd(Pkg.dir("BKMaxflow")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Yupei Qi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
22 changes: 0 additions & 22 deletions LICENSE.md

This file was deleted.

3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
authors = ["Gnimuc <[email protected]>"]
name = "BKMaxflow"
uuid = "7d36e1c2-8e6d-11e8-39fb-ab2b1a405295"
authors = ["Gnimuc <[email protected]>"]
version = "0.1.0"

[deps]
BinaryProvider = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
2 changes: 0 additions & 2 deletions REQUIRE

This file was deleted.

20 changes: 13 additions & 7 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.7/julia-0.7-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.7/julia-0.7-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

## uncomment the following lines to allow failures on nightly julia
## (tests will run but not make your overall status red)
matrix:
allow_failures:
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
allow_failures:
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

branches:
only:
Expand All @@ -23,6 +25,11 @@ notifications:

install:
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
# If there's a newer build queued for the same PR, cancel this one
- ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
throw "There are newer queued builds for this pull request, failing early." }
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile(
$env:JULIA_URL,
Expand All @@ -33,8 +40,7 @@ install:
build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo();
Pkg.clone(pwd(), \"BKMaxflow\"); Pkg.build(\"BKMaxflow\")"
- C:\projects\julia\bin\julia -e "versioninfo(); using Pkg; Pkg.instantiate(); Pkg.build(\"BKMaxflow\")"

test_script:
- C:\projects\julia\bin\julia -e "Pkg.test(\"BKMaxflow\")"
26 changes: 13 additions & 13 deletions gen/api/bk_api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function bk_error_message(error)
end

function bk_error_release(error)
ccall((:bk_error_release, libbkmaxflow), Void, (bk_error,), error)
ccall((:bk_error_release, libbkmaxflow), Cvoid, (bk_error,), error)
end

function bk_create_graph_int(node_num_max, edge_num_max, error)
Expand All @@ -27,19 +27,19 @@ function bk_create_graph_double(node_num_max, edge_num_max, error)
end

function bk_delete_graph_int(g)
ccall((:bk_delete_graph_int, libbkmaxflow), Void, (bk_graph_int,), g)
ccall((:bk_delete_graph_int, libbkmaxflow), Cvoid, (bk_graph_int,), g)
end

function bk_delete_graph_short(g)
ccall((:bk_delete_graph_short, libbkmaxflow), Void, (bk_graph_short,), g)
ccall((:bk_delete_graph_short, libbkmaxflow), Cvoid, (bk_graph_short,), g)
end

function bk_delete_graph_float(g)
ccall((:bk_delete_graph_float, libbkmaxflow), Void, (bk_graph_float,), g)
ccall((:bk_delete_graph_float, libbkmaxflow), Cvoid, (bk_graph_float,), g)
end

function bk_delete_graph_double(g)
ccall((:bk_delete_graph_double, libbkmaxflow), Void, (bk_graph_double,), g)
ccall((:bk_delete_graph_double, libbkmaxflow), Cvoid, (bk_graph_double,), g)
end

function bk_add_node_int(g, num, error)
Expand All @@ -59,35 +59,35 @@ function bk_add_node_double(g, num, error)
end

function bk_add_tweights_int(g, id, cap_source, cap_sink, error)
ccall((:bk_add_tweights_int, libbkmaxflow), Void, (bk_graph_int, Cint, Cint, Cint, Ptr{bk_error}), g, id, cap_source, cap_sink, error)
ccall((:bk_add_tweights_int, libbkmaxflow), Cvoid, (bk_graph_int, Cint, Cint, Cint, Ptr{bk_error}), g, id, cap_source, cap_sink, error)
end

function bk_add_tweights_short(g, id, cap_source, cap_sink, error)
ccall((:bk_add_tweights_short, libbkmaxflow), Void, (bk_graph_short, Cint, Cint, Cint, Ptr{bk_error}), g, id, cap_source, cap_sink, error)
ccall((:bk_add_tweights_short, libbkmaxflow), Cvoid, (bk_graph_short, Cint, Cint, Cint, Ptr{bk_error}), g, id, cap_source, cap_sink, error)
end

function bk_add_tweights_float(g, id, cap_source, cap_sink, error)
ccall((:bk_add_tweights_float, libbkmaxflow), Void, (bk_graph_float, Cint, Cfloat, Cfloat, Ptr{bk_error}), g, id, cap_source, cap_sink, error)
ccall((:bk_add_tweights_float, libbkmaxflow), Cvoid, (bk_graph_float, Cint, Cfloat, Cfloat, Ptr{bk_error}), g, id, cap_source, cap_sink, error)
end

function bk_add_tweights_double(g, id, cap_source, cap_sink, error)
ccall((:bk_add_tweights_double, libbkmaxflow), Void, (bk_graph_double, Cint, Cdouble, Cdouble, Ptr{bk_error}), g, id, cap_source, cap_sink, error)
ccall((:bk_add_tweights_double, libbkmaxflow), Cvoid, (bk_graph_double, Cint, Cdouble, Cdouble, Ptr{bk_error}), g, id, cap_source, cap_sink, error)
end

function bk_add_edge_int(g, i, j, cap, rev_cap, error)
ccall((:bk_add_edge_int, libbkmaxflow), Void, (bk_graph_int, Cint, Cint, Cint, Cint, Ptr{bk_error}), g, i, j, cap, rev_cap, error)
ccall((:bk_add_edge_int, libbkmaxflow), Cvoid, (bk_graph_int, Cint, Cint, Cint, Cint, Ptr{bk_error}), g, i, j, cap, rev_cap, error)
end

function bk_add_edge_short(g, i, j, cap, rev_cap, error)
ccall((:bk_add_edge_short, libbkmaxflow), Void, (bk_graph_short, Cint, Cint, Int16, Int16, Ptr{bk_error}), g, i, j, cap, rev_cap, error)
ccall((:bk_add_edge_short, libbkmaxflow), Cvoid, (bk_graph_short, Cint, Cint, Int16, Int16, Ptr{bk_error}), g, i, j, cap, rev_cap, error)
end

function bk_add_edge_float(g, i, j, cap, rev_cap, error)
ccall((:bk_add_edge_float, libbkmaxflow), Void, (bk_graph_float, Cint, Cint, Cfloat, Cfloat, Ptr{bk_error}), g, i, j, cap, rev_cap, error)
ccall((:bk_add_edge_float, libbkmaxflow), Cvoid, (bk_graph_float, Cint, Cint, Cfloat, Cfloat, Ptr{bk_error}), g, i, j, cap, rev_cap, error)
end

function bk_add_edge_double(g, i, j, cap, rev_cap, error)
ccall((:bk_add_edge_double, libbkmaxflow), Void, (bk_graph_double, Cint, Cint, Cdouble, Cdouble, Ptr{bk_error}), g, i, j, cap, rev_cap, error)
ccall((:bk_add_edge_double, libbkmaxflow), Cvoid, (bk_graph_double, Cint, Cint, Cdouble, Cdouble, Ptr{bk_error}), g, i, j, cap, rev_cap, error)
end

function bk_maxflow_int(g, reuse_trees, error)
Expand Down
20 changes: 10 additions & 10 deletions gen/api/bk_common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ const SOURCE = (UInt32)(0)
const SINK = (UInt32)(1)
# end enum bk_termtype

error = Void
error = Cvoid

const bk_error = Ptr{Void}
const bk_error = Ptr{Cvoid}

graph_int = Void
graph_int = Cvoid

const bk_graph_int = Ptr{Void}
const bk_graph_int = Ptr{Cvoid}

graph_short = Void
graph_short = Cvoid

const bk_graph_short = Ptr{Void}
const bk_graph_short = Ptr{Cvoid}

graph_float = Void
graph_float = Cvoid

const bk_graph_float = Ptr{Void}
const bk_graph_float = Ptr{Cvoid}

graph_double = Void
graph_double = Cvoid

const bk_graph_double = Ptr{Void}
const bk_graph_double = Ptr{Cvoid}
2 changes: 2 additions & 0 deletions src/bitmask.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
BK_T_ACTIVE = 0x0c, # BK_T | BK_ACTIVE
)

Base.convert(::Type{BKStatusBits}, x::UInt8) = BKStatusBits(x)

Base.:~(x::BKStatusBits) = ~UInt8(x)

Base.:|(x::UInt8, y::BKStatusBits) = x | UInt8(y)
Expand Down
18 changes: 9 additions & 9 deletions src/boykov_kolmogorov.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ function PATH(s, t, i, source, sink, PARENT, INDEX)
idxs = Int[]
sᵢ = tᵢ = i
while s != source
unshift!(path, s)
unshift!(idxs, sᵢ)
pushfirst!(path, s)
pushfirst!(idxs, sᵢ)
s, sᵢ = PARENT[s], INDEX[s]
end
unshift!(path, s)
unshift!(idxs, sᵢ)
pushfirst!(path, s)
pushfirst!(idxs, sᵢ)
pop!(idxs) # pop i out since we gonna push it again
while t != sink
push!(path, t)
Expand Down Expand Up @@ -66,7 +66,7 @@ function growth_stage!(source, sink, neighbors, residual, A, STATUS, PARENT, IND
# then add q to search tree as an active node
STATUS[q] = STATUS[p]
PARENT[q] = p
unshift!(A, q) # "First-In-First-Out": enqueue -> queue -> dequeue
pushfirst!(A, q) # "First-In-First-Out": enqueue -> queue -> dequeue
INDEX[q] = qᵢ # cache index for referencing residual in augmentation stage
end
TREE(q)&& TREE(q)TREE(p) && return TREE(p)==BK_S ? PATH(p,q,qᵢ,source,sink,PARENT,INDEX) : PATH(q,p,qᵢ,source,sink,PARENT,INDEX)
Expand Down Expand Up @@ -104,12 +104,12 @@ function augmentation_stage!(neighbors, residual, P, IDX, O, STATUS, PARENT, IND
end
if TREE(p) == TREE(q) == BK_S
PARENT[q] = 0
unshift!(O, q)
pushfirst!(O, q)
INDEX[q] = 0 # clean up index cache
end
if TREE(p) == TREE(q) == BK_T
PARENT[p] = 0
unshift!(O, p)
pushfirst!(O, p)
INDEX[p] = 0 # clean up index cache
end
end
Expand Down Expand Up @@ -148,8 +148,8 @@ function adoption_stage!(source, sink, neighbors, residual, O, A, ORPHAN, STATUS
@inbounds for (q,qᵢ) in neighbors[p]
TREE(q) == TREE(p) || continue
tree_cap = TREE(p)==BK_S ? (q < p ? residual[1,qᵢ] : residual[2,qᵢ]) : (q < p ? residual[2,qᵢ] : residual[1,qᵢ])
tree_cap > 0 && (STATUS[q] |= BK_ACTIVE; unshift!(A, q);)
PARENT[q] == p && (PARENT[q] = 0; INDEX[q] = 0; unshift!(O, q);)
tree_cap > 0 && (STATUS[q] |= BK_ACTIVE; pushfirst!(A, q);)
PARENT[q] == p && (PARENT[q] = 0; INDEX[q] = 0; pushfirst!(O, q);)
end
# TREE(p) := ∅, A := A - {p}
STATUS[p] = BK_FREE # note that this also marks p as inactive node
Expand Down
12 changes: 6 additions & 6 deletions src/c_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ end
end
end

@generated function delete_graph(::Type{CImpl{Tv}}, graph::Ptr{Void}) where {Tv<:Real}
@generated function delete_graph(::Type{CImpl{Tv}}, graph::Ptr{Cvoid}) where {Tv<:Real}
if Tv == Cint
return :(bk_delete_graph_int(graph))
elseif Tv == Cshort
Expand All @@ -83,7 +83,7 @@ end
end
end

@generated function add_node(::Type{CImpl{Tv}}, graph::Ptr{Void}, num::Integer=1) where {Tv<:Real}
@generated function add_node(::Type{CImpl{Tv}}, graph::Ptr{Cvoid}, num::Integer=1) where {Tv<:Real}
if Tv == Cint
return quote
err = Ref{bk_error}(C_NULL)
Expand Down Expand Up @@ -115,7 +115,7 @@ end
end
end

@generated function add_tweights(::Type{CImpl}, graph::Ptr{Void}, id::Integer, cap_source::Tv, cap_sink::Tv) where {Tv<:Real}
@generated function add_tweights(::Type{CImpl}, graph::Ptr{Cvoid}, id::Integer, cap_source::Tv, cap_sink::Tv) where {Tv<:Real}
if Tv == Cint
return quote
err = Ref{bk_error}(C_NULL)
Expand Down Expand Up @@ -143,7 +143,7 @@ end
end
end

@generated function add_edge(::Type{CImpl}, graph::Ptr{Void}, i::Integer, j::Integer, cap::Tv, rev_cap::Tv) where {Tv<:Real}
@generated function add_edge(::Type{CImpl}, graph::Ptr{Cvoid}, i::Integer, j::Integer, cap::Tv, rev_cap::Tv) where {Tv<:Real}
if Tv == Cint
return quote
err = Ref{bk_error}(C_NULL)
Expand Down Expand Up @@ -171,7 +171,7 @@ end
end
end

@generated function maxflow(::Type{CImpl{Tv}}, graph::Ptr{Void}, reuse_trees::Bool=false) where {Tv<:Real}
@generated function maxflow(::Type{CImpl{Tv}}, graph::Ptr{Cvoid}, reuse_trees::Bool=false) where {Tv<:Real}
if Tv == Cint
return quote
err = Ref{bk_error}(C_NULL)
Expand Down Expand Up @@ -203,7 +203,7 @@ end
end
end

@generated function what_segment(::Type{CImpl{Tv}}, graph::Ptr{Void}, i::Integer) where {Tv<:Real}
@generated function what_segment(::Type{CImpl{Tv}}, graph::Ptr{Cvoid}, i::Integer) where {Tv<:Real}
if Tv == Cint
return quote
err = Ref{bk_error}(C_NULL)
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using BKMaxflow
using Base.Test
using Test

# Julia API
weights, neighbors = create_graph(JuliaImpl{Float64,Int}, 4)
Expand Down

0 comments on commit f344785

Please sign in to comment.