Code Monkey home page Code Monkey logo

rmaxcut's Introduction

Introduction

Rmaxcut finds an approximate solution to a weighted max-cut problem via random perturbation. Each line in an input file consists of the first nodeID, the second nodeID and an integer weight. The output gives

N  nodeID   spin     w++  w+-  w-+  w--
E  nodeID1  nodeID2  weight  spin1  spin2

where spin is either 1 or -1, indicating the partition of nodeID. On an N-line, w++ is the sum of positive weights of neighbors with positive spins; other w** numbers are similar. These numbers are mostly for debugging purposes.

To try rmaxcut, you may acquire x-all.txt.gz from the download page and run

rmaxcut -r20000 x-all.txt.gz > test.out 2> test.err

It will take a couple of minutes on a single thread. Increasing option -r, the number of iterations, often leads to a better solution for the largest few connected components. Rmaxcut emits good enough solutions to problems at my hand. I haven't compared it to other more sophisticated max-cut solvers. Use with caution.

Algorithms

The weighted max-cut problem is to find a bipartition in an undirected graph such that the sum of edge weights between the two partitions are maximized. Max-cut is NP-complete. In physics, solving max-cut is equivalent to finding optimal states in an Ising model without external fields. We often take ideas in physics to find approximate solutions to large-scale max-cut problems. This repo provides such an implementation. It uses a fairly naive algorithm:

  1. Find connected component. Do the following in each component.
  2. Randomly partition nodes, or equivalently, randomly assign a spin {-1,1} to each node.
  3. For each node, flip its spin if doing that increases the weight. Repeat until the total weight can't be improved this way. This is a local maximum.
  4. Randomly flip 10% of spins, or flip the spins of nodes within a certain distance from a random node (done by BFS). Do step 3 again. If the new local maximum is better, do step 4 on the new state; otherwise, do step 4 on the old state.
  5. Repeat 3-4 for many times. Then move to the next component.

The algorithm is akin to simulated annealing but without proper annealing. When I have time, I need to try more sophisticated procedures in vein of Monte Carlo methods. This may speed up heuristic search.

rmaxcut's People

Contributors

lh3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.