Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions optim/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (m *Model) AddRealVariable() Variable {
return m.AddVariableClassic(-INFINITY, INFINITY, Continuous)
}

// AddVariable adds a variable of a given variable type to the model given the lower
// AddVariableClassic AddVariable adds a variable of a given variable type to the model given the lower
// and upper value limits. This variable is returned.
func (m *Model) AddVariableClassic(lower, upper float64, vtype VarType) Variable {
id := uint64(len(m.Variables))
Expand All @@ -50,7 +50,7 @@ func (m *Model) AddVariableClassic(lower, upper float64, vtype VarType) Variable
return newVar
}

// AddBinaryVar adds a binary variable to the model and returns said variable.
// AddBinaryVariable AddBinaryVar adds a binary variable to the model and returns said variable.
func (m *Model) AddBinaryVariable() Variable {
return m.AddVariableClassic(0, 1, Binary)
}
Expand Down Expand Up @@ -118,7 +118,7 @@ func (m *Model) AddBinaryVariableMatrix(rows, cols int) [][]Variable {
return m.AddVariableMatrix(rows, cols, 0, 1, Binary)
}

// AddConstr adds the given constraint to the model.
// AddConstraint AddConstr adds the given constraint to the model.
func (m *Model) AddConstraint(constr Constraint, errors ...error) error {
// Constants

Expand Down
2 changes: 1 addition & 1 deletion optim/scalar_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type ScalarExpression interface {
Check() error
}

// NewExpr returns a new expression with a single additive constant value, c,
// NewScalarExpression NewExpr returns a new expression with a single additive constant value, c,
// and no variables. Creating an expression like sum := NewExpr(0) is useful
// for creating new empty expressions that you can perform operatotions on
// later
Expand Down
2 changes: 1 addition & 1 deletion optim/scalar_linear_expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (sle ScalarLinearExpr) NumVars() int {
return sle.X.Len()
}

// Vars returns a slice of the Var ids in the expression
// IDs Vars returns a slice of the Var ids in the expression
func (sle ScalarLinearExpr) IDs() []uint64 {
return sle.X.IDs()
}
Expand Down
2 changes: 1 addition & 1 deletion optim/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (v Variable) NumVars() int {
return 1
}

// Vars returns a slice of the Var ids in the expression. For a variable, it
// IDs Vars returns a slice of the Var ids in the expression. For a variable, it
// always returns a singleton slice with the given variable ID.
func (v Variable) IDs() []uint64 {
return []uint64{v.ID}
Expand Down
84 changes: 36 additions & 48 deletions problem/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,18 @@ import (
"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 >= -1.0
x2 >= -1.0
x3 >= -1.0
*/
// GetExampleProblem3 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 >= -1.0
// x2 >= -1.0
// x3 >= -1.0
func GetExampleProblem3() *OptimizationProblem {
// Setup
out := NewProblem("TestProblem3")
Expand Down Expand Up @@ -61,22 +57,18 @@ func GetExampleProblem3() *OptimizationProblem {
return out
}

/*
GetExampleProblem4
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
*/
// GetExampleProblem4 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 GetExampleProblem4() *OptimizationProblem {
// Setup
out := NewProblem("TestProblem3")
Expand Down Expand Up @@ -108,22 +100,18 @@ func GetExampleProblem4() *OptimizationProblem {
return out
}

/*
GetExampleProblem5
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
*/
// GetExampleProblem5 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 GetExampleProblem5() *OptimizationProblem {
// Setup
out := NewProblem("TestProblem3")
Expand Down
14 changes: 2 additions & 12 deletions problem/objective.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,12 @@ func NewObjective(e symbolic.Expression, sense ObjSense) *Objective {
return &Objective{e, sense}
}

/*
IsLinear
Description:

This method returns true if the objective is linear, false otherwise.
*/
// IsLinear Returns true if the objective is linear, false otherwise.
func (o *Objective) IsLinear() bool {
return symbolic.IsLinear(o.Expression)
}

/*
SubstituteAccordingTo
Description:

Substitutes the variables in the objective according to the replacement map.
*/
// SubstituteAccordingTo Substitutes the variables in the objective according to the replacement map.
func (o *Objective) SubstituteAccordingTo(replacementMap map[symbolic.Variable]symbolic.Expression) *Objective {
newExpression := o.Expression.SubstituteAccordingTo(replacementMap)
return &Objective{newExpression, o.Sense}
Expand Down
7 changes: 1 addition & 6 deletions problem/objective_sense.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ const (
SenseFind ObjSense = "Find"
)

/*
ToObjSense
Description:

This method converts an input optim.ObjSense to a problem.ObjSense.
*/
// ToObjSense Converts an input optim.ObjSense to a problem.ObjSense.
func ToObjSense(sense optim.ObjSense) ObjSense {
if sense == optim.SenseMinimize {
return SenseMinimize
Expand Down
Loading