-
Notifications
You must be signed in to change notification settings - Fork 80
Add bertsekas algo for assignment problem #600
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
Open
smu160
wants to merge
15
commits into
evenfurther:main
Choose a base branch
from
smu160:bertsekas
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
630a279
Add bertsekas algo for assignment problem
smu160 b9092c3
Utilize `Matrix` as cost matrix and add benchmark
smu160 2f3b7e4
Add lifetime to avoid cloning cost matrix
smu160 2fb3c22
Add example for profiling
smu160 63bc9bb
Add profile for profiling to manifest
smu160 57d80c8
Cleanup assignment phase
smu160 421d525
Cleanup bidding phase
smu160 d6cc805
More cleanup of assignment phase
smu160 a0055cf
Fix doc comment warning
smu160 32992ff
Remove cruising phase allocations of channels
smu160 ea0ec6c
Fix example so both matrices are generated at once
smu160 95df073
Merge branch 'evenfurther:main' into bertsekas
smu160 d2479d9
Fix example of assignment
smu160 322f8a1
Create simple csv output for example assignment
smu160 6c707cf
Modify bids for tasks (bids by agents) into SoA
smu160 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use codspeed_criterion_compat::{ | ||
black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput, | ||
}; | ||
use pathfinding::bertsekas::{bertsekas_aaap, Auction}; | ||
use pathfinding::prelude::{kuhn_munkres, Matrix}; | ||
use rand::Rng; | ||
|
||
fn create_matrices(size: usize) -> (Matrix<i64>, Matrix<f64>) { | ||
let mut rng = rand::thread_rng(); | ||
let int_matrix: Matrix<i64> = Matrix::from_fn(size, size, |_| rng.gen_range(0..100)); | ||
let float_matrix = int_matrix.clone().map(|value| value as f64); | ||
(int_matrix, float_matrix) | ||
} | ||
|
||
fn compare_algorithms(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("Assignment Problem"); | ||
let sizes = [10, 20, 50, 100, 200, 500, 1000]; | ||
|
||
for size in sizes.iter() { | ||
let elements = size * size; | ||
|
||
group.throughput(Throughput::Elements(elements as u64)); | ||
group.bench_function(BenchmarkId::new("Bertekas Auction", size), |b| { | ||
let (_, float_matrix) = black_box(create_matrices(*size)); | ||
b.iter_with_large_drop(|| { | ||
let mut auction_data = Auction::new(&float_matrix); | ||
bertsekas_aaap(&mut auction_data); | ||
}); | ||
}); | ||
|
||
group.throughput(Throughput::Elements(elements as u64)); | ||
group.bench_function(BenchmarkId::new("Hungarian Algorithm", size), |b| { | ||
let (int_64matrix, _) = black_box(create_matrices(*size)); | ||
b.iter_with_large_drop(|| kuhn_munkres(&int_64matrix)); | ||
}); | ||
} | ||
|
||
// Configure the plot | ||
group.plot_config( | ||
codspeed_criterion_compat::PlotConfiguration::default() | ||
.summary_scale(codspeed_criterion_compat::AxisScale::Logarithmic), | ||
); | ||
|
||
group.finish(); | ||
} | ||
|
||
criterion_group!(benches, compare_algorithms); | ||
criterion_main!(benches); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use pathfinding::bertsekas::{bertsekas_aaap, Auction}; | ||
use pathfinding::kuhn_munkres::kuhn_munkres; | ||
use pathfinding::matrix::Matrix; | ||
use rand::Rng; | ||
use std::time::Instant; | ||
|
||
fn generate_random_matrices(rows: usize, cols: usize) -> (Matrix<f64>, Matrix<i64>) { | ||
let mut rng = rand::thread_rng(); | ||
let random_numbers: Vec<i64> = (0..rows * cols).map(|_| rng.gen_range(1..500)).collect(); | ||
|
||
let matrix_int = Matrix::from_vec(rows, cols, random_numbers.clone()).unwrap(); | ||
let matrix_float = Matrix::from_vec( | ||
rows, | ||
cols, | ||
random_numbers.into_iter().map(|x| x as f64).collect(), | ||
) | ||
.unwrap(); | ||
|
||
(matrix_float, matrix_int) | ||
} | ||
|
||
fn main() { | ||
let sizes: [usize; 9] = [5, 10, 50, 100, 250, 500, 1000, 2500, 5000]; | ||
|
||
println!("Algorithm, Matrix Size, Time (ns), Score"); | ||
|
||
for &size in &sizes { | ||
let (f_matrix, i_matrix) = generate_random_matrices(size, size); | ||
|
||
let now = Instant::now(); | ||
let mut auction_data = Auction::new(&f_matrix); | ||
bertsekas_aaap(&mut auction_data); | ||
let score = auction_data.score().unwrap(); | ||
let elapsed = now.elapsed().as_nanos(); | ||
println!("Bertsekas, {size}x{size}, {elapsed}, {score}"); | ||
|
||
let now = Instant::now(); | ||
let (score, _) = kuhn_munkres(&i_matrix); | ||
let elapsed = now.elapsed().as_nanos(); | ||
println!("Kuhn_Munkres, {size}x{size}, {elapsed}, {score}"); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in the benchmark name: 'Bertekas Auction' should be corrected to 'Bertsekas Auction' to match the module name and maintain consistency.
Copilot uses AI. Check for mistakes.