Code Monkey home page Code Monkey logo

k-way-kernighan-lin-algorithm's Introduction

Java Implementation of the Extended Kernighan-Lin Algorithm

Overview

This project presents a Java implementation of the Kernighan-Lin algorithm, traditionally used for solving the minimum-weight k-cut problem by dividing a graph into two subsets. The Kernighan-Lin algorithm is a heuristic method for partitioning a graph into two subsets, aiming to minimize the edge cut between them. This implementation extends the classic approach to support partitioning into k groups rather than just two. It's particularly useful in scenarios requiring a balanced partitioning of nodes while minimizing the sum of the weights of the edges that are cut.

Features

  • K-Group Partitioning: Unlike the traditional implementation that limits partitioning to two subsets, this version extends the functionality to support partitioning into k groups.
  • Weighted Graph Support: Fully supports graphs with weighted edges, optimizing for minimum-weight cuts.
  • Customizable Parameters: Offers flexibility in setting parameters like the number of desired partitions and initial partition states.
  • Efficient Implementation: Designed for performance, efficiently handling large graphs.

Pseudocode

k-Way Kernighan-Lin Algorithm

Pseudo-code:

Procedure Kernighan-Lin-k(G(V, E), k)
    Initialize a list S containing all vertices
    While length of S < k
        Identify the largest subset L in S
        Partition vertices in L into balanced sets A and B
        Repeat
            Compute D values for all a in A and b in B
            Let gv, av, and bv be empty lists
            For n := 1 to |L| / 2
                Find a in A and b in B to maximize g = D[a] + D[b] - 2 * c(a, b)
                Remove a and b from further consideration in this pass
                Add g to gv, a to av, and b to bv
                Update D values for the elements of A = A \ {a} and B = B \ {b}
            End For
            Find t which maximizes g_max, the sum of gv[1], ..., gv[t]
            If g_max > 0
                Exchange av[1], av[2], ..., av[t] with bv[1], bv[2], ..., bv[t]
            End If
        Until g_max <= 0
        Replace L in S with two new subsets A and B
    End While
    Return S (List of k subsets)
End Procedure

Prerequisites

  • Java JDK 8 or higher

Installation

Clone the repository and run the KernighanLinProgram.java

k-way-kernighan-lin-algorithm's People

Contributors

haidinhtuan avatar

Watchers

 avatar

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.