Skip to content

Commit 1f7eb68

Browse files
Refactor docstrings in optimization_problem.go to remove method names and Description labels
Co-authored-by: kwesiRutledge <9002730+kwesiRutledge@users.noreply.github.com>
1 parent 0291d34 commit 1f7eb68

1 file changed

Lines changed: 73 additions & 140 deletions

File tree

problem/optimization_problem.go

Lines changed: 73 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,14 @@ func NewProblem(name string) *OptimizationProblem {
3030
}
3131

3232
/*
33-
AddVariable
34-
Description:
35-
36-
This method adds an "unbounded" continuous variable to the model.
33+
This method adds an "unbounded" continuous variable to the model.
3734
*/
3835
func (op *OptimizationProblem) AddVariable() symbolic.Variable {
3936
return op.AddRealVariable()
4037
}
4138

4239
/*
43-
AddRealVariable
44-
Description:
45-
46-
Adds a Real variable to the model and returns said variable.
40+
Adds a Real variable to the model and returns said variable.
4741
*/
4842
func (op *OptimizationProblem) AddRealVariable() symbolic.Variable {
4943
return op.AddVariableClassic(-optim.INFINITY, optim.INFINITY, symbolic.Continuous)
@@ -71,11 +65,8 @@ func (op *OptimizationProblem) AddBinaryVariable() symbolic.Variable {
7165
}
7266

7367
/*
74-
AddVariableVector
75-
Description:
76-
77-
Creates a VarVector object using a constructor that assumes you want an "unbounded" vector of real optimization
78-
variables.
68+
Creates a VarVector object using a constructor that assumes you want an "unbounded" vector of real optimization
69+
variables.
7970
*/
8071
func (op *OptimizationProblem) AddVariableVector(dim int) symbolic.VariableVector {
8172
// Constants
@@ -89,10 +80,7 @@ func (op *OptimizationProblem) AddVariableVector(dim int) symbolic.VariableVecto
8980
}
9081

9182
/*
92-
AddVariableVectorClassic
93-
Description:
94-
95-
The classic version of AddVariableVector defined in the original goop.
83+
The classic version of AddVariableVector defined in the original goop.
9684
*/
9785
func (op *OptimizationProblem) AddVariableVectorClassic(
9886
num int, lower, upper float64, vtype symbolic.VarType,
@@ -141,10 +129,9 @@ func (op *OptimizationProblem) AddBinaryVariableMatrix(rows, cols int) [][]symbo
141129
}
142130

143131
/*
144-
SetObjective
145-
Description:
146-
sets the objective of the model given an expression and
147-
objective sense.
132+
Sets the objective of the model given an expression and
133+
objective sense.
134+
148135
Notes:
149136
To make this function easier to parse, we will assume an expression
150137
is given, even though objectives are normally scalars.
@@ -163,10 +150,7 @@ func (op *OptimizationProblem) SetObjective(e symbolic.Expression, sense ObjSens
163150
}
164151

165152
/*
166-
ToSymbolicConstraint
167-
Description:
168-
169-
Converts a constraint in the form of a optim.Constraint object into a symbolic.Constraint object.
153+
Converts a constraint in the form of a optim.Constraint object into a symbolic.Constraint object.
170154
*/
171155
func ToSymbolicConstraint(inputConstraint optim.Constraint) (symbolic.Constraint, error) {
172156
// Input Processing
@@ -207,10 +191,7 @@ func ToSymbolicConstraint(inputConstraint optim.Constraint) (symbolic.Constraint
207191
}
208192

209193
/*
210-
From
211-
Description:
212-
213-
Converts the given input into an optimization problem.
194+
Converts the given input into an optimization problem.
214195
*/
215196
func From(inputModel optim.Model) (*OptimizationProblem, error) {
216197
// Create a new optimization problem
@@ -273,10 +254,7 @@ func From(inputModel optim.Model) (*OptimizationProblem, error) {
273254
}
274255

275256
/*
276-
Check
277-
Description:
278-
279-
Checks that the OptimizationProblem is valid.
257+
Checks that the OptimizationProblem is valid.
280258
*/
281259
func (op *OptimizationProblem) Check() error {
282260
// Check Objective
@@ -310,13 +288,10 @@ func (op *OptimizationProblem) Check() error {
310288
}
311289

312290
/*
313-
IsLinear
314-
Description:
315-
316-
Checks if the optimization problem is linear.
317-
Per the definition of a linear optimization problem, the problem is linear if and only if:
318-
1. The objective function is linear (i.e., a constant or an affine combination of variables).
319-
2. All constraints are linear (i.e., an affine combination of variables in an inequality or equality).
291+
Checks if the optimization problem is linear.
292+
Per the definition of a linear optimization problem, the problem is linear if and only if:
293+
1. The objective function is linear (i.e., a constant or an affine combination of variables).
294+
2. All constraints are linear (i.e., an affine combination of variables in an inequality or equality).
320295
*/
321296
func (op *OptimizationProblem) IsLinear() bool {
322297
// Run the check method
@@ -346,14 +321,11 @@ func (op *OptimizationProblem) IsLinear() bool {
346321
}
347322

348323
/*
349-
LinearInequalityConstraintMatrices
350-
Description:
351-
352-
Returns the linear INEQUALITY constraint matrices and vectors.
353-
For all linear inequality constraints, we assemble them into the form:
354-
Ax <= b
355-
Where A is the matrix of coefficients, x is the vector of variables, and b is the vector of constants.
356-
We return A and b.
324+
Returns the linear INEQUALITY constraint matrices and vectors.
325+
For all linear inequality constraints, we assemble them into the form:
326+
Ax <= b
327+
Where A is the matrix of coefficients, x is the vector of variables, and b is the vector of constants.
328+
We return A and b.
357329
*/
358330
func (op *OptimizationProblem) LinearInequalityConstraintMatrices() (symbolic.KMatrix, symbolic.KVector, error) {
359331
// Setup
@@ -452,14 +424,11 @@ func (op *OptimizationProblem) LinearInequalityConstraintMatrices() (symbolic.KM
452424
}
453425

454426
/*
455-
LinearEqualityConstraintMatrices
456-
Description:
457-
458-
Returns the linear EQUALITY constraint matrices and vectors.
459-
For all linear equality constraints, we assemble them into the form:
460-
Cx = d
461-
Where C is the matrix of coefficients, x is the vector of variables, and d is the vector of constants.
462-
We return C and d.
427+
Returns the linear EQUALITY constraint matrices and vectors.
428+
For all linear equality constraints, we assemble them into the form:
429+
Cx = d
430+
Where C is the matrix of coefficients, x is the vector of variables, and d is the vector of constants.
431+
We return C and d.
463432
*/
464433
func (op *OptimizationProblem) LinearEqualityConstraintMatrices() (symbolic.KMatrix, symbolic.KVector, error) {
465434
// Setup
@@ -567,15 +536,12 @@ func (op *OptimizationProblem) LinearEqualityConstraintMatrices() (symbolic.KMat
567536
}
568537

569538
/*
570-
ToProblemWithAllPositiveVariables
571-
Description:
572-
573-
Transforms the given optimization problem into a new optimization problem
574-
that only contains positive variables.
575-
In math, this means that we will create two new variables (x_+ and x_-) for each
576-
original variable (x), one for the positive part and one for the negative part.
577-
Then, we replace every instance of the original variable with the difference
578-
of the two new variables (x = x_+ - x_-).
539+
Transforms the given optimization problem into a new optimization problem
540+
that only contains positive variables.
541+
In math, this means that we will create two new variables (x_+ and x_-) for each
542+
original variable (x), one for the positive part and one for the negative part.
543+
Then, we replace every instance of the original variable with the difference
544+
of the two new variables (x = x_+ - x_-).
579545
*/
580546
func (op *OptimizationProblem) ToProblemWithAllPositiveVariables() (*OptimizationProblem, map[symbolic.Variable]symbolic.Expression, error) {
581547
// Setup
@@ -644,20 +610,17 @@ func (op *OptimizationProblem) ToProblemWithAllPositiveVariables() (*Optimizatio
644610
}
645611

646612
/*
647-
ToLPStandardForm1
648-
Description:
613+
Transforms the given linear program (represented in an OptimizationProblem object)
614+
into a standard form (i.e., only linear equality constraints and a linear objective function).
649615
650-
Transforms the given linear program (represented in an OptimizationProblem object)
651-
into a standard form (i.e., only linear equality constraints and a linear objective function).
616+
sense c^T * x
617+
subject to
618+
A * x = b
619+
x >= 0
652620
653-
sense c^T * x
654-
subject to
655-
A * x = b
656-
x >= 0
657-
658-
Where A is a matrix of coefficients, b is a vector of constants, and c is the vector of coefficients
659-
for the objective function. This method also returns the slack variables (i.e., the variables that
660-
are added to the problem to convert the inequalities into equalities).
621+
Where A is a matrix of coefficients, b is a vector of constants, and c is the vector of coefficients
622+
for the objective function. This method also returns the slack variables (i.e., the variables that
623+
are added to the problem to convert the inequalities into equalities).
661624
662625
Note:
663626
@@ -782,23 +745,20 @@ func (problemIn *OptimizationProblem) ToLPStandardForm1() (*OptimizationProblem,
782745
}
783746

784747
/*
785-
ToLPStandardForm2
786-
Description:
787-
788-
Transforms the given linear program (represented in an OptimizationProblem object)
789-
into a standard form (i.e., only linear equality constraints and a linear objective function).
790-
791-
max c^T * x
792-
subject to
793-
A * x = b
794-
x >= 0
795-
796-
Where:
797-
- A is a matrix of coefficients,
798-
- b is a vector of constants, and
799-
- c is the vector of coefficients for the objective function.
800-
This method also returns the slack variables (i.e., the variables that
801-
are added to the problem to convert the inequalities into equalities).
748+
Transforms the given linear program (represented in an OptimizationProblem object)
749+
into a standard form (i.e., only linear equality constraints and a linear objective function).
750+
751+
max c^T * x
752+
subject to
753+
A * x = b
754+
x >= 0
755+
756+
Where:
757+
- A is a matrix of coefficients,
758+
- b is a vector of constants, and
759+
- c is the vector of coefficients for the objective function.
760+
This method also returns the slack variables (i.e., the variables that
761+
are added to the problem to convert the inequalities into equalities).
802762
*/
803763
func (problemIn *OptimizationProblem) ToLPStandardForm2() (*OptimizationProblem, []symbolic.Variable, map[symbolic.Variable]symbolic.Expression, error) {
804764
// Input Processing
@@ -830,15 +790,12 @@ func (problemIn *OptimizationProblem) ToLPStandardForm2() (*OptimizationProblem,
830790
}
831791

832792
/*
833-
WithAllPositiveVariableConstraintsRemoved
834-
Description:
835-
836-
Returns a new optimization problem that is the same as the original problem
837-
but with all constraints of the following form removed:
838-
x >= 0
839-
0 <= x
840-
Where x is a variable in the problem.
841-
This is useful for removing redundant constraints that are already implied by the variable bounds.
793+
Returns a new optimization problem that is the same as the original problem
794+
but with all constraints of the following form removed:
795+
x >= 0
796+
0 <= x
797+
Where x is a variable in the problem.
798+
This is useful for removing redundant constraints that are already implied by the variable bounds.
842799
*/
843800
func (op *OptimizationProblem) WithAllPositiveVariableConstraintsRemoved() *OptimizationProblem {
844801
// Setup
@@ -869,11 +826,8 @@ func (op *OptimizationProblem) WithAllPositiveVariableConstraintsRemoved() *Opti
869826
}
870827

871828
/*
872-
CheckIfLinear
873-
Description:
874-
875-
Checks the current optimization problem to see if it is linear.
876-
Returns an error if the problem is not linear.
829+
Checks the current optimization problem to see if it is linear.
830+
Returns an error if the problem is not linear.
877831
*/
878832
func (op *OptimizationProblem) CheckIfLinear() error {
879833
// Input Processing
@@ -912,11 +866,8 @@ func (op *OptimizationProblem) CheckIfLinear() error {
912866
}
913867

914868
/*
915-
CopyVariable
916-
Description:
917-
918-
Creates a deep copy of the given variable within
919-
the optimization problem.
869+
Creates a deep copy of the given variable within
870+
the optimization problem.
920871
*/
921872
func (op *OptimizationProblem) CopyVariable(variable symbolic.Variable) symbolic.Variable {
922873
// Setup
@@ -938,10 +889,7 @@ func (op *OptimizationProblem) CopyVariable(variable symbolic.Variable) symbolic
938889
}
939890

940891
/*
941-
Copy
942-
Description:
943-
944-
Returns a deep copy of the optimization problem.
892+
Returns a deep copy of the optimization problem.
945893
*/
946894
func (op *OptimizationProblem) Copy() *OptimizationProblem {
947895
// Setup
@@ -968,10 +916,7 @@ func (op *OptimizationProblem) Copy() *OptimizationProblem {
968916
}
969917

970918
/*
971-
SimplifyConstraints
972-
Description:
973-
974-
This method simplifies the constraints of the optimization problem by removing redundant constraints.
919+
This method simplifies the constraints of the optimization problem by removing redundant constraints.
975920
*/
976921
func (op *OptimizationProblem) SimplifyConstraints() {
977922
// Setup
@@ -1001,10 +946,7 @@ func (op *OptimizationProblem) MakeNotWellDefinedError() ope.NotWellDefinedError
1001946
}
1002947

1003948
/*
1004-
String
1005-
Description:
1006-
1007-
Creates a string for the problem.
949+
Creates a string for the problem.
1008950
*/
1009951
func (op *OptimizationProblem) String() string {
1010952
// Create string for the objective
@@ -1041,22 +983,16 @@ func (op *OptimizationProblem) String() string {
1041983
}
1042984

1043985
/*
1044-
GetName
1045-
Description:
1046-
1047-
Returns the name of the optimization problem.
1048-
(Necessary for implementing the symbolic.Environment interface).
986+
Returns the name of the optimization problem.
987+
(Necessary for implementing the symbolic.Environment interface).
1049988
*/
1050989
func (op *OptimizationProblem) GetName() string {
1051990
return op.Name
1052991
}
1053992

1054993
/*
1055-
TrackVariable
1056-
Description:
1057-
1058-
Adds the given variable to the optimization problem if it is not already present.
1059-
Returns true if the variable was added, false if it was already present.
994+
Adds the given variable to the optimization problem if it is not already present.
995+
Returns true if the variable was added, false if it was already present.
1060996
*/
1061997
func (op *OptimizationProblem) TrackVariable(v symbolic.Variable) bool {
1062998
// Check if the variable is already present
@@ -1072,11 +1008,8 @@ func (op *OptimizationProblem) TrackVariable(v symbolic.Variable) bool {
10721008
}
10731009

10741010
/*
1075-
AllTrackedVariables
1076-
Description:
1077-
1078-
Returns a slice of all variables that are tracked by the optimization problem.
1079-
(Necessary for implementing the symbolic.Environment interface).
1011+
Returns a slice of all variables that are tracked by the optimization problem.
1012+
(Necessary for implementing the symbolic.Environment interface).
10801013
*/
10811014
func (op *OptimizationProblem) AllTrackedVariables() []symbolic.Variable {
10821015
return op.Variables

0 commit comments

Comments
 (0)