Skip to content

Commit

Permalink
feat: Updating .pest grammar to support Special Order Sets
Browse files Browse the repository at this point in the history
  • Loading branch information
dandxy89 committed Nov 12, 2023
1 parent 33153be commit 191a55e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/lp_file_format.pest
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ VALID_CHARS = _{
| "~"
}
VARIABLE = ${
!(FREE | END | CONSTRAINT_SECTION | BOUND_SECTION | GENERALS_SECTION | BINARIES_SECTION | SEMI_CONTINUOUS_SECTION) ~ VALID_CHARS{1, 255}
!(FREE | END | SOS_SECTION | CONSTRAINT_SECTION | BOUND_SECTION | GENERALS_SECTION | BINARIES_SECTION | SEMI_CONTINUOUS_SECTION) ~ VALID_CHARS{1, 255}
}

// Problem Name
Expand Down Expand Up @@ -133,14 +133,20 @@ BINARIES = { NEWLINE ~ BINARIES_SECTION ~ (NEWLINE? ~ VARIABLE)* }
SEMI_CONTINUOUS_SECTION = _{ ^"SEMI" ~ (^"S" | ^"-CONTINUOUS") }
SEMI_CONTINUOUS = { NEWLINE ~ SEMI_CONTINUOUS_SECTION ~ (NEWLINE? ~ VARIABLE)* }

// SOS: Special Ordered Sets
// 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+ }

// End of file
// https://www.ibm.com/docs/en/icos/22.1.1?topic=representation-end-file-in-lp-file-format
EOF = _{ NEWLINE* ~ END }

// Global
OPTIONAL_SECTIONS = _{ BOUNDS? ~ INTEGERS? ~ GENERALS? ~ BINARIES? ~ SEMI_CONTINUOUS? ~ EOF? }
OPTIONAL_SECTIONS = _{ BOUNDS? ~ INTEGERS? ~ GENERALS? ~ BINARIES? ~ SEMI_CONTINUOUS? ~ SOS? ~ EOF? }
LP_FILE = {
LP_PROBLEM_NAME? ~ COMMENTS* ~ PROBLEM_SENSE ~ OBJECTIVES ~ CONSTRAINTS ~ OPTIONAL_SECTIONS
}

0 comments on commit 191a55e

Please sign in to comment.