Thank you for answering.
I already know the read_from_file
and I have tried that…
However, I couldn’t make a constraint sparse matrix.
Exactly, I couldn’t find the way to make a list for each constraint as like this, [coefficient, variable].
m = read_from_file("example.mps")
optimizer=optimizer_with_attributes(Cbc.Optimizer, "maxSolutions" => 1, "logLevel "=>1, "seconds" => 300,"allowableGap "=>70)
set_optimizer(m, optimizer)
The type of constraint is followed
julia> list_of_constraint_types(m)
7element Array{Tuple{DataType,DataType},1}:
(GenericAffExpr{Float64,VariableRef}, MathOptInterface.EqualTo{Float64})
(GenericAffExpr{Float64,VariableRef}, MathOptInterface.GreaterThan{Float64})
(GenericAffExpr{Float64,VariableRef}, MathOptInterface.LessThan{Float64})
(VariableRef, MathOptInterface.EqualTo{Float64})
(VariableRef, MathOptInterface.Interval{Float64})
(VariableRef, MathOptInterface.Integer)
(VariableRef, MathOptInterface.ZeroOne)
If I get one of MOI.LessThan{Float64}
constraint,
julia> less_than_constraints = all_constraints(m, GenericAffExpr{Float64,VariableRef}, MOI.LessThan{Float64})
julia>less_than_constraints[1]
HSBAL_CNYIT1701W_DEHAM1701E_004_OUTER : 1.0e6 HSBAL_CNYIT1701W_DEHAM1701E_004_OUTER + BSBAL_CNYIT1701W_DEHAM_004C1 + BSBAL_CNYIT1701W_DEHAM_004S1 + BSBAL_CNYIT1701W_DEHAM_004C2 ≤ 0.0
Here, I couldn’t extract the constraint name, coefficient and variable, sense, rhs.
I want to make a sparse matrix like as
[HSBAL_CNYIT1701W_DEHAM1701E_004_OUTER, HSBAL_CNYIT1701W_DEHAM1701E_004_OUTER] = 1.0e6
[HSBAL_CNYIT1701W_DEHAM1701E_004_OUTER, BSBAL_CNYIT1701W_DEHAM_004C1] = 1.0
[HSBAL_CNYIT1701W_DEHAM1701E_004_OUTER, BSBAL_CNYIT1701W_DEHAM_004S1] = 1.0
[HSBAL_CNYIT1701W_DEHAM1701E_004_OUTER, BSBAL_CNYIT1701W_DEHAM_004C2] = 1.0
I want to handle the ConstraintRef

 Extracting the constraint name

 Extraicting the coefficient and variables
julia> typeof(less_than_constraints[1])
ConstraintRef{Model,MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.LessThan{Float64}},ScalarShape}
julia>less_than_constraints[1]
HSBAL_CNYIT1701W_DEHAM1701E_004_OUTER : 1.0e6 HSBAL_CNYIT1701W_DEHAM1701E_004_OUTER + BSBAL_CNYIT1701W_DEHAM_004C1 + BSBAL_CNYIT1701W_DEHAM_004S1 + BSBAL_CNYIT1701W_DEHAM_004C2 ≤ 0.0
# Extracting the name
julia> name(less_than_constraints[1])
"HSBAL_CNYIT1701W_DEHAM1701E_004_OUTER"
# How can extract the variables and coefficient?
julia> constraint_object(less_than_constraints[1]).func
1.0e6 HSBAL_CNYIT1701W_DEHAM1701E_004_OUTER + BSBAL_CNYIT1701W_DEHAM_004C1 + BSBAL_CNYIT1701W_DEHAM_004S1 + BSBAL_CNYIT1701W_DEHAM_004C2
julia> constraint_object(less_than_constraints[1]).func[1]
ERROR: MethodError: no method matching getindex(::GenericAffExpr{Float64,VariableRef}, ::Int64)
Stacktrace:
[1] toplevel scope at none:0
I think MathProgBase package is the better option for me…
So I want to know the extract the “variable name” from the MathProgBase.