Giter Club home page Giter Club logo

maxcutpy's Introduction

maxcutpy

A Python Implementation of Graph Max Cut Solutions

Problem Statement

The goal of this script is to provide simple python libraries for solving the Maximum cut problem.

Current Solvers

Universal

The Structure of all Solvers is the same, from an API point of view. This allows for quick testing of multiple different solvers, to find the best one.

In general, the flow will look like this:

from maxcutpy import RandomMaxCut
import numpy as np

matrix = np.array([[0,1,1],[1,0,5],[1,5,0]])
random_max_cut = RandomMaxCut(matrix=matrix, seed=12345)

best_cut_vector = random_cut.batch_split()

best_cut_vector will be a numpy array of shape (1,n) where n is the number of rows in the input matrix. Each number inside of best_cut_vector will be an integer 0 or 1, depending on if it belongs to the 0th Slice or the 1st Slice.

You can then generally check the score of this best_cut_vector by using the same object again:

best_cut_score = random_cut.best_cut_score

At this time, a single Solver Object is Single-Use only, meaning it gets created for a specific matrix, and provides a batch split for this matrix only. Once the result is calculated, it will be stored, and repeated calls to batch_split() will only return the cached result.

For now, the matrix must be in the form of a numpy adjacency matrix, but support will be added soon for networkx Graph objects, as well as helper functions to transform between the two.

RandomMaxCut

This solve provides a method to compare against, as all this Solver does is select a random set of vertices to cut, giving each vertex a 50% chance of occurring in a different slice of the graph.

from maxcutpy import RandomMaxCut
import numpy as np

matrix = np.array([[0,1,1],[1,0,5],[1,5,0]])
random_max_cut = RandomMaxCut(matrix=matrix, seed=12345)

best_cut_vector = random_cut.batch_split()

best_cut_vector will be a numpy array of shape (1,n) where each entry is a random integer 0 or 1, with 50% probability for either event. This means this could lead to the case where no cuts are made at all, yielding a score of 0.

maxcutpy's People

Contributors

trevorwieland avatar

Stargazers

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