Skip to content

Commit

Permalink
Remove dependency on Combinatorics package.
Browse files Browse the repository at this point in the history
  • Loading branch information
tasseff committed Nov 5, 2023
1 parent fb196b8 commit 2b55a8d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 1 addition & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ name = "SecretSanta"
uuid = "bb3d3a65-b032-5cdd-a073-dfed7b606c01"
authors = ["Byron Tasseff"]
repo = "https://github.com/tasseff/SecretSanta.jl"
version = "0.2.2"
version = "0.2.3"

[deps]
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Expand All @@ -14,7 +13,6 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SMTPClient = "c35d69d1-b747-5018-a192-25bc5e63c83d"

[compat]
Combinatorics = "~1"
HiGHS = "~1"
JSON = "~0.21"
JuMP = "~0.22, ~0.23, ~1"
Expand Down
16 changes: 14 additions & 2 deletions src/SecretSanta.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module SecretSanta

import Combinatorics
import Dates
import HiGHS
import JSON
Expand All @@ -27,7 +26,7 @@ function SecretSantaModel(data::Dict{String,Any})

# Create arcs for a complete bipartite graph.
exclude = vcat([[[x["email"], y] for y in x["exclude"]] for x in P]...)
A = collect(Combinatorics.combinations(N, 2)) # Collect arcs from i to j.
A = get_combinations(N) # Get arcs from i to j.
A = vcat([reverse(a) for a in A], A) # Concatenate arcs from j to i.
A = filter(x -> !(x in exclude), A) # Remove excluded arcs.
A = [(a[1], a[2]) for a in A] # Convert to array of tuples.
Expand Down Expand Up @@ -68,6 +67,19 @@ function build_model(input_path::String)
end


function get_combinations(entries::Vector{String})::Vector{Vector{String}}
combinations = Vector{Vector{String}}()

for i in 1:length(entries)
for j in (i + 1):length(entries)
push!(combinations, [entries[i], entries[j]])
end
end

return combinations
end


function solve_model(ssm::SecretSantaModel)
JuMP.optimize!(ssm.model)

Expand Down

0 comments on commit 2b55a8d

Please sign in to comment.