GitHub - MatProGo-dev/simplex: A small library used to demonstrate the concepts of the Simplex algorithm in convex optimization.
Repository navigation
simplexPublic
About
A small library used to demonstrate the concepts of the Simplex algorithm in convex optimization.
Resources
Readme MIT license Activity Custom propertiesStars
1 starWatchers
1 watchingForks
0 forks Report repositoryBranches
Tags
Go to Branches page Go to Tags page
Latest commit
History
51 Commits
View commit history for this file.
Folders and files
| Name | Name | Last commit message | Last commit date |
|---|---|---|---|
| .github/ workflows | .github/ workflows | ||
| algorithms | algorithms | ||
| examples | examples | ||
| simplexSolver | simplexSolver | ||
| solution | solution | ||
| testing | testing | ||
| utils | utils | ||
| .gitignore | .gitignore | ||
| LICENSE | LICENSE | ||
| README.md | README.md | ||
| go.mod | go.mod | ||
| go.sum | go.sum | ||
Repository files navigation
simplex
A small library used to demonstrate the concepts of the Simplex algorithm in convex optimization.
Installation
You can add this module to your package using:
go get github.com/MatProGo-dev/simplex
Usage
package main
import (
"github.com/MatProGo-dev/MatProInterface.go/problem"
getKVector "github.com/MatProGo-dev/SymbolicMath.go/get/KVector"
"github.com/MatProGo-dev/SymbolicMath.go/symbolic"
"github.com/MatProGo-dev/simplex/simplexSolver"
)
func BuildOptimizationProblem() problem.OptimizationProblem {
// setup
varCount := 2
out := problem.NewProblem("Box LP Problem")
// Create the variables
x := out.AddVariableVector(varCount)
// Create the objective
c := getKVector.From(
[]float64{1, 2},
)
out.SetObjective(
c.Transpose().Multiply(x),
problem.SenseMinimize,
)
// Create the constraints
// - x >= 0
out.Constraints = append(
out.Constraints,
x.GreaterEq(symbolic.ZerosVector(varCount)),
)
// - x <= 1
out.Constraints = append(
out.Constraints,
x.LessEq(symbolic.OnesVector(varCount)),
)
return *out
}
func main() {
// This is just a placeholder to make the package "main" valid.
trickyProblem := BuildOptimizationProblem()
// Use solver to solve the problem
solver := simplexSolver.New("Simplex Solver Example")
solver.IterationLimit = 100
// Solve the problem
solution, err := solver.Solve(trickyProblem)
if err != nil {
panic(err)
}
// Print the solution
solutionMessage, _ := solution.Status.ToMessage()
println("Solution Status: ", solutionMessage)
println("Objective Value: ", solution.Objective)
println("Number of Iterations: ", solution.Iterations)
println("Variable Values: ")
for varName, varValue := range solution.VariableValues {
println(" ", varName, ": ", varValue)
}
}
See the examples directory for more example use cases for the library.
About
A small library used to demonstrate the concepts of the Simplex algorithm in convex optimization.