Simplex-Swift - A basic implementation of the Simplex algorithm, written in Swift

Overview

Simplex-Swift

This package contains a basic implementation of the Simplex algorithm.

Usage

1. Solving maximization problem

For example, given a function with constraints:

F = 7X1 + 8X2 + 10X3

2X1 + 3X2 + 2X3 ≤ 1000

X1 + X2 + 2X3 ≤ 800

We need to maximize F(X1 X2 X3).

let function    : [Double] = [7, 8, 10]
let constraint1 : [Double] = [2, 3, 2, 1000]
let constraint2 : [Double] = [1, 1, 2, 800]

if let solution = SimplexSolver.maximize(function: function, constraints: [constraint1, constraint2], maximumIterationsCount: 10) {
    let x1 = solution[0]  // 200
    let x2 = solution[1]  // 0
    let x3 = solution[2]  // 300
    let f  = solution[3]  // 4400
}

The maximum value of the function F(X1 X2 X3) is 4400 when X1 = 200, X2 = 0, X3 = 300.

2. Solving minimization problem

Another example, given a function with constraints:

F = 3X1 + 9X2

2X1 + X2 ≥ 8

X1 + 2X2 ≥ 8

Minimize F(X1 X2).

let function    : [Double] = [3, 9]
let constraint1 : [Double] = [2, 1, 8]
let constraint2 : [Double] = [1, 2, 8]

if let solution = SimplexSolver.minimize(function: function, constraints: [constraint1, constraint2], maximumIterationsCount: 10) {
    let x1 = solution[0]  // 8
    let x2 = solution[1]  // 0
    let f  = solution[2]  // 24
}

The minimum value of the function F(X1 X2) is 24 when X1 = 8, X2 = 0.

You might also like...
Simple and secure hashing in Swift with the SipHash algorithm

SipHash ⚠️ WARNING This package has been obsoleted by the Hasher type and the Hashable.hash(into:) requirement introduced in Swift 4.2. Using this pac

💻 A fast and flexible O(n) difference algorithm framework for Swift collection.
💻 A fast and flexible O(n) difference algorithm framework for Swift collection.

A fast and flexible O(n) difference algorithm framework for Swift collection. The algorithm is optimized based on the Paul Heckel's algorithm. Made wi

swift-algorithm 눈물이 차올라서 고갤 들어..
swift-algorithm 눈물이 차올라서 고갤 들어..

swift-algorithm 눈물이 차올라서 고갤 들어.. 알고리즘 정리 Union Find Dynamic Programming 자주 사용되는 문법 1. for문 거꾸로 돌리기 0...n의 반대 for i in stride(from: n, to: 0, by: -1) {

💻 A fast and flexible O(n) difference algorithm framework for Swift collection.
💻 A fast and flexible O(n) difference algorithm framework for Swift collection.

A fast and flexible O(n) difference algorithm framework for Swift collection. The algorithm is optimized based on the Paul Heckel's algorithm. Made wi

The Binary Search Algorithm in Swift 🤯 👨🏻‍💻
The Binary Search Algorithm in Swift 🤯 👨🏻‍💻

Binary Search in Swift Binary search is a simple algorithm that lets you search an array for a specific value. It’s trivial to implement in Swift, whi

Swift package wrapping the OpenWall BCrypt hashing algorithm

SwiftBCrypt A simple Swift Package wrapping the OpenWall BCrypt hashing algorithm. Generate Salt let bcryptSalt = try BCRypt.makeSalt() Hash Phrases

Debit/Credit card validation port of the Luhn Algorithm in Swift

SwiftLuhn Warning! This repository is no longer maintained. This is a port of the Luhn Algorithm, generally used for validating debit/credit card deta

Simple and secure hashing in Swift with the SipHash algorithm

SipHash ⚠️ WARNING This package has been obsoleted by the Hasher type and the Hashable.hash(into:) requirement introduced in Swift 4.2. Using this pac

Algorithm is a library of tools that is used to create intelligent applications.
Algorithm is a library of tools that is used to create intelligent applications.

Welcome to Algorithm Algorithm is a library of tools that is used to create intelligent applications. Features Probability Tools Expected Value Progra

Differific is a diffing tool that helps you compare Hashable objects using the Paul Heckel's diffing algorithm
Differific is a diffing tool that helps you compare Hashable objects using the Paul Heckel's diffing algorithm

Differific is a diffing tool that helps you compare Hashable objects using the Paul Heckel's diffing algorithm. Creating a chan

Algorithm is a library of tools that is used to create intelligent applications.
Algorithm is a library of tools that is used to create intelligent applications.

Welcome to Algorithm Algorithm is a library of tools that is used to create intelligent applications. Features Probability Tools Expected Value Progra

Simple macOS app that applies Apple's Person Segmentation algorithm to a video.
Simple macOS app that applies Apple's Person Segmentation algorithm to a video.

Simple macOS app that applies Apple's Person Segmentation algorithm to a video.

Luhn Credit Card Validation Algorithm

Luhn Algorithm This is a port of the Luhn Algorithm, generally used for validating Credit Card details, to Objective-C (iOS). Swift port can be found

A lightweight stochastic optimizer based on slime mold (Slime Mold Algorithm)
A lightweight stochastic optimizer based on slime mold (Slime Mold Algorithm)

Slime This is a Swift implementation of a Slime Mold Algorithm - a stochastic optimizer - generally based on this paper The only dependency required b

Luhn Credit Card Validation Algorithm

Luhn Algorithm This is a port of the Luhn Algorithm, generally used for validating Credit Card details, to Objective-C (iOS). Swift port can be found

A compiler with very basic capabilities written in Swift

BasicCompiler A compiler with very basic capabilities written in Swift. This project is not intended for real-world use; it's implemented just for fun

A very basic proof-of-concept Swift HTTP server that does not require Foundation

Swift Server Introduction This is very rough and basic HTTP server written in Swift without using Foundation. This is partially based on the Swifter r

Basic app to show how to login with Facebook, Google, Twitter. Created for learning purpose :) using Xcode 9 and Swift 4.0
Basic app to show how to login with Facebook, Google, Twitter. Created for learning purpose :) using Xcode 9 and Swift 4.0

Social Logins iOS Basic app to show how to login with Facebook, Google, Twitter. Created for learning purpose :) using Xcode 9 and Swift 4.0 Note: Bef

Code Swift iOS app showcasing basic movies list from Orange TV API.

iOS Code Test - Optiva Media Code Swift iOS app showcasing basic movies list from Orange TV API. Built using XCode 13.0 (Swift 5) How to run the examp

Owner
Evgeny Seliverstov
Evgeny Seliverstov
swift-algorithm 눈물이 차올라서 고갤 들어..

swift-algorithm 눈물이 차올라서 고갤 들어.. 알고리즘 정리 Union Find Dynamic Programming 자주 사용되는 문법 1. for문 거꾸로 돌리기 0...n의 반대 for i in stride(from: n, to: 0, by: -1) {

윤예지 6 Nov 8, 2022
Algorithm is a library of tools that is used to create intelligent applications.

Welcome to Algorithm Algorithm is a library of tools that is used to create intelligent applications. Features Probability Tools Expected Value Progra

Cosmicmind 821 Jan 9, 2023
An implementation of HAMT data-structure in Swift

HAMT (for Swift) An implementation of HAMT(Hash Array Mapped Trie, Bagwell) in Swift. Eonil, May 2019. Getting Started Use HAMT type. This type provid

Eonil 47 Jul 22, 2022
Fast sorted collections for Swift using in-memory B-trees

Fast Sorted Collections for Swift Using In-Memory B-Trees Overview Reference Documentation Optimizing Collections: The Book What Are B-Trees? Why In-M

null 1.3k Dec 20, 2022
Algorithms and data structures in Swift, with explanations!

Welcome to the Swift Algorithm Club! Here you'll find implementations of popular algorithms and data structures in everyone's favorite new language Sw

raywenderlich 27.2k Dec 30, 2022
AssignmentChalkboard - A simple assignment made in Swift

AssignmentChalkboard This is a simple assignment that i made in Swift

Angelos Staboulis 0 Jan 29, 2022
Swift implementation of the longest common subsequence (LCS) algorithm.

SwiftLCS SwitLCS provides an extension of Collection that finds the indexes of the longest common subsequence with another collection. The longest com

Tommaso Madonia 212 Dec 29, 2022
VidyoPlatform Basic CustomLayouts Reference App for iOS (Swift)VidyoPlatform Basic CustomLayouts Reference App for iOS (Swift)

VidyoPlatform Basic CustomLayouts Reference App for iOS (Swift) VidyoPlatform reference application highlighting how to integrate video chat into a na

Taras Melko 0 Nov 19, 2021
A mosaic collection view layout inspired by Lightbox's Algorithm, written in Swift 🔶

TRMosaicLayout A mosaic collection view layout inspired by Lightbox's Algorithm. This is a swift implementation/extension of @fmitech's FMMosaicLayout

Vincent Le 252 Nov 23, 2022
Swift-cuckoo-collections - Cross-platform Swift dictionaries & sets that use a cuckoo hashing algorithm

CuckooCollections A Swift package for open-addressed sets and dictionaries that

Christopher Richez 0 Aug 2, 2022