Class: MIPPeR::CbcModel
Overview
A linear programming model using the COIN-OR solver
Instance Attribute Summary collapse
-
#ptr ⇒ Object
readonly
Returns the value of attribute ptr.
Attributes inherited from Model
Instance Method Summary collapse
-
#initialize ⇒ CbcModel
constructor
A new instance of CbcModel.
-
#optimize ⇒ Object
Optimize the model.
- #parent_update ⇒ Object
-
#sense=(sense) ⇒ Object
Set the sense of the model.
-
#set_variable_bounds(var_index, lb, ub, force = false) ⇒ Object
Set the bounds of a variable in the model.
-
#update ⇒ Object
Avoid doing anything here.
-
#write_mps(filename) ⇒ Object
Write the model to a file in MPS format.
Methods inherited from Model
#<<, #compute_iis, #objective_value, #status, #variable_value, #write_lp
Constructor Details
Instance Attribute Details
#ptr ⇒ Object (readonly)
Returns the value of attribute ptr.
6 7 8 |
# File 'lib/mipper/cbc/model.rb', line 6 def ptr @ptr end |
Instance Method Details
#optimize ⇒ Object
Optimize the model
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/mipper/cbc/model.rb', line 52 def optimize # Ensure pending variables and constraints are added parent_update # Run the solver and save the status for later Cbc.Cbc_solve @ptr fail if Cbc.Cbc_status(@ptr) != 0 save_solution @ptr = new_model reset_model end |
#parent_update ⇒ Object
37 |
# File 'lib/mipper/cbc/model.rb', line 37 alias_method :parent_update, :update |
#sense=(sense) ⇒ Object
Set the sense of the model
45 46 47 48 49 |
# File 'lib/mipper/cbc/model.rb', line 45 def sense=(sense) @sense = sense sense = sense == :min ? 1 : -1 Cbc.Cbc_setObjSense @ptr, sense end |
#set_variable_bounds(var_index, lb, ub, force = false) ⇒ Object
Set the bounds of a variable in the model
67 68 69 70 71 72 73 74 |
# File 'lib/mipper/cbc/model.rb', line 67 def set_variable_bounds(var_index, lb, ub, force = false) # This is a bit of a hack so that we don't try to set # the variable bounds before they get added to the model return unless force Cbc.Cbc_setColLower @ptr, var_index, lb Cbc.Cbc_setColUpper @ptr, var_index, ub end |
#update ⇒ Object
Avoid doing anything here. Updating multiple times will break the model so we defer to #solve.
41 42 |
# File 'lib/mipper/cbc/model.rb', line 41 def update end |
#write_mps(filename) ⇒ Object
Write the model to a file in MPS format
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/mipper/cbc/model.rb', line 21 def write_mps(filename) # Make a new model and ensure everything is added old_ptr = @ptr @ptr = new_model parent_update Cbc.Cbc_writeMps @ptr, filename.chomp('.mps') contents = Zlib::GzipReader.open(filename + '.gz').read File.delete(filename + '.gz') File.open(filename, 'w').write contents # Reset to the original model @ptr = old_ptr reset_model end |