This library can be used to fairly match students to categories (or activities). Or students to schools. Or anything to anything else.
Background
The matching problem this library solves is mathematically know as the residence problem and is a subset of the stable marriage problem. There are sereval known algorithms that solve this problem, each with there own pros and cons. For more information about the subject see also Matching algorithms for the secondary school admission problem in Amsterdam.
Algorithm
At this time this library only implements the Deferred Acceptance - Single Tie Break algorithm. The library has been designed to make the implementation of other algorithms possible (it just needs to be done ;).
Usage
Default matching
Students are distributed over multiple categories, but each student can only be placed once.
use match_students;
use ;
use thread_rng;
use VecDeque;
// Create categories
let cooking = new;
let reading = new;
let walking = new;
// Create student Bert
// Bert wishes to be placed in category cooking or reading (in that order)
let bert = new;
// Create student Suze
// Suze wishes to be placed in category cooking or reading (in that order),
// but does not wish to be placed in category walking
let suze = new;
let mut rng = thread_rng;
let categories = Vecfrom;
let match_result = match_students;
println!;
println!;
for category in &categories
if match_result.not_placable.is_empty
This should the following result:
Students matched to categories:
Cooking:
- Bert
Reading:
- Suze
Walking:
All students could be placed.
Place students in multiple categories
Students are distributed over multiple categories. A single student can be placed in more than one category.
Example
use ;
use match_students_to_multiple_categories;
use thread_rng;
use VecDeque;
// Create categories
let cooking = new;
let reading = new;
let walking = new;
// Create student Bert
// Bert wishes to be placed in category cooking or reading (in that order)
let bert = new;
// Create student Suze
// Suze wishes to be placed in category cooking or reading (in that order),
// but does not wish to be placed in category walking
let suze = new;
let mut rng = thread_rng;
let categories = Vecfrom;
let match_result = match_students_to_multiple_categories;
println!;
println!;
for category in &categories
if match_result.not_placable.is_empty
This should the following result:
Students matched to categories:
Cooking:
- Suze
- Bert
Reading:
- Bert
- Suze
Walking:
- Bert
All students could be placed.