Skip to content

Adding Advanced Support for Linear Program Analysis #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1a7f68d
Introducing conversion methods from the Simplex repo
kwesiRutledge May 14, 2025
f833ade
Upgrading SymbolicMath.go dependency
kwesiRutledge May 14, 2025
0d33117
Upgrading the version of Go used in the testing workflow
kwesiRutledge May 14, 2025
037cdd6
Adding support for new gonum mat
kwesiRutledge May 14, 2025
7279ba1
tidying
kwesiRutledge May 14, 2025
2cc82ca
Adding new errors and example
kwesiRutledge May 14, 2025
732fbf6
Migrated to helper utilities from simplex to MPI: Transforming optimi…
kwesiRutledge May 14, 2025
db08ec8
Changed function signature for getting linear equality and inequality…
kwesiRutledge May 14, 2025
ea584ab
renamed some parts of workflow
kwesiRutledge May 14, 2025
cbe9259
Attempting to use newer version of action with specific file name input
kwesiRutledge May 14, 2025
d089794
Attempting to improve when the workflow is triggered
kwesiRutledge May 14, 2025
bbafc71
hail mary; does coverage2 contain useful info for upload?
kwesiRutledge May 14, 2025
be1e06a
Added tests for calling the LinearInequalityConstraintMatrices and Li…
kwesiRutledge May 15, 2025
76b9b2f
Introduced tests to cover more of the cases in ToLPStandardForm1
kwesiRutledge May 16, 2025
d008772
Small formatting of ToLPStandardForm1
kwesiRutledge May 16, 2025
da2d52c
Added a new error for when an optimization problem is not linear
kwesiRutledge May 16, 2025
227ffe2
Fixed typo in one of the for loops
kwesiRutledge May 16, 2025
07ac53c
Added tests for a few more corner cases of LPStandardForm1 inputs
kwesiRutledge May 16, 2025
ca948fb
Did some test renaming
kwesiRutledge May 16, 2025
c5597d5
Added test for the not well defined possibility of CheckIfLinear
kwesiRutledge May 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions .github/workflows/coverage1.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
name: Go # The name of the workflow that will appear on Github
name: Testing # The name of the workflow that will appear on Github

on:
push:
branches: [ main , kr-feature-problem1 ]
pull_request:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
build:
compute-coverage:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
go: [1.19]
go: [1.23]
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
Expand All @@ -40,7 +37,8 @@ jobs:
go tool cover -func coverage.out -o coverage2.out

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v5
with:
files: ./coverage2.out
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.out
9 changes: 9 additions & 0 deletions causeOfProblemNonlinearity/causes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package causeOfProblemNonlinearity

type Cause string

const (
Objective Cause = "Objective"
Constraint = "Constraint"
NotWellDefined = "NotWellDefined"
)
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
module github.com/MatProGo-dev/MatProInterface.go

go 1.21
go 1.23.0

require gonum.org/v1/gonum v0.14.0
toolchain go1.23.9

require github.com/MatProGo-dev/SymbolicMath.go v0.2.1
require gonum.org/v1/gonum v0.16.0

require github.com/MatProGo-dev/SymbolicMath.go v0.2.2
16 changes: 4 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
github.com/MatProGo-dev/SymbolicMath.go v0.1.8 h1:lpe+6cK/2fg29WwxOykm4hKvfJeqvFUBGturC9qh5ug=
github.com/MatProGo-dev/SymbolicMath.go v0.1.8/go.mod h1:gKbGR/6sYWi2koMUEDIPWBPi6jQPELKle0ijIM+eaHU=
github.com/MatProGo-dev/SymbolicMath.go v0.1.9 h1:NMqvS9Bt2DWWLGxd+j3Qta4Ckq/x74gpMM7bt32om5g=
github.com/MatProGo-dev/SymbolicMath.go v0.1.9/go.mod h1:gKbGR/6sYWi2koMUEDIPWBPi6jQPELKle0ijIM+eaHU=
github.com/MatProGo-dev/SymbolicMath.go v0.2.0 h1:W8IREsZGeIuPAKHgJDyeCr3vLJjMr6H/O9RNFAjOVp8=
github.com/MatProGo-dev/SymbolicMath.go v0.2.0/go.mod h1:gKbGR/6sYWi2koMUEDIPWBPi6jQPELKle0ijIM+eaHU=
github.com/MatProGo-dev/SymbolicMath.go v0.2.1 h1:3qcLYNx3+9Ud/saS4QWxJzmDUbVvYZIWt9aX2bQ9iOk=
github.com/MatProGo-dev/SymbolicMath.go v0.2.1/go.mod h1:gKbGR/6sYWi2koMUEDIPWBPi6jQPELKle0ijIM+eaHU=
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 h1:ooxPy7fPvB4kwsA2h+iBNHkAbp/4JxTSwCmvdjEYmug=
golang.org/x/exp v0.0.0-20230321023759-10a507213a29/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
gonum.org/v1/gonum v0.14.0 h1:2NiG67LD1tEH0D7kM+ps2V+fXmsAnpUeec7n8tcr4S0=
gonum.org/v1/gonum v0.14.0/go.mod h1:AoWeoz0becf9QMWtE8iWXNXc27fK4fNeHNf/oMejGfU=
github.com/MatProGo-dev/SymbolicMath.go v0.2.2 h1:U9nLLgtslRXbweCsgW9uSw8AvoGMgjq2luQtXIuN3eA=
github.com/MatProGo-dev/SymbolicMath.go v0.2.2/go.mod h1:tW8thj4pkaTV9lFNU3OCKmwQ3mZ2Eim6S4JpHRDfRvU=
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
7 changes: 7 additions & 0 deletions mpiErrors/no_equality_constraints_found.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package mpiErrors

type NoEqualityConstraintsFoundError struct{}

func (e NoEqualityConstraintsFoundError) Error() string {
return "No equality constraints found in the optimization problem; please define some by adding them with \"testProblem1.Constraints = append(testProblem1.Constraints, newConstraint)\""
}
7 changes: 7 additions & 0 deletions mpiErrors/no_inequality_constraints_found.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package mpiErrors

type NoInequalityConstraintsFoundError struct{}

func (e NoInequalityConstraintsFoundError) Error() string {
return "No inequality constraints found in the optimization problem; please define some by adding them with \"testProblem1.Constraints = append(testProblem1.Constraints, newConstraint)\""
}
29 changes: 29 additions & 0 deletions mpiErrors/not_linear.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package mpiErrors

import (
"fmt"

"github.com/MatProGo-dev/MatProInterface.go/causeOfProblemNonlinearity"
)

type ProblemNotLinearError struct {
ProblemName string
Cause causeOfProblemNonlinearity.Cause
ConstraintIndex int // Index of the constraint that is not linear, if applicable
}

func (e ProblemNotLinearError) Error() string {
preamble := "The problem " + e.ProblemName + " is not linear"
switch e.Cause {
case causeOfProblemNonlinearity.Objective:
preamble += "; the objective is not linear"
case causeOfProblemNonlinearity.Constraint:
preamble += fmt.Sprintf("; constraint #%v is not linear", e.ConstraintIndex)
case causeOfProblemNonlinearity.NotWellDefined:
preamble += "; the problem is not well defined"
default:
preamble += "; the cause of the problem is not recognized (create an issue on GitHub if you think this is a bug!)"

Check warning on line 25 in mpiErrors/not_linear.go

View check run for this annotation

Codecov / codecov/patch

mpiErrors/not_linear.go#L24-L25

Added lines #L24 - L25 were not covered by tests
}
// Return the error message
return preamble
}
62 changes: 62 additions & 0 deletions problem/examples.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package problem

import (
getKMatrix "github.com/MatProGo-dev/SymbolicMath.go/get/KMatrix"
getKVector "github.com/MatProGo-dev/SymbolicMath.go/get/KVector"
"github.com/MatProGo-dev/SymbolicMath.go/symbolic"
)

/*
GetExampleProblem3
Description:

Returns the LP from this youtube video:
https://www.youtube.com/watch?v=QAR8zthQypc&t=483s
It should look like this:
Maximize 4 x1 + 3 x2 + 5 x3
Subject to
x1 + 2 x2 + 2 x3 <= 4
3 x1 + 4 x3 <= 6
2 x1 + x2 + 4 x3 <= 8
x1 >= 0
x2 >= 0
x3 >= 0
*/
func GetExampleProblem3() *OptimizationProblem {
// Setup
out := NewProblem("TestProblem3")

// Create variables
x := out.AddVariableVectorClassic(
3,
0.0,
symbolic.Infinity.Constant(),
symbolic.Continuous,
)

// Create Basic Objective
c := getKVector.From([]float64{4.0, 3.0, 5.0})
out.SetObjective(
c.Transpose().Multiply(x),
SenseMaximize,
)

// Create Constraints (using one big matrix)
A := getKMatrix.From([][]float64{
{1.0, 2.0, 2.0},
{3.0, 0.0, 4.0},
{2.0, 1.0, 4.0},
})
b := getKVector.From([]float64{4.0, 6.0, 8.0})
out.Constraints = append(out.Constraints, A.Multiply(x).LessEq(b))

// TODO(kwesi): Figure out how to add non-negativity constraints
// // Add non-negativity constraints
// for _, varII := range x {
// out.Constraints = append(
// out.Constraints,
// varII.GreaterEq(0.0),
// )
// }
return out
}
Loading