# roommate.checkStability: Check if a roommate matching is stable In matchingR: Matching Algorithms in R and C++

## Description

This function checks if a particular roommate matching is stable. A matching is stable if there is no roommate `r1` that would rather be matched to some other roommate `d2` than to his current roommate `r2` and the other roommate `d2` would rather be matched to `r1` than to his current roommate `d1`.

## Usage

 `1` ```roommate.checkStability(utils = NULL, pref = NULL, matching) ```

## Arguments

 `utils` is a matrix with cardinal utilities for each individual in the market. If there are `n` individuals, then this matrix will be of dimension `n-1` by `n`. Column `j` refers to the payoff that individual `j` receives from being matched to individual ```1, 2, ..., j-1, j+1, ...n```. If a square matrix is passed as `utils`, then the main diagonal will be removed. `pref` is a matrix with the preference order of each individual in the market. This argument is only required when `utils` is not provided. If there are `n` individuals, then this matrix will be of dimension `n-1` by `n`. The `i,j`th element refers to `j`'s `i`th most favorite partner. Preference orders can either be specified using R-indexing (starting at 1) or C++ indexing (starting at 0). The matrix `pref` must be of dimension `n-1` by `n`. Otherwise, the function will throw an error. `matching` is a vector of length `n` corresponding to the matchings that were formed. E.g. if the `4`th element of this vector is `6` then individual `4` was matched with individual `6`.

## Value

true if stable, false if not

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12``` ```# define preferences pref <- matrix(c( 3, 1, 2, 3, 4, 3, 4, 2, 2, 4, 1, 1 ), byrow = TRUE, ncol = 4) pref # compute matching results <- roommate(pref = pref) results # check if matching is stable roommate.checkStability(pref = pref, matching = results) ```

matchingR documentation built on May 25, 2021, 9:07 a.m.