Class: LpSolver::LpGenerator
- Inherits:
-
Object
- Object
- LpSolver::LpGenerator
- Defined in:
- lib/lpsolver/lp_generator.rb
Overview
Generates HiGHS LP format strings from a model’s data.
This class handles all serialization logic for converting a model’s variables, constraints, objectives, and bounds into the HiGHS LP format. It is used by both the CLI and native drivers.
Instance Method Summary collapse
-
#generate ⇒ String
Generates the HiGHS LP format string.
-
#initialize(model) ⇒ LpGenerator
constructor
Creates a new LP generator for the given model.
Constructor Details
#initialize(model) ⇒ LpGenerator
Creates a new LP generator for the given model.
17 18 19 |
# File 'lib/lpsolver/lp_generator.rb', line 17 def initialize(model) @model = model end |
Instance Method Details
#generate ⇒ String
Generates the HiGHS LP format string.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lpsolver/lp_generator.rb', line 35 def generate lines = [] lines << (@model.heading == :minimize ? 'Minimize' : 'Maximize') lines << generate_objective lines.concat(generate_constraints) if @model.constraints.any? lines.concat(generate_bounds) if @model.var_bounds.any? lines.concat(generate_integers) if has_integer_variables? lines << 'End' lines.join("\n") end |