Giter Club home page Giter Club logo

kuhn-munkres's Introduction

Kuhn Munkres algorithm for weighted bipartite graph matching

This is a C++ implement of the Kuhn Munkres (KM) algorithm. Besides, we provide a Python interface named KM.pyd compiled using VS2017 and Python3.6.

Usage

  • C++
    Construct the KM object using the weight array of float type.
    float weights[] = { 3,5,5,4,1,2,2,0,2,2,2,4,4,1,0,1,2,1,3,3 };
    KM km(weights, 4, 5);   //KM(weight, rows, cols)
    km.compute();
    vector<int> match = km.getMatch(0);
    //If True, return the matched col nodes, else the matched row nodes
  • Python
    Construct the KM object using the weight list, which is a 1-d view of the 2-d weight matrix.
w=np.array([
    [3,5,5,4,1],
    [2,2,0,2,2],
    [2,4,4,1,0],
    [1,2,1,3,3]], np.float32).ravel().tolist()

km=KM.KM(w,4,5) #KM(weight, rows, cols)
km.compute()
matches=km.getMatch(True)   
#If True, return the matched col nodes, else the matched row nodes

Compile with Visual Studio

  • Build a DLL project in VS
  • Copy the km.h and km.cpp into your source folder
  • Add the Python include and library path to the peoject. The python36.lib is used.
  • Modify the project property. Set the target file name to KM and the target extension to pyd
  • Build, then you get xx.lib and KM.pyd

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.