Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

speedup greedy method #47

Merged
merged 18 commits into from
Jan 18, 2025
Merged

speedup greedy method #47

merged 18 commits into from
Jan 18, 2025

Conversation

GiggleLiu
Copy link
Collaborator

@GiggleLiu GiggleLiu commented Jan 9, 2025

Before

julia> @btime res = OptimalBranchingMIS.OptimalBranchingCore.greedymerge(candidates, MISProblem(graph), vs, m)
  359.852 ms (1598250 allocations: 270.76 MiB)
OptimalBranchingResult{LongLongUInt{1}, Int64}:
 optimal_rule: DNF{LongLongUInt{1}}: (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #5 ∧ ¬#6 ∧ #7 ∧ ¬#8 ∧ #9 ∧ ¬#10 ∧ ¬#11 ∧ ¬#12 ∧ #13 ∧ #14 ∧ ¬#15 ∧ ¬#16 ∧ #17 ∧ #18 ∧ ¬#19 ∧ ¬#20 ∧ #21 ∧ #22) ∨ (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #6 ∧ #8 ∧ #10 ∧ ¬#13 ∧ ¬#14 ∧ ¬#17 ∧ ¬#18 ∧ ¬#21 ∧ ¬#22) ∨ (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #5 ∧ ¬#6 ∧ #8 ∧ #10 ∧ ¬#11 ∧ ¬#12 ∧ #13 ∧ #14 ∧ ¬#17 ∧ ¬#18 ∧ ¬#21 ∧ ¬#22) ∨ (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #6 ∧ #7 ∧ ¬#8 ∧ #10 ∧ ¬#13 ∧ ¬#14 ∧ ¬#15 ∧ ¬#16 ∧ #17 ∧ #18 ∧ ¬#21 ∧ ¬#22) ∨ (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #6 ∧ #8 ∧ #9 ∧ ¬#10 ∧ ¬#13 ∧ ¬#14 ∧ ¬#17 ∧ ¬#18 ∧ ¬#19 ∧ ¬#20 ∧ #21 ∧ #22) ∨ (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #5 ∧ ¬#6 ∧ #7 ∧ ¬#8 ∧ #10 ∧ ¬#11 ∧ ¬#12 ∧ #13 ∧ #14 ∧ ¬#15 ∧ ¬#16 ∧ #17 ∧ #18 ∧ ¬#21 ∧ ¬#22) ∨ (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #5 ∧ ¬#6 ∧ #8 ∧ #9 ∧ ¬#10 ∧ ¬#11 ∧ ¬#12 ∧ #13 ∧ #14 ∧ ¬#17 ∧ ¬#18 ∧ ¬#19 ∧ ¬#20 ∧ #21 ∧ #22) ∨ (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #6 ∧ #7 ∧ ¬#8 ∧ #9 ∧ ¬#10 ∧ ¬#13 ∧ ¬#14 ∧ ¬#15 ∧ ¬#16 ∧ #17 ∧ #18 ∧ ¬#19 ∧ ¬#20 ∧ #21 ∧ #22) ∨ (¬#1 ∧ #2 ∧ #3 ∧ ¬#5 ∧ ¬#6 ∧ ¬#7 ∧ ¬#8) ∨ (¬#1 ∧ #2 ∧ ¬#3 ∧ #4 ∧ ¬#5 ∧ ¬#6 ∧ #8 ∧ ¬#9 ∧ ¬#10 ∧ ¬#17 ∧ ¬#18) ∨ (¬#1 ∧ ¬#2 ∧ #3 ∧ #4 ∧ #6 ∧ ¬#7 ∧ ¬#8 ∧ ¬#9 ∧ ¬#10 ∧ ¬#13 ∧ ¬#14)
 branching_vector: [46, 28, 34, 34, 34, 40, 40, 40, 16, 24, 24]
 γ: 1.0842073740067577

After

julia> @btime res = OptimalBranchingMIS.OptimalBranchingCore.greedymerge(candidates, MISProblem(graph), vs, m)
@pro  3.816 ms (172 allocations: 183.97 KiB)
OptimalBranchingResult{LongLongUInt{1}, Int64}:
 optimal_rule: DNF{LongLongUInt{1}}: (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #6 ∧ #8 ∧ #10 ∧ ¬#13 ∧ ¬#14 ∧ ¬#17 ∧ ¬#18 ∧ ¬#21 ∧ ¬#22) ∨ (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #5 ∧ ¬#6 ∧ #8 ∧ #10 ∧ ¬#11 ∧ ¬#12 ∧ #13 ∧ #14 ∧ ¬#17 ∧ ¬#18 ∧ ¬#21 ∧ ¬#22) ∨ (¬#1 ∧ #2 ∧ #3 ∧ ¬#5 ∧ ¬#6 ∧ ¬#7 ∧ ¬#8) ∨ (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #6 ∧ #7 ∧ ¬#8 ∧ #10 ∧ ¬#13 ∧ ¬#14 ∧ ¬#15 ∧ ¬#16 ∧ #17 ∧ #18 ∧ ¬#21 ∧ ¬#22) ∨ (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #5 ∧ ¬#6 ∧ #7 ∧ ¬#8 ∧ #10 ∧ ¬#11 ∧ ¬#12 ∧ #13 ∧ #14 ∧ ¬#15 ∧ ¬#16 ∧ #17 ∧ #18 ∧ ¬#21 ∧ ¬#22) ∨ (¬#1 ∧ #2 ∧ ¬#3 ∧ #4 ∧ ¬#5 ∧ ¬#6 ∧ #8 ∧ ¬#9 ∧ ¬#10 ∧ ¬#17 ∧ ¬#18) ∨ (¬#1 ∧ ¬#2 ∧ #3 ∧ #4 ∧ #6 ∧ ¬#7 ∧ ¬#8 ∧ ¬#9 ∧ ¬#10 ∧ ¬#13 ∧ ¬#14) ∨ (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #6 ∧ #8 ∧ #9 ∧ ¬#10 ∧ ¬#13 ∧ ¬#14 ∧ ¬#17 ∧ ¬#18 ∧ ¬#19 ∧ ¬#20 ∧ #21 ∧ #22) ∨ (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #5 ∧ ¬#6 ∧ #8 ∧ #9 ∧ ¬#10 ∧ ¬#11 ∧ ¬#12 ∧ #13 ∧ #14 ∧ ¬#17 ∧ ¬#18 ∧ ¬#19 ∧ ¬#20 ∧ #21 ∧ #22) ∨ (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #6 ∧ #7 ∧ ¬#8 ∧ #9 ∧ ¬#10 ∧ ¬#13 ∧ ¬#14 ∧ ¬#15 ∧ ¬#16 ∧ #17 ∧ #18 ∧ ¬#19 ∧ ¬#20 ∧ #21 ∧ #22) ∨ (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #5 ∧ ¬#6 ∧ #7 ∧ ¬#8 ∧ #9 ∧ ¬#10 ∧ ¬#11 ∧ ¬#12 ∧ #13 ∧ #14 ∧ ¬#15 ∧ ¬#16 ∧ #17 ∧ #18 ∧ ¬#19 ∧ ¬#20 ∧ #21 ∧ #22)
 branching_vector: [28, 34, 16, 34, 40, 24, 24, 34, 40, 40, 46]
 γ: 1.0842073740067577

@ArrogantGao ArrogantGao requested a review from nzy1997 January 9, 2025 05:40
Copy link

codecov bot commented Jan 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Files with missing lines Coverage Δ
lib/OptimalBranchingCore/src/branch.jl 96.55% <100.00%> (+96.55%) ⬆️
lib/OptimalBranchingCore/src/greedymerge.jl 100.00% <100.00%> (+90.00%) ⬆️
lib/OptimalBranchingCore/src/mockproblem.jl 100.00% <100.00%> (ø)
lib/OptimalBranchingCore/src/setcovering.jl 95.45% <100.00%> (+0.75%) ⬆️
lib/OptimalBranchingMIS/src/graphs.jl 97.33% <100.00%> (+0.45%) ⬆️
lib/OptimalBranchingMIS/src/selector.jl 96.61% <100.00%> (-0.22%) ⬇️
lib/OptimalBranchingMIS/src/types.jl 89.28% <100.00%> (+0.82%) ⬆️

... and 3 files with indirect coverage changes

@nzy1997
Copy link
Collaborator

nzy1997 commented Jan 9, 2025

One test on mock problem didn't pass.

@nzy1997
Copy link
Collaborator

nzy1997 commented Jan 10, 2025

Benchmarks Before Using Priority Queue

@btime result = OptimalBranchingMIS.OptimalBranchingCore.greedymerge(candidates, MISProblem(graph), vs, m)
  3.804 ms (172 allocations: 183.97 KiB)
OptimalBranchingResult{LongLongUInt{1}, Int64}:
 optimal_rule: DNF{LongLongUInt{1}}: (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #6 ∧ #8 ∧ #10 ∧ ¬#13 ∧ ¬#14 ∧ ¬#17 ∧ ¬#18 ∧ ¬#21 ∧ ¬#22) ∨ (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #5 ∧ ¬#6 ∧ #8 ∧ #10 ∧ ¬#11 ∧ ¬#12 ∧ #13 ∧ #14 ∧ ¬#17 ∧ ¬#18 ∧ ¬#21 ∧ ¬#22) ∨ (¬#1 ∧ #2 ∧ #3 ∧ ¬#5 ∧ ¬#6 ∧ ¬#7 ∧ ¬#8) ∨ (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #6 ∧ #7 ∧ ¬#8 ∧ #10 ∧ ¬#13 ∧ ¬#14 ∧ ¬#15 ∧ ¬#16 ∧ #17 ∧ #18 ∧ ¬#21 ∧ ¬#22) ∨ (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #5 ∧ ¬#6 ∧ #7 ∧ ¬#8 ∧ #10 ∧ ¬#11 ∧ ¬#12 ∧ #13 ∧ #14 ∧ ¬#15 ∧ ¬#16 ∧ #17 ∧ #18 ∧ ¬#21 ∧ ¬#22) ∨ (¬#1 ∧ #2 ∧ ¬#3 ∧ #4 ∧ ¬#5 ∧ ¬#6 ∧ #8 ∧ ¬#9 ∧ ¬#10 ∧ ¬#17 ∧ ¬#18) ∨ (¬#1 ∧ ¬#2 ∧ #3 ∧ #4 ∧ #6 ∧ ¬#7 ∧ ¬#8 ∧ ¬#9 ∧ ¬#10 ∧ ¬#13 ∧ ¬#14) ∨ (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #6 ∧ #8 ∧ #9 ∧ ¬#10 ∧ ¬#13 ∧ ¬#14 ∧ ¬#17 ∧ ¬#18 ∧ ¬#19 ∧ ¬#20 ∧ #21 ∧ #22) ∨ (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #5 ∧ ¬#6 ∧ #8 ∧ #9 ∧ ¬#10 ∧ ¬#11 ∧ ¬#12 ∧ #13 ∧ #14 ∧ ¬#17 ∧ ¬#18 ∧ ¬#19 ∧ ¬#20 ∧ #21 ∧ #22) ∨ (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #6 ∧ #7 ∧ ¬#8 ∧ #9 ∧ ¬#10 ∧ ¬#13 ∧ ¬#14 ∧ ¬#15 ∧ ¬#16 ∧ #17 ∧ #18 ∧ ¬#19 ∧ ¬#20 ∧ #21 ∧ #22) ∨ (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #5 ∧ ¬#6 ∧ #7 ∧ ¬#8 ∧ #9 ∧ ¬#10 ∧ ¬#11 ∧ ¬#12 ∧ #13 ∧ #14 ∧ ¬#15 ∧ ¬#16 ∧ #17 ∧ #18 ∧ ¬#19 ∧ ¬#20 ∧ #21 ∧ #22)
 branching_vector: [28, 34, 16, 34, 40, 24, 24, 34, 40, 40, 46]
 γ: 1.0842073740067577

Benchmarks Now

@btime result = OptimalBranchingMIS.OptimalBranchingCore.greedymerge(candidates, MISProblem(graph), vs, m)
  6.005 ms (193 allocations: 27.47 KiB)
OptimalBranchingResult{LongLongUInt{1}, Float64}:
 optimal_rule: DNF{LongLongUInt{1}}: (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #6 ∧ #8 ∧ #10 ∧ ¬#13 ∧ ¬#14 ∧ ¬#17 ∧ ¬#18 ∧ ¬#21 ∧ ¬#22) ∨ (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #5 ∧ ¬#6 ∧ #8 ∧ #10 ∧ ¬#11 ∧ ¬#12 ∧ #13 ∧ #14 ∧ ¬#17 ∧ ¬#18 ∧ ¬#21 ∧ ¬#22) ∨ (¬#1 ∧ #2 ∧ #3 ∧ ¬#5 ∧ ¬#6 ∧ ¬#7 ∧ ¬#8 ∧ #15 ∧ ¬#16 ∧ #17 ∧ ¬#18 ∧ ¬#19 ∧ ¬#21) ∨ (¬#1 ∧ #2 ∧ #3 ∧ ¬#5 ∧ ¬#6 ∧ ¬#7 ∧ ¬#8 ∧ #11 ∧ ¬#12 ∧ #13 ∧ ¬#14 ∧ #16 ∧ ¬#17 ∧ ¬#22) ∨ (¬#1 ∧ #2 ∧ #3 ∧ ¬#5 ∧ ¬#6 ∧ ¬#7 ∧ ¬#8 ∧ ¬#11 ∧ #12 ∧ ¬#13 ∧ #14 ∧ ¬#15 ∧ #18 ∧ ¬#21) ∨ (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #6 ∧ #7 ∧ ¬#8 ∧ #9 ∧ ¬#13 ∧ ¬#14 ∧ ¬#15 ∧ ¬#16 ∧ #17 ∧ #18 ∧ ¬#19 ∧ ¬#20) ∨ (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #5 ∧ ¬#6 ∧ #7 ∧ ¬#8 ∧ #9 ∧ ¬#11 ∧ ¬#12 ∧ #13 ∧ #14 ∧ ¬#15 ∧ ¬#16 ∧ #17 ∧ #18 ∧ ¬#19 ∧ ¬#20) ∨ (¬#1 ∧ #3 ∧ #4 ∧ ¬#7 ∧ ¬#8 ∧ ¬#9 ∧ ¬#10 ∧ #15 ∧ ¬#16 ∧ #17 ∧ ¬#18) ∨ (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #5 ∧ #7 ∧ ¬#8 ∧ ¬#9 ∧ #10 ∧ ¬#11 ∧ ¬#12 ∧ ¬#15 ∧ ¬#16 ∧ #17 ∧ #18 ∧ #19 ∧ #20 ∧ ¬#21 ∧ ¬#22) ∨ (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ ¬#5 ∧ #6 ∧ #7 ∧ ¬#8 ∧ ¬#9 ∧ #10 ∧ #11 ∧ #12 ∧ ¬#13 ∧ ¬#14 ∧ ¬#15 ∧ ¬#16 ∧ #17 ∧ #18 ∧ #19 ∧ #20 ∧ ¬#21 ∧ ¬#22) ∨ (¬#1 ∧ #2 ∧ ¬#3 ∧ #4 ∧ ¬#5 ∧ ¬#6 ∧ #7 ∧ ¬#9 ∧ ¬#10 ∧ ¬#15 ∧ ¬#16 ∧ #19 ∧ ¬#20 ∧ #21 ∧ ¬#22) ∨ (¬#1 ∧ #2 ∧ #3 ∧ #4 ∧ ¬#5 ∧ ¬#6 ∧ ¬#7 ∧ ¬#8 ∧ ¬#9 ∧ ¬#10 ∧ ¬#11 ∧ #14 ∧ #19 ∧ ¬#20 ∧ #21 ∧ ¬#22) ∨ (¬#1 ∧ ¬#2 ∧ #3 ∧ #4 ∧ #6 ∧ ¬#7 ∧ ¬#8 ∧ ¬#9 ∧ ¬#10 ∧ ¬#13 ∧ ¬#14 ∧ ¬#15 ∧ #16 ∧ ¬#17 ∧ #18 ∧ #19 ∧ ¬#20 ∧ #21 ∧ ¬#22) ∨ (¬#1 ∧ #2 ∧ #4 ∧ ¬#5 ∧ ¬#6 ∧ ¬#9 ∧ ¬#10 ∧ ¬#17 ∧ ¬#19 ∧ #22) ∨ (¬#1 ∧ ¬#2 ∧ #3 ∧ #4 ∧ #5 ∧ ¬#7 ∧ ¬#8 ∧ ¬#9 ∧ ¬#10 ∧ ¬#11 ∧ ¬#12 ∧ ¬#15 ∧ #16 ∧ ¬#17 ∧ #18 ∧ ¬#19 ∧ #20 ∧ ¬#21 ∧ #22) ∨ (¬#1 ∧ #2 ∧ ¬#3 ∧ #4 ∧ ¬#5 ∧ ¬#6 ∧ #7 ∧ ¬#8 ∧ ¬#9 ∧ ¬#10 ∧ #11 ∧ ¬#12 ∧ #13 ∧ ¬#14 ∧ ¬#15 ∧ ¬#16 ∧ #17 ∧ #18 ∧ ¬#19 ∧ #20 ∧ ¬#21 ∧ #22) ∨ (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #6 ∧ #8 ∧ #9 ∧ ¬#10 ∧ ¬#13 ∧ ¬#14 ∧ ¬#17 ∧ ¬#18 ∧ ¬#19 ∧ ¬#20 ∧ #21 ∧ #22) ∨ (#1 ∧ ¬#2 ∧ ¬#3 ∧ ¬#4 ∧ #5 ∧ ¬#6 ∧ #8 ∧ #9 ∧ ¬#10 ∧ ¬#11 ∧ ¬#12 ∧ #13 ∧ #14 ∧ ¬#17 ∧ ¬#18 ∧ ¬#19 ∧ ¬#20 ∧ #21 ∧ #22)
 branching_vector: [28.0, 34.0, 32.0, 32.0, 32.0, 34.0, 40.0, 24.0, 40.0, 46.0, 32.0, 34.0, 40.0, 24.0, 40.0, 46.0, 34.0, 40.0]
 γ: 1.090233540640428

@GiggleLiu
Copy link
Collaborator Author

I also noticed that. It is so wield, since the algorithm should be the same. Is it possible that this is due to randomness? Since I noticed that when picking the largest value, there may be multiple candidates.

@GiggleLiu
Copy link
Collaborator Author

GiggleLiu commented Jan 11, 2025

02a0ce3

These are the relevant changes. After switching to priority queue, this value has been increased. I do not see any problem with this commit. Can you see any clue?

fyi: linear prog also has fluctuations in performance: #36

@GiggleLiu
Copy link
Collaborator Author

GiggleLiu commented Jan 11, 2025

Maybe test in branch count is more reasonable. Also, the benchmark. Instances with 71 bit string is too small. The advantage is more clear if you use the test instance.

@nzy1997
Copy link
Collaborator

nzy1997 commented Jan 12, 2025

Same test case with #45

using Test
using OptimalBranchingMIS
using OptimalBranchingCore
using OptimalBranchingMIS.Graphs


g = random_regular_graph(200, 3; seed = 2134)

bs = BranchingStrategy(table_solver = TensorNetworkSolver(), selector = KaHyParSelector(15), measure = D3Measure(), set_cover_solver = OptimalBranchingCore.GreedyMerge())
miskg, countkg = mis_branch_count(g; branching_strategy = bs)

(miskg, countkg) = (88, 13007)

@GiggleLiu
Copy link
Collaborator Author

I will get it merged, you can revert it later.

@GiggleLiu GiggleLiu merged commit 3fd91ea into nzykahypar Jan 18, 2025
6 checks passed
GiggleLiu added a commit that referenced this pull request Jan 18, 2025
* greedymerge

* size_reduction

* size_reduction

* spaces

* sapces

* add test on coverd_by

* fix test

* fix test

* update

* update-greedy-implementation

* merge and fix bugs

* fix doc

* save

* kahypar selector

* add more test

* rm simulated annealing

* speedup greedy method (#47)

* save

* update

* update

* update

* fix test

* use priority queue

* update

* add inbounds

* update

* ugly fix

* fix tests

* update

* new visualization

* update

* change name

---------

Co-authored-by: nzy <[email protected]>

---------

Co-authored-by: GiggleLiu <[email protected]>
Co-authored-by: nzy <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants