API Reference

Main Entry Point

ModelCompare.compare_modelsFunction
compare_models(file1, file2; tol, outfile, verbose=true, one_by_one=true, separate_files=false)

Compare two optimization model files (LP or MPS format) and write a detailed diff report to outfile. Returns a NamedTuple with fields variables, bounds, objective, and constraints.

Arguments

  • file1::String: path to the first model file.
  • file2::String: path to the second model file.
  • tol::Float64: absolute tolerance for numerical comparisons.
  • outfile::String: path to the output report file.
  • separate_files::Bool: if true, write each section to a separate file.
source

Variables

ModelCompare.VariablesDiffType
VariablesDiff

Result of comparing variable names between two models.

Fields

  • in_both::Vector{String}: variable names present in both models.
  • only_one::Vector{String}: variable names unique to the first model.
  • only_two::Vector{String}: variable names unique to the second model.
source

Bounds

ModelCompare.compare_boundsFunction
compare_bounds(model1, model2, vardiff; tol) -> BoundsDiff
compare_bounds(model1, model2; tol) -> BoundsDiff

Compare variable bounds between two MOI models. The 2-argument form computes the VariablesDiff automatically. Returns a BoundsDiff.

source

Objective

ModelCompare.ObjectiveDiffType
ObjectiveDiff

Result of comparing objective functions between two models.

Fields

  • sense::Tuple{MOI.OptimizationSense, MOI.OptimizationSense}: optimization senses (min/max) of each model.
  • expression::ExpressionDiff: coefficient differences in the objective expression.
source

Expressions

ModelCompare.ExpressionDiffType
ExpressionDiff

Result of comparing two linear expressions (objective or constraint).

Fields

  • equal::Vector{String}: variable names with matching coefficients (within tolerance).
  • both::Dict{String, Tuple{Float64, Float64}}: variables present in both expressions with differing coefficients (coef1, coef2).
  • first::Dict{String, Float64}: variables only in the first expression.
  • second::Dict{String, Float64}: variables only in the second expression.
source
ModelCompare.compare_expressionsFunction
compare_expressions(expr1, expr2, model1, model2; tol) -> ExpressionDiff

Compare two MOI.AbstractScalarFunction expressions, returning an ExpressionDiff that partitions variables into equal, differing, and unique-to-each-model categories.

source

Constraints

ModelCompare.ConstraintNamesDiffType
ConstraintNamesDiff

Result of comparing constraint names between two models.

Fields

  • in_both::Vector{String}: constraint names present in both models.
  • only_one::Vector{String}: constraint names unique to the first model.
  • only_two::Vector{String}: constraint names unique to the second model.
source
ModelCompare.ConstraintElementsDiffType
ConstraintElementsDiff

Result of comparing constraint coefficients and bounds between two models.

Fields

  • equal::Vector{String}: constraints that are identical (within tolerance).
  • both::Dict: constraints present in both models with differences — maps name to (ExpressionDiff, (set1, set2)).
  • first::Dict: constraints unique to the first model — maps name to (coefficients, bounds).
  • second::Dict: constraints unique to the second model — maps name to (coefficients, bounds).
source
ModelCompare.compare_constraintsFunction
compare_constraints(model1, model2; tol) -> ConstraintElementsDiff

Compare the constraints of two MOI models. Only constraints with matching names are compared; unmatched constraint names are reported separately.

source

Utilities

ModelCompare.readmodelFunction
readmodel(fname::String)

Read an optimization model from an LP or MPS file and return an MOI.ModelLike object.

source
ModelCompare.partitionFunction
partition(A, B)

Partition two collections into disjoint collections containing their intersection and the elements unique to each of them:

partition(A, B) = (A ∩ B, A \ B, B \ A)
source
ModelCompare.sort_modelFunction
sort_model(file1::String)

Canonicalize a model file by sorting its variables and constraints alphabetically. Writes the sorted model to file1 * ".sorted" in LP format.

source