Skip to content

[feature] LP round-trip tests #67

Open

Description

@GermanHeim

Is your feature request related to a problem? Please describe.
Currently, the LP writer/reader doesn't have any round-trip tests.

Describe the solution you'd like
Build models covering senses/bounds/domains/objective names, write to LP string, read back, assert equivalence.
Improves confidence in the reader without needing solvers.

Additional context
This issue is tagged good first issue specifically to help new contributors get hands-on with the codebase and wants to contribute in the long term. Please do not use AI for this issue.

Activity

  1. added
    enhancement
    good first issue
    on Aug 23, 2026
  2. NikitaPomies commented on Aug 30, 2026

    @NikitaPomies
    Contributor

    Hello again,

    I have been working on this issue and find some other pbs along the way with oximo-io write_lp

    You can fix an Integer variable to a non integer value. It does not raise any error + write the infeasible lp

    fn integer_var_fixing_to_non_int_bug() {
        let m = Model::new("lp_model");
        variable!(m, z, Integer);
        m.fix(z, 0.3); // We should raise an error
        objective!(m, Min, 2 * z);
        let dir = PathBuf::from(env!("CARGO_TARGET_TMPDIR"));
        write_lp(&m, &mut File::create(dir.join("integer_var_fixing.lp")).expect("create LP file"))
            .expect("dump LP");
    }
    

    You cannot fix a a Binary variable at all. See line 1040 of oximo-io/src/lp.rs

    #[test]
    fn binary_var_fixing_to_non_int_bug() {
        let m = Model::new("lp_model");
        variable!(m, z, Binary);
        m.fix(z, 1); // Currently not written due to a loo
        objective!(m, Min, 2 * z);
        let dir = PathBuf::from(env!("CARGO_TARGET_TMPDIR"));
        write_lp(&m, &mut File::create(dir.join("binary_var_fixing.lp")).expect("create LP file"))
            .expect("dump LP");
    }
    

    will write :

    \* OXIMO LP export - model: lp_model *\
    Minimize
     obj: 2 z
    Subject To
    Binaries
     z
    End
    

    You cannot properly fix a semi-integer variable

    #[test]
    fn semi_continous_var_fixing_to_non_int_bug() {
        let m = Model::new("lp_model");
        variable!(m, z, SemiContinuous(1));
        m.fix(z, 2.0); // We should raise an error
        objective!(m, Min, 2 * z);
        let dir = PathBuf::from(env!("CARGO_TARGET_TMPDIR"));
        write_lp(&m, &mut File::create(dir.join("semi_cont_fixing.lp")).expect("create LP file"))
            .expect("dump LP");
    }
    
    \* OXIMO LP export - model: lp_model *\
    Minimize
     obj: 2 z
    Subject To
    Bounds
     1 <= z <= 2
    Semi-Continuous
     z
    End
    

    Want me to fix that in the same PR ?

  3. GermanHeim commented on Aug 30, 2026

    @GermanHeim
    MemberAuthor

    Hi @NikitaPomies, yes, that would be great, thank you!
    Also, it would be nice if you could fix your Git commit config so that you are credited as a contributor.

  4. NikitaPomies commented on Aug 31, 2026

    @NikitaPomies
    Contributor

    Hello, my git config should be fixed now.

    I made a first PR in #80 to prevent the user fixing variable to non coherent values.

    More incoming

  5. NikitaPomies commented on Sep 7, 2026

    @NikitaPomies
    Contributor

    Hello @GermanHeim,
    Here is another MR fixing a bug I found while working on this issue #92.

    Another MR incoming to allow writing a .lp for a model where the user used objective!(model, Feasibility) (currently fails)

    and then the rest of the round trip tests.

  6. NikitaPomies commented on Sep 20, 2026

    @NikitaPomies
    Contributor

    Hello @GermanHeim

    What behavior do you want for such a case where several bounds are declared for the same variable ? Same question for
    smt like (free declaration + bound or bound than free declaration)

    fn a_later_bound_declaration_overrides_an_earlier_one() {
        let model = read_lp("Minimize\n obj: x\nBounds\n x >= 2\n x >= 1\nEnd\n".as_bytes())
            .expect("repeated bounds");
        assert!(close(model.variables()[0].lb, 2.0)); -> currently  lb would be 1 
    
    • Xpress would say : '?Warning: Repeated bound at (6.1):. Previous bound ignored.' and keeps the last bound

    • Highs would silently takes the last one too.

    I think we should left it as is and issue a warning.

  7. GermanHeim commented on Sep 20, 2026

    @GermanHeim
    MemberAuthor

    Hi @NikitaPomies,

    My preference for oximo would be strict by default, with these rules:

    • Complementary lower and upper bounds are accepted.
    • Repeating either side is an LP import error, even if the numerical value is identical.
    • Equality declares both sides and therefore conflicts with any explicit prior bound.
    • Free only removes the implicit default lower bound; it does not erase explicit bounds.
    • Inconsistent final bounds are rejected by the reader and not deferred to solvers.

    I think we should error instead of applying last-wins. What do you think?

  8. NikitaPomies commented on Sep 21, 2026

    @NikitaPomies
    Contributor

    Yes I agree it is more rust oriented and would make oximo stands out from other modelers on that matter.

  9. NikitaPomies commented on Oct 25, 2026

    @NikitaPomies
    Contributor

    Hello @GermanHeim,

    another issue I found after resuming working on oximo (after a harsh month at work aha 🥲 ).

    On a model with indexed variables, the .lp writer produce a .lp file that the reader rejects.

    For instance, the following snippet :

    use oximo_core::prelude::*;
    use oximo_io::{read_lp, to_lp_string};
    
    let model = Model::new("indexed");
    variable!(model, 0.0 <= x[i in 0..2] <= 3.0);
    constraint!(model, cap[i in 0..2], x[i] <= 2.0);
    objective!(model, Min, x[0] + x[1]);
    
    let text = to_lp_string(&model).unwrap();
    read_lp(text.as_bytes()).unwrap(); // fails
    

    would produce :

    \* OXIMO LP export - model: indexed *\
    Minimize
     obj: x[0] + x[1]
    Subject To
     cap[0]: x[0] <= 2
     cap[1]: x[1] <= 2
    Bounds
     0 <= x[0] <= 3
     0 <= x[1] <= 3
    End
    

    The reader forbid such variable names as brackets are used to delimit quadratic terms.

    What do you think about writing indexed variables using "_" : "x[i, j]" would become "x_i_j" ?

  10. GermanHeim commented on Oct 25, 2026

    @GermanHeim
    MemberAuthor

    Hi @NikitaPomies,

    Thanks for looking into this! I hadn’t realized that IBM’s naming conventions don’t allow square brackets in variable names (though it makes sense).

    I think it makes sense to rename variables only during LP export, preserving model names internally. We should reserve existing valid names first (e.g.: If x_0 already exists, the exported x[0] gets a unique suffix). We should also build a single name map keyed by variable ID and use it everywhere (objective, constraints, bounds, domains, etc.). Other invalid characters and/or reserved kwds can be handled through the same mechanism. I remember adding something similar for MPS.

    Replacing brackets with "_" would be fine, but I believe using braces is better to preserve the indexed appearance:
    x[0] -> x{0}
    x[0,1] -> x{0,1}
    cap[0] -> cap{0}

    I checked and CPLEX allows braces and commas in names.
    Another option is x#0#1, which follows CPLEX's documented convention for exporting multidimensional OPL arrays, but I think it’s less readable. What do you think?

  11. NikitaPomies commented on Oct 26, 2026

    @NikitaPomies
    Contributor

    I like the braces notation. Mosek (and Knitro, dont know if you plan to integrate it) do not support them though. Not a blocking point for you ?

  12. GermanHeim commented on Oct 26, 2026

    @GermanHeim
    MemberAuthor

    MOSEK seems to support it (MOSEK accepts any character as valid for names, except \0, although they specially mention !"#$%&()/,.;?@_'`|~, so I am not sure); KNITRO does not support them. It also doesn't support commas.

    I plan to add support for KNITRO in the future, but I don't have a license and knitro-rs is currently unmaintained, so we would have to fork it and update it, if needed.

    Given this, I think _ or # would be more appropriate. Which one do you prefer?

  13. NikitaPomies commented on Oct 26, 2026

    @NikitaPomies
    Contributor

    yes you are right. I tested and mosek indeed support the braces. Make sense avoiding braces if you plan to integrate knitro. Have you asked for a license btw ?

    I would rather use "_" for the index delimiters than #

  14. GermanHeim commented on Oct 26, 2026

    @GermanHeim
    MemberAuthor

    Lets go with _, then.

    I got a temporary KNITRO license a while back, but when I started the gurobi-rs fork and sending PRs to the other bindings (IPOPT, SCIP, CPLEX), forking and updating knitro-rs was outside my scope.

    Edit: What about x(i_j)? They all support parentheses

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementgood first issue

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions