Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Blank lines aren't ignored #30

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading