diff --git a/resources/blank_lines.lp b/resources/blank_lines.lp new file mode 100644 index 0000000..c88822a --- /dev/null +++ b/resources/blank_lines.lp @@ -0,0 +1,10 @@ +\ LP format example + +Minimize +obj: x + 10 y +Subject To +r01: x + y >= 1 + +Binaries + x y z +End diff --git a/src/lp_file_format.pest b/src/lp_file_format.pest index c3b45e0..113f5be 100644 --- a/src/lp_file_format.pest +++ b/src/lp_file_format.pest @@ -114,24 +114,24 @@ 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" } @@ -139,7 +139,7 @@ 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 diff --git a/tests/test_from_file.rs b/tests/test_from_file.rs index f8b2b80..3cf22ed 100644 --- a/tests/test_from_file.rs +++ b/tests/test_from_file.rs @@ -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"]