Class: MIPPeR::LPSolveModel
Overview
A linear programming model using the lp_solve solver
Instance Attribute Summary collapse
-
#ptr ⇒ Object
readonly
Returns the value of attribute ptr.
Attributes inherited from Model
Instance Method Summary collapse
-
#initialize ⇒ LPSolveModel
constructor
A new instance of LPSolveModel.
-
#optimize ⇒ Object
Optimize the model.
-
#sense=(sense) ⇒ Object
Set the sense of the model.
- #set_variable_bounds(var_index, lb, ub) ⇒ Object
Methods inherited from Model
#<<, #compute_iis, #objective_value, #status, #update, #variable_value, #write_lp, #write_mps
Constructor Details
#initialize ⇒ LPSolveModel
Returns a new instance of LPSolveModel.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/mipper/lp_solve/model.rb', line 6 def initialize fail unless MIPPeR.const_defined?(:LPSolve) super @var_count = 0 @constr_count = 0 # Construct a new model @ptr = FFI::AutoPointer.new LPSolve.make_lp(0, 0), LPSolve.method(:delete_lp) # Disable output ret = LPSolve.set_outputfile @ptr, '' fail if ret != 1 end |
Instance Attribute Details
#ptr ⇒ Object (readonly)
Returns the value of attribute ptr.
4 5 6 |
# File 'lib/mipper/lp_solve/model.rb', line 4 def ptr @ptr end |
Instance Method Details
#optimize ⇒ Object
Optimize the model
31 32 33 34 35 36 37 38 |
# File 'lib/mipper/lp_solve/model.rb', line 31 def optimize # Ensure pending variables and constraints are added update # Run the solver and save the status for later status = LPSolve.solve(@ptr) save_solution status end |
#sense=(sense) ⇒ Object
Set the sense of the model
24 25 26 27 28 |
# File 'lib/mipper/lp_solve/model.rb', line 24 def sense=(sense) @sense = sense sense = sense == :min ? 0 : 1 LPSolve.set_sense @ptr, sense end |
#set_variable_bounds(var_index, lb, ub) ⇒ Object
40 41 42 43 |
# File 'lib/mipper/lp_solve/model.rb', line 40 def set_variable_bounds(var_index, lb, ub) ret = LPSolve.set_bounds @ptr, var_index, lb, ub fail if ret != 1 end |