File Formats

FormatReadWriteModelSolutionsStartMetadata
BQPJSON
QUBin
Qubist
QUBO

Defining a Custom File Format

using QUBOTools

struct SuperFormat <: QUBOTools.AbstractFormat
    super::Bool

    SuperFormat(super::Bool = true) = new(super)
end

Writing Models

To write a model using SuperFormat, one must implement the

QUBOTools.write_model(io::IO, ::QUBOTools.AbstractModel{V,T,U}, ::SuperFormat) where {V,T,U}

method for the custom format.

Info

This assumption is valid for text-based and binary formats. If you pretend to write in a format that does not rely on io::IO (such as QUBOTools.QUBin), you should also implement

QUBOTools.write_model(filepath::AbstractString, ::QUBOTools.AbstractModel{V,T,U}, ::SuperFormat) where {V,T,U}
function QUBOTools.write_model(io::IO, model::QUBOTools.AbstractModel, fmt::SuperFormat)
    if fmt.super
        println(io, "Format Type: SUPER")

        _write_super_model(io, model)
    else
        println(io, "Format Type: Regular")

        _write_regular_model(io, model)
    end

    return nothing
end

Reading Models

function QUBOTools.read_model(io::IO, fmt::SuperFormat)
    header = readline(io)

    if fmt.super
        @assert("SUPER" in header, "Invalid header: '$header' is not SUPER!")

        return _read_super_model(io)
    else
        return _read_regular_model(io)
    end
end
Info

QUBOTools.read_model should return a QUBOTools.Model instance.