API Reference
Main Entry Point
ModelCompare.compare_models — Function
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: iftrue, write each section to a separate file.
Variables
ModelCompare.VariablesDiff — Type
VariablesDiffResult 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.
ModelCompare.compare_variables — Function
compare_variables(model1, model2) -> VariablesDiffCompare the variable names of two MOI models and return a VariablesDiff.
Bounds
ModelCompare.BoundsDiff — Type
struct BoundsDiffCarry the information needed to compare the variable bounds between two models.
ModelCompare.compare_bounds — Function
compare_bounds(model1, model2, vardiff; tol) -> BoundsDiff
compare_bounds(model1, model2; tol) -> BoundsDiffCompare variable bounds between two MOI models. The 2-argument form computes the VariablesDiff automatically. Returns a BoundsDiff.
Objective
ModelCompare.ObjectiveDiff — Type
ObjectiveDiffResult 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.
ModelCompare.compare_objective — Function
compare_objective(model1, model2; tol) -> ObjectiveDiffCompare the objective functions (sense and coefficients) of two MOI models.
Expressions
ModelCompare.ExpressionDiff — Type
ExpressionDiffResult 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.
ModelCompare.compare_expressions — Function
compare_expressions(expr1, expr2, model1, model2; tol) -> ExpressionDiffCompare two MOI.AbstractScalarFunction expressions, returning an ExpressionDiff that partitions variables into equal, differing, and unique-to-each-model categories.
Constraints
ModelCompare.ConstraintNamesDiff — Type
ConstraintNamesDiffResult 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.
ModelCompare.ConstraintElementsDiff — Type
ConstraintElementsDiffResult 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).
ModelCompare.compare_constraints — Function
compare_constraints(model1, model2; tol) -> ConstraintElementsDiffCompare the constraints of two MOI models. Only constraints with matching names are compared; unmatched constraint names are reported separately.
Utilities
ModelCompare.readmodel — Function
readmodel(fname::String)Read an optimization model from an LP or MPS file and return an MOI.ModelLike object.
ModelCompare.partition — Function
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)ModelCompare.sort_model — Function
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.