def test_indicator_and_name(): """ Tests if the indicator and name are correctly parsed. """ data_line = DataLine(" N OBJ") # from the LandS.cor file. assert_equal(data_line.indicator(), "N") assert_equal(data_line.first_name(), "OBJ")
def test_first_name_columns(line, expected): """ The first name field is the 5-12 column range (inclusive). """ padding = " " * 4 # starts at column 5, so 4 spaces. data_line = DataLine(padding + line) assert_equal(data_line.first_name(), expected)
def _process_scenarios(self, data_line: DataLine): if data_line.indicator() == "SC": # new scenario scen = Scenario(data_line.first_name(), data_line.second_name(), data_line.third_name(), data_line.first_number()) self._current_scen = scen return var = data_line.first_name() constr = data_line.second_name() value = data_line.first_number() assert self._current_scen is not None self._current_scen.add_modification(constr, var, value) if data_line.has_third_name() and data_line.has_second_number(): constr = data_line.third_name() value = data_line.second_number() self._current_scen.add_modification(constr, var, value)
def test_first_data_entry(): """ Tests if the DataLine class correctly parses the first data entry. """ # From the sslp_5_25_50.cor file. line = " x_1 c2 188" data_line = DataLine(line) assert_equal(data_line.first_name(), "x_1") assert_equal(data_line.second_name(), "c2") assert_almost_equal(data_line.first_number(), 188)
def _process_periods(self, data_line: DataLine): assert data_line.has_third_name() period = data_line.third_name() self._stage_names.append(period) if self._param == "IMPLICIT": # In the IMPLICIT formulation, the PERIODS section also contains # the (var, constr) offsets of this stage's CORE data. var = data_line.first_name() constr = data_line.second_name() self._stage_offsets.append((var, constr))
def _parse_marker(self, data_line: DataLine): assert data_line.has_third_name() name = data_line.first_name() marker_type = data_line.third_name() logger.debug(f"Encountered a {marker_type} marker named {name}.") if "INTORG" in marker_type.upper(): self._parse_ints = True if "INTEND" in marker_type.upper(): self._parse_ints = False
def _parse_column(self, data_line: DataLine): var = data_line.first_name() if var not in self._var2idx: self._variable_names.append(var) self._types.append('I' if self._parse_ints else 'C') self._var2idx[var] = len(self._variable_names) - 1 constr = data_line.second_name() value = data_line.first_number() self._add_value(constr, var, value) if data_line.has_third_name() and data_line.has_second_number(): constr = data_line.third_name() value = data_line.second_number() self._add_value(constr, var, value)
def _process_rows(self, data_line: DataLine): indicator = data_line.indicator() name = data_line.first_name() assert indicator in _CONSTRAINT_SENSES # This is a "no restriction" row, which indicates an objective function. # There can be more than one such row, but there can only be one # objective. We take the first such row as the objective, and then # ignore any subsequent "no restriction" rows. if indicator == 'N': if self.objective_name == "": logger.debug(f"Setting {name} as objective.") self._objective_name = name return else: self._constr_names.append(name) self._senses.append(indicator) self._constr2idx[name] = len(self._constr_names) - 1
def _process_columns(self, data_line: DataLine): var = data_line.first_name() period = data_line.second_name() self._explicit_variables.append((var, period))
def _process_rows(self, data_line: DataLine): constr = data_line.first_name() period = data_line.second_name() self._explicit_constraints.append((constr, period))