Skip to content

Implementation of Hopcroft-Karp algorithm in R. (用R语言实现Hopcroft-Karp算法)

License

Notifications You must be signed in to change notification settings

GaoFangshu/Hopcroft-Karp-algorithm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

Hopcroft-Karp-algorithm

Implementation of Hopcroft-Karp algorithm in R

Here is an example:

source('C:/Users/Fangshu Gao/Desktop/Advisor/Hopcroft_Karp.R', encoding = 'UTF-8')
test1 <- matrix(c(1,1,0,0,1,0,1,
                  1,0,0,0,0,1,0,
                  0,1,0,0,0,0,0,
                  0,1,0,1,0,0,0,
                  0,1,0,1,0,0,0,
                  0,0,1,1,1,0,0,
                  0,0,0,0,0,1,0), nrow = 7, ncol = 7, byrow = TRUE)
test2 <- matrix(c(1,0,1,
                  0,1,0,
                  1,0,0), nrow = 3, ncol = 3, byrow = TRUE)
MMHK(test1)
> [1] 3 2 4 4 6 3 7 6 2 1 1 5
MMHK(test2)
> [1] 2 2 3 1 1 3

The result shows that matrix test1 has a maximum cardinality matching {(3,2),(4,4),(6,3),(7,6),(2,1),(1,5)} and matrix test2 has a perfect matching {(2,2),(3,1),(1,3)}.

More details can be found at my blog.

About

Implementation of Hopcroft-Karp algorithm in R. (用R语言实现Hopcroft-Karp算法)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages