1
1
using Test
2
2
3
3
"""
4
- evalvariables (varval::Function, f::AbstractFunction)
4
+ eval_variables (varval::Function, f::AbstractFunction)
5
5
6
6
Returns the value of function `f` if each variable index `vi` is evaluated as `varval(vi)`.
7
7
"""
8
- function evalvariables end
9
- evalvariables (varval:: Function , f:: SVF ) = varval (f. variable)
10
- evalvariables (varval:: Function , f:: VVF ) = varval .(f. variables)
11
- function evalvariables (varval:: Function , f:: SAF )
8
+ function eval_variables end
9
+ eval_variables (varval:: Function , f:: SVF ) = varval (f. variable)
10
+ eval_variables (varval:: Function , f:: VVF ) = varval .(f. variables)
11
+ function eval_variables (varval:: Function , f:: SAF )
12
12
return mapreduce (t-> evalterm (varval, t), + , f. terms, init= f. constant)
13
13
end
14
- function evalvariables (varval:: Function , f:: VAF )
14
+ function eval_variables (varval:: Function , f:: VAF )
15
15
out = copy (f. constants)
16
16
for t in f. terms
17
17
out[t. output_index] += evalterm (varval, t. scalar_term)
18
18
end
19
19
out
20
20
end
21
- function evalvariables (varval:: Function , f:: SQF )
21
+ function eval_variables (varval:: Function , f:: SQF )
22
22
init = zero (f. constant)
23
23
lin = mapreduce (t-> evalterm (varval, t), + , f. affine_terms, init= init)
24
24
quad = mapreduce (t-> evalterm (varval, t), + , f. quadratic_terms, init= init)
25
25
return lin + quad + f. constant
26
26
end
27
- function evalvariables (varval:: Function , f:: VQF )
27
+ function eval_variables (varval:: Function , f:: VQF )
28
28
out = copy (f. constants)
29
29
for t in f. affine_terms
30
30
out[t. output_index] += evalterm (varval, t. scalar_term)
@@ -204,13 +204,13 @@ function unsafe_add(t1::VT, t2::VT) where VT <: Union{MOI.VectorAffineTerm,
204
204
end
205
205
206
206
"""
207
- iscanonical (f::Union{ScalarAffineFunction, ScalarQuadraticFunction
207
+ is_canonical (f::Union{ScalarAffineFunction, ScalarQuadraticFunction
208
208
VectorAffineFunction, VectorQuadraticTerm})
209
209
210
210
Returns a Bool indicating whether the function is in canonical form.
211
211
See [`canonical`](@ref).
212
212
"""
213
- function iscanonical (f:: Union{SAF, VAF, SQF, VQF} )
213
+ function is_canonical (f:: Union{SAF, VAF, SQF, VQF} )
214
214
is_strictly_sorted (f. terms, MOI. term_indices,
215
215
t -> ! iszero (MOI. coefficient (t)))
216
216
end
@@ -460,44 +460,44 @@ function _rmvar(vis_or_terms::Vector, vi)
460
460
end
461
461
462
462
"""
463
- removevariable (f::AbstractFunction, vi::VariableIndex)
463
+ remove_variable (f::AbstractFunction, vi::VariableIndex)
464
464
465
465
Return a new function `f` with the variable vi removed.
466
466
"""
467
- function removevariable end
468
- function removevariable (f:: MOI.SingleVariable , vi:: MOI.VariableIndex )
467
+ function remove_variable end
468
+ function remove_variable (f:: MOI.SingleVariable , vi:: MOI.VariableIndex )
469
469
if f. variable == vi
470
470
error (" Cannot remove variable from a `SingleVariable` function of the" ,
471
471
" same variable." )
472
472
end
473
473
return f
474
474
end
475
- function removevariable (f:: VVF , vi)
475
+ function remove_variable (f:: VVF , vi)
476
476
VVF (_rmvar (f. variables, vi))
477
477
end
478
- function removevariable (f:: Union{SAF, VAF} , vi)
478
+ function remove_variable (f:: Union{SAF, VAF} , vi)
479
479
typeof (f)(_rmvar (f. terms, vi), MOI. constant (f))
480
480
end
481
- function removevariable (f:: Union{SQF, VQF} , vi)
481
+ function remove_variable (f:: Union{SQF, VQF} , vi)
482
482
terms = _rmvar .((f. affine_terms, f. quadratic_terms), Ref (vi))
483
483
typeof (f)(terms... , MOI. constant (f))
484
484
end
485
485
486
486
"""
487
- modifyfunction (f::AbstractFunction, change::AbstractFunctionModification)
487
+ modify_function (f::AbstractFunction, change::AbstractFunctionModification)
488
488
489
489
Return a new function `f` modified according to `change`.
490
490
"""
491
- function modifyfunction (f:: SAF , change:: MOI.ScalarConstantChange )
491
+ function modify_function (f:: SAF , change:: MOI.ScalarConstantChange )
492
492
return SAF (f. terms, change. new_constant)
493
493
end
494
- function modifyfunction (f:: VAF , change:: MOI.VectorConstantChange )
494
+ function modify_function (f:: VAF , change:: MOI.VectorConstantChange )
495
495
return VAF (f. terms, change. new_constant)
496
496
end
497
- function modifyfunction (f:: SQF , change:: MOI.ScalarConstantChange )
497
+ function modify_function (f:: SQF , change:: MOI.ScalarConstantChange )
498
498
return SQF (f. affine_terms, f. quadratic_terms, change. new_constant)
499
499
end
500
- function modifyfunction (f:: VQF , change:: MOI.VectorConstantChange )
500
+ function modify_function (f:: VQF , change:: MOI.VectorConstantChange )
501
501
return VQF (f. affine_terms, f. quadratic_terms, change. new_constant)
502
502
end
503
503
function _modifycoefficient (terms:: Vector{<:MOI.ScalarAffineTerm} , variable:: VI , new_coefficient)
@@ -518,11 +518,11 @@ function _modifycoefficient(terms::Vector{<:MOI.ScalarAffineTerm}, variable::VI,
518
518
end
519
519
terms
520
520
end
521
- function modifyfunction (f:: SAF , change:: MOI.ScalarCoefficientChange )
521
+ function modify_function (f:: SAF , change:: MOI.ScalarCoefficientChange )
522
522
lin = _modifycoefficient (f. terms, change. variable, change. new_coefficient)
523
523
return SAF (lin, f. constant)
524
524
end
525
- function modifyfunction (f:: SQF , change:: MOI.ScalarCoefficientChange )
525
+ function modify_function (f:: SQF , change:: MOI.ScalarCoefficientChange )
526
526
lin = _modifycoefficient (f. affine_terms, change. variable, change. new_coefficient)
527
527
return SQF (lin, f. quadratic_terms, f. constant)
528
528
end
@@ -553,13 +553,13 @@ function _modifycoefficients(n, terms::Vector{<:MOI.VectorAffineTerm}, variable:
553
553
end
554
554
terms
555
555
end
556
- function modifyfunction (f:: VAF , change:: MOI.MultirowChange )
556
+ function modify_function (f:: VAF , change:: MOI.MultirowChange )
557
557
dim = MOI. output_dimension (f)
558
558
coefficients = change. new_coefficients
559
559
lin = _modifycoefficients (dim, f. terms, change. variable, coefficients)
560
560
VAF (lin, f. constants)
561
561
end
562
- function modifyfunction (f:: VQF , change:: MOI.MultirowChange )
562
+ function modify_function (f:: VQF , change:: MOI.MultirowChange )
563
563
dim = MOI. output_dimension (f)
564
564
coefficients = change. new_coefficients
565
565
lin = _modifycoefficients (dim, f. affine_terms, change. variable, coefficients)
0 commit comments