11# Functions
22
33"""
4- AbstractFunction{V}
4+ AbstractFunction
55
6- Abstract supertype for function objects. The parameter `V` indicates the variable type, usually `VariableReference`.
6+ Abstract supertype for function objects.
77"""
8- abstract type AbstractFunction{V} end
8+ abstract type AbstractFunction end
99
1010"""
11- AbstractScalarFunction{V}
12-
13- Abstract supertype for scalar-valued function objects. The parameter `V` indicates the variable type, usually `VariableReference`.
11+ AbstractScalarFunction
1412
13+ Abstract supertype for scalar-valued function objects.
1514"""
16- abstract type AbstractScalarFunction{V} <: AbstractFunction{V} end
15+ abstract type AbstractScalarFunction <: AbstractFunction end
1716
1817"""
19- AbstractVectorFunction{V}
20-
21- Abstract supertype for vector-valued function objects. The parameter `V` indicates the variable type, usually `VariableReference`.
18+ AbstractVectorFunction
2219
20+ Abstract supertype for vector-valued function objects.
2321"""
24- abstract type AbstractVectorFunction{V} <: AbstractFunction{V} end
25-
26- # These generic functions are not used directly in MOI, but are useful in related interfaces where other objects stand in for VariableReference.
27-
28- struct GenericSingleVariable{V} <: AbstractScalarFunction{V}
29- variable:: V
30- end
31-
32- struct GenericVectorOfVariables{V} <: AbstractVectorFunction{V}
33- variables:: Vector{V}
34- end
35-
36- struct GenericScalarAffineFunction{V,T} <: AbstractScalarFunction{V}
37- variables:: Vector{V}
38- coefficients:: Vector{T}
39- constant:: T
40- end
22+ abstract type AbstractVectorFunction <: AbstractFunction end
4123
42- struct GenericVectorAffineFunction{V,T} <: AbstractVectorFunction{V}
43- outputindex:: Vector{Int}
44- variables:: Vector{V}
45- coefficients:: Vector{T}
46- constant:: Vector{T}
47- end
48-
49- struct GenericScalarQuadraticFunction{V,T} <: AbstractScalarFunction{V}
50- affine_variables:: Vector{V}
51- affine_coefficients:: Vector{T}
52- quadratic_rowvariables:: Vector{V}
53- quadratic_colvariables:: Vector{V}
54- quadratic_coefficients:: Vector{T}
55- constant:: T
56- end
57-
58- struct GenericVectorQuadraticFunction{V,T} <: AbstractVectorFunction{V}
59- affine_outputindex:: Vector{Int}
60- affine_variables:: Vector{V}
61- affine_coefficients:: Vector{T}
62- quadratic_outputindex:: Vector{Int}
63- quadratic_rowvariables:: Vector{V}
64- quadratic_colvariables:: Vector{V}
65- quadratic_coefficients:: Vector{T}
66- constant:: Vector{T}
67- end
6824
6925"""
7026 SingleVariable(variable)
7127
7228The function that extracts the scalar variable referenced by `variable`, a `VariableReference`.
7329This function is naturally be used for single variable bounds or integrality constraints.
7430"""
75- const SingleVariable = GenericSingleVariable{VariableReference}
31+ struct SingleVariable <: AbstractScalarFunction
32+ variable:: VariableReference
33+ end
7634
7735"""
7836 VectorOfVariables(variables)
7937
8038The function that extracts the vector of variables referenced by `variables`, a `Vector{VariableReference}`.
8139This function is naturally be used for constraints that apply to groups of variables, such as an "all different" constraint, an indicator constraint, or a complementarity constraint.
8240"""
83- const VectorOfVariables = GenericVectorOfVariables{VariableReference}
41+ struct VectorOfVariables <: AbstractVectorFunction
42+ variables:: Vector{VariableReference}
43+ end
8444
8545"""
8646 ScalarAffineFunction{T}(variables, coefficients, constant)
@@ -91,7 +51,11 @@ The scalar-valued affine function ``a^T x + b``, where:
9151
9252Duplicate variable references in `variables` are accepted, and the corresponding coefficients are summed together.
9353"""
94- const ScalarAffineFunction = GenericScalarAffineFunction{VariableReference}
54+ struct ScalarAffineFunction{T} <: AbstractScalarFunction
55+ variables:: Vector{VariableReference}
56+ coefficients:: Vector{T}
57+ constant:: T
58+ end
9559
9660"""
9761 VectorAffineFunction{T}(outputindex, variables, coefficients, constant)
@@ -102,7 +66,12 @@ The vector-valued affine function ``A x + b``, where:
10266
10367Duplicate indices in the ``A`` are accepted, and the corresponding coefficients are summed together.
10468"""
105- const VectorAffineFunction = GenericVectorAffineFunction{VariableReference}
69+ struct VectorAffineFunction{T} <: AbstractVectorFunction
70+ outputindex:: Vector{Int}
71+ variables:: Vector{VariableReference}
72+ coefficients:: Vector{T}
73+ constant:: Vector{T}
74+ end
10675
10776"""
10877 ScalarQuadraticFunction{T}(affine_variables, affine_coefficients, quadratic_rowvariables, quadratic_colvariables, quadratic_coefficients, constant)
@@ -115,7 +84,14 @@ The scalar-valued quadratic function ``\\frac{1}{2}x^TQx + a^T x + b``, where:
11584Duplicate indices in ``a`` or ``Q`` are accepted, and the corresponding coefficients are summed together.
11685"Mirrored" indices `(q,r)` and `(r,q)` (where `r` and `q` are `VariableReferences`) are considered duplicates; only one need be specified.
11786"""
118- const ScalarQuadraticFunction = GenericScalarQuadraticFunction{VariableReference}
87+ struct ScalarQuadraticFunction{T} <: AbstractScalarFunction
88+ affine_variables:: Vector{VariableReference}
89+ affine_coefficients:: Vector{T}
90+ quadratic_rowvariables:: Vector{VariableReference}
91+ quadratic_colvariables:: Vector{VariableReference}
92+ quadratic_coefficients:: Vector{T}
93+ constant:: T
94+ end
11995
12096
12197"""
@@ -129,53 +105,46 @@ The vector-valued quadratic function with i`th` component ("output index") defin
129105Duplicate indices in ``a_i`` or ``Q_i`` are accepted, and the corresponding coefficients are summed together.
130106"Mirrored" indices `(q,r)` and `(r,q)` (where `r` and `q` are `VariableReferences`) are considered duplicates; only one need be specified.
131107"""
132- const VectorQuadraticFunction = GenericVectorQuadraticFunction{VariableReference}
133-
108+ struct VectorQuadraticFunction{T} <: AbstractVectorFunction
109+ affine_outputindex:: Vector{Int}
110+ affine_variables:: Vector{VariableReference}
111+ affine_coefficients:: Vector{T}
112+ quadratic_outputindex:: Vector{Int}
113+ quadratic_rowvariables:: Vector{VariableReference}
114+ quadratic_colvariables:: Vector{VariableReference}
115+ quadratic_coefficients:: Vector{T}
116+ constant:: Vector{T}
117+ end
134118
135119# Function modifications
136120
137121
138122"""
139123 AbstractFunctionModification
140124
141- An abstract supertype for structs which specify partial modifications to functions, to be used for making small modifications instead of replacing the functions entirely. The parameter `V` indicates the variable type, usually `VariableReference`.
125+ An abstract supertype for structs which specify partial modifications to functions, to be used for making small modifications instead of replacing the functions entirely.
142126"""
143- abstract type AbstractFunctionModification{V} end
144-
145- struct GenericScalarConstantChange{V,T} <: AbstractFunctionModification{V}
146- new_constant:: T
147- end
148-
149- struct GenericVectorConstantChange{V,T} <: AbstractFunctionModification{V}
150- new_constant:: Vector{T}
151- end
152-
153- struct GenericScalarCoefficientChange{V,T} <: AbstractFunctionModification{V}
154- variable:: V
155- new_coefficient:: T
156- end
157-
158- struct GenericMultirowChange{V,T} <: AbstractFunctionModification{V}
159- variable:: V
160- rows:: Vector{Int}
161- new_coefficients:: Vector{T}
162- end
127+ abstract type AbstractFunctionModification end
163128
164129"""
165130 ScalarConstantChange{T}(new_constant)
166131
167132A struct used to request a change in the constant term of a scalar-valued function.
168133Applicable to `ScalarAffineFunction` and `ScalarQuadraticFunction`.
169134"""
170- const ScalarConstantChange = GenericScalarConstantChange{VariableReference}
135+ struct ScalarConstantChange{T} <: AbstractFunctionModification
136+ new_constant:: T
137+ end
171138
172139"""
173140 VectorConstantChange{T}(new_constant)
174141
175142A struct used to request a change in the constant vector of a vector-valued function.
176143Applicable to `VectorAffineFunction` and `VectorQuadraticFunction`.
177144"""
178- const VectorConstantChange = GenericVectorConstantChange{VariableReference}
145+ struct VectorConstantChange{T} <: AbstractFunctionModification
146+ new_constant:: Vector{T}
147+ end
179148
180149"""
181150 ScalarCoefficientChange{T}(variable, new_coefficient)
@@ -184,7 +153,10 @@ A struct used to request a change in the linear coefficient of a single variable
184153in a scalar-valued function.
185154Applicable to `ScalarAffineFunction` and `ScalarQuadraticFunction`.
186155"""
187- const ScalarCoefficientChange = GenericScalarCoefficientChange{VariableReference}
156+ struct ScalarCoefficientChange{T} <: AbstractFunctionModification
157+ variable:: VariableReference
158+ new_coefficient:: T
159+ end
188160
189161"""
190162 MultirowChange{T}(variable, rows, new_coefficients)
@@ -193,4 +165,8 @@ A struct used to request a change in the linear coefficients of a single variabl
193165in a vector-valued function.
194166Applicable to `VectorAffineFunction` and `VectorQuadraticFunction`.
195167"""
196- const MultirowChange = GenericMultirowChange{VariableReference}
168+ struct MultirowChange{T} <: AbstractFunctionModification
169+ variable:: VariableReference
170+ rows:: Vector{Int}
171+ new_coefficients:: Vector{T}
172+ end
0 commit comments