Basic Usage
using QUBOTools
By loading the package with the using
statement, only a few constants will be dumped in the namespace, most of them model types.
File I/O
To read and write models one should use the QUBOTools.read_model
/QUBOTools.write_model
API.
# File Path
path = joinpath(@__DIR__, "data", "problem.json")
model = QUBOTools.read_model(path)
QUBOTools Model
▷ Sense ………………… Min
▷ Domain ……………… BoolDomain
▷ Variables ……… 3
Density:
▷ Linear ……………… 66.67%
▷ Quadratic ……… 66.67%
▷ Total ………………… 66.67%
There are no warm-start values.
There are no solutions available.
The QUBOTools.read_model
and QUBOTools.write_model
methods will try to infer the file format from the file extension. The format can be manually set by passing an extra optional parameter after the source path. For more information, see File Formats.
Data Access
QUBOTools.description(model)
"Simple QUBO Problem"
QUBOTools.linear_terms(model) |> collect
2-element Vector{Pair{Int64, Float64}}:
2 => 0.4
3 => -4.4
QUBOTools.quadratic_terms(model) |> collect
2-element Vector{Pair{Tuple{Int64, Int64}, Float64}}:
(1, 2) => -0.8
(1, 3) => 6.0
Model Analysis
QUBOTools.density(model)
0.6666666666666666
File formats
Conversion between formats
One of the main functionalities of this package is to allow fast conversion from a QUBO file format to another. Achieving this is as simple as writing the loaded model but providing a different specification:
QUBOTools.write_model(stdout, model, QUBOTools.Qubist())
3 4
2 2 0.4
3 3 -4.4
1 2 -0.8
1 3 6.0