-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathLP.jl
More file actions
129 lines (108 loc) · 3.33 KB
/
LP.jl
File metadata and controls
129 lines (108 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# Copyright (c) 2017: Miles Lubin and contributors
# Copyright (c) 2017: Google Inc.
#
# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
module LP
import ..FileFormats
import MathOptInterface as MOI
const _ILT1{T} = MOI.Indicator{MOI.ACTIVATE_ON_ONE,MOI.LessThan{T}}
const _IGT1{T} = MOI.Indicator{MOI.ACTIVATE_ON_ONE,MOI.GreaterThan{T}}
const _IET1{T} = MOI.Indicator{MOI.ACTIVATE_ON_ONE,MOI.EqualTo{T}}
const _ILT0{T} = MOI.Indicator{MOI.ACTIVATE_ON_ZERO,MOI.LessThan{T}}
const _IGT0{T} = MOI.Indicator{MOI.ACTIVATE_ON_ZERO,MOI.GreaterThan{T}}
const _IET0{T} = MOI.Indicator{MOI.ACTIVATE_ON_ZERO,MOI.EqualTo{T}}
MOI.Utilities.@model(
Model,
(MOI.ZeroOne, MOI.Integer),
(MOI.EqualTo, MOI.GreaterThan, MOI.LessThan, MOI.Interval),
(),
(MOI.SOS1, MOI.SOS2, _ILT1, _IET1, _IGT1, _ILT0, _IGT0, _IET0),
(),
(MOI.ScalarQuadraticFunction, MOI.ScalarAffineFunction),
(MOI.VectorOfVariables,),
(MOI.VectorAffineFunction,)
)
function MOI.supports_constraint(
::Model,
::Type{MOI.VariableIndex},
::Type{<:Union{MOI.Parameter,MOI.Semicontinuous,MOI.Semiinteger}},
)
return false
end
function MOI.supports_constraint(
::Model{T},
::Type{MOI.VectorAffineFunction{T}},
::Type{MOI.SOS1{T}},
) where {T}
return false
end
function MOI.supports_constraint(
::Model{T},
::Type{MOI.VectorAffineFunction{T}},
::Type{MOI.SOS2{T}},
) where {T}
return false
end
MOI.supports(::Model, ::MOI.ObjectiveFunction) = false
function MOI.supports(
::Model{T},
::MOI.ObjectiveFunction{
<:Union{
MOI.VariableIndex,
MOI.ScalarAffineFunction{T},
MOI.ScalarQuadraticFunction{T},
},
},
) where {T}
return true
end
struct Options
maximum_length::Int
warn::Bool
generic_names::Bool
end
function get_options(m::Model)
default_options = Options(255, false, false)
return get(m.ext, :LP_OPTIONS, default_options)
end
"""
Model(;
maximum_length::Int = 255,
warn::Bool = false,
coefficient_type::Type{T} = Float64,
generic_names::Bool = false,
) where {T}
Create an empty instance of FileFormats.LP.Model.
Keyword arguments are:
- `maximum_length::Int=255`: the maximum length for the name of a variable.
lp_solve 5.0 allows only 16 characters, while CPLEX 12.5+ allow 255.
- `warn::Bool=false`: print a warning when variables or constraints are renamed.
- `coefficient_type::Type{T} = Float64`: the supported type to use when reading
and writing files.
- `generic_names::Bool=false`: strip all names in the model and replace them
with the generic names `C\$i` and `R\$i` for the i'th column and row
respectively.
"""
function Model(;
maximum_length::Int = 255,
warn::Bool = false,
coefficient_type::Type{T} = Float64,
generic_names::Bool = false,
kwargs...,
) where {T}
if !isempty(kwargs)
error(
"The LP file format does not support the keyword arguments: ",
kwargs...,
)
end
model = Model{T}()
options = Options(maximum_length, warn, generic_names)
model.ext[:LP_OPTIONS] = options
return model
end
Base.summary(io::IO, ::Model) = print(io, "MOI.FileFormats.LP.Model")
include("read.jl")
include("write.jl")
end # module LP