def _process_rhs(self, data_line: DataLine): if len(self._rhs) != len(self.constraint_names): self._rhs = np.zeros(len(self.constraint_names)) self._add_rhs(data_line.second_name(), data_line.first_number()) if data_line.has_third_name() and data_line.has_second_number(): self._add_rhs(data_line.third_name(), data_line.second_number())
def test_has_second_data_entry(line, exp_name, exp_number): """ Tests if the DataLine class correctly tests if there is a second data entry, and parses the result. Also checks that this does not intervene with the first data entry. """ padding = " " * 39 # starts at column 40, so 5 spaces. data_line = DataLine(padding + line) assert_equal(data_line.has_third_name(), exp_name) assert_equal(data_line.has_second_number(), exp_number)
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_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)