Skip to content

Commit

Permalink
fix: Blank lines aren't ignored (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
dandxy89 authored Jan 3, 2024
1 parent cd266cd commit 5a58e64
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
10 changes: 10 additions & 0 deletions resources/blank_lines.lp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
\ LP format example

Minimize
obj: x + 10 y
Subject To
r01: x + y >= 1

Binaries
x y z
End
10 changes: 5 additions & 5 deletions src/lp_file_format.pest
Original file line number Diff line number Diff line change
Expand Up @@ -114,32 +114,32 @@ BOUNDS = { NEWLINE* ~ BOUND_SECTION ~ (BOUND+)? }
// A list of variable names of integer variables. Unless otherwise specified in the
// bounds section, the default relaxation interval of the variables is [0, 1].
INTEGER_SECTION = _{ ^"Integers" }
INTEGERS = { NEWLINE ~ INTEGER_SECTION ~ (NEWLINE? ~ VARIABLE)* }
INTEGERS = { NEWLINE* ~ INTEGER_SECTION ~ (NEWLINE? ~ VARIABLE)* }

// Generals
// A list of variable names of integer variables. Unless otherwise specified in the
// bounds section, the default relaxation interval of the variables is [0, +Infinity].
GENERALS_SECTION = _{ ^"Gen" ~ ^"eral"? ~ ^"s"? }
GENERALS = { NEWLINE ~ GENERALS_SECTION ~ (NEWLINE? ~ VARIABLE)* }
GENERALS = { NEWLINE* ~ GENERALS_SECTION ~ (NEWLINE? ~ VARIABLE)* }

// Binaries
// A list of variable names of binary variables.
BINARIES_SECTION = _{ ^"Binar" ~ (^"ies" | ^"y") }
BINARIES = { NEWLINE ~ BINARIES_SECTION ~ (NEWLINE? ~ VARIABLE)* }
BINARIES = { NEWLINE* ~ BINARIES_SECTION ~ (NEWLINE? ~ VARIABLE)* }

// Semi-Continuous
// To specify any of the variables as semi-continuous variables, that is as variables that
// may take the value 0 or values between the specified lower and upper bounds
SEMI_CONTINUOUS_SECTION = _{ ^"SEMI" ~ (^"S" | ^"-CONTINUOUS") }
SEMI_CONTINUOUS = { NEWLINE ~ SEMI_CONTINUOUS_SECTION ~ (NEWLINE? ~ VARIABLE)* }
SEMI_CONTINUOUS = { NEWLINE* ~ SEMI_CONTINUOUS_SECTION ~ (NEWLINE? ~ VARIABLE)* }

// SOS: Special Ordered Set
SOS_SECTION = _{ ^"SOS" }
TYPE1 = { "S1::" }
TYPE2 = { "S2::" }
VARIABLE_AND_WEIGHT = { VARIABLE ~ ":" ~ FLOAT }
SOS_CONSTRAINT = { NEWLINE? ~ (CONSTRAINT_NAME ~ COLON?)? ~ (TYPE1 | TYPE2) ~ VARIABLE_AND_WEIGHT* }
SOS = { NEWLINE ~ SOS_SECTION ~ SOS_CONSTRAINT+ }
SOS = { NEWLINE* ~ SOS_SECTION ~ SOS_CONSTRAINT+ }

// End of file
// https://www.ibm.com/docs/en/icos/22.1.1?topic=representation-end-file-in-lp-file-format
Expand Down
1 change: 1 addition & 0 deletions tests/test_from_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ generate_test!(sos, "sos.lp", Maximize, 1, 6, 8);
generate_test!(test, "test.lp", Maximize, 1, 4, 12);
generate_test!(test2, "test2.lp", Maximize, 1, 7, 139);
generate_test!(empty_bounds, "empty_bounds.lp", Minimize, 1, 1, 2);
generate_test!(blank_lines, "blank_lines.lp", Minimize, 1, 1, 3);

#[test]
#[ignore = "fit2d.mps takes > 60 seconds"]
Expand Down

0 comments on commit 5a58e64

Please sign in to comment.