class MIPPeR::Model
Stores a linear programming model for a particular solver
Attributes
constraints[R]
variables[R]
Public Class Methods
new()
click to toggle source
# File lib/mipper/model.rb, line 6 def initialize @solution = nil @sense = :min @variables = [] @constraints = [] @pending_variables = [] @pending_constraints = [] end
Public Instance Methods
<<(obj)
click to toggle source
Add new objects (variables and constraints) to the model
# File lib/mipper/model.rb, line 18 def <<(obj) case obj when Variable @pending_variables << obj when Constraint @pending_constraints << obj else fail TypeError end end
compute_iis()
click to toggle source
Compute an irreducible inconsistent subsytem for the model
# File lib/mipper/model.rb, line 65 def compute_iis fail NotImplementedError end
objective_value()
click to toggle source
Get the value of the objective function from a previous solution
# File lib/mipper/model.rb, line 70 def objective_value @solution.objective_value unless @solution.nil? end
optimize()
click to toggle source
Optimize the model
# File lib/mipper/model.rb, line 51 def optimize fail NotImplementedError end
sense=(_sense)
click to toggle source
Set the sense of the model
# File lib/mipper/model.rb, line 46 def sense=(_sense) fail NotImplementedError end
status()
click to toggle source
Get the status of the model
# File lib/mipper/model.rb, line 56 def status if @solution.nil? :unknown else @solution.status end end
update()
click to toggle source
Update the model
# File lib/mipper/model.rb, line 30 def update update_variables update_constraints end
variable_value(var)
click to toggle source
Get the value of a variable from a previous solution
# File lib/mipper/model.rb, line 75 def variable_value(var) @solution.variable_values[var.index] unless @solution.nil? end
write_lp(_filename)
click to toggle source
Write the model to a file in CPLEX LP format
# File lib/mipper/model.rb, line 36 def write_lp(_filename) fail NotImplementedError end
write_mps(_filename)
click to toggle source
Write the model to a file in MPS format
# File lib/mipper/model.rb, line 41 def write_mps(_filename) fail NotImplementedError end
Protected Instance Methods
add_constraint(constr)
click to toggle source
Just add the constraint as an array
# File lib/mipper/model.rb, line 95 def add_constraint(constr) add_constraints([constr]) end
add_variable(var)
click to toggle source
Just add the variable as an array
# File lib/mipper/model.rb, line 90 def add_variable(var) add_variables([var]) end
build_pointer_array(array, type)
click to toggle source
Shortcut to build a C array from a Ruby array
# File lib/mipper/model.rb, line 82 def build_pointer_array(array, type) buffer = FFI::MemoryPointer.new type, array.length buffer.send("write_array_of_#{type}".to_sym, array) buffer end
set_variable_bounds(_var_index, _ub, _lb)
click to toggle source
# File lib/mipper/model.rb, line 99 def set_variable_bounds(_var_index, _ub, _lb) fail NotImplementedError end
Private Instance Methods
update_constraints()
click to toggle source
Add any pending constraints to the model
# File lib/mipper/model.rb, line 116 def update_constraints if @pending_constraints.length == 1 add_constraint @pending_constraints.first elsif @pending_constraints.length > 0 add_constraints @pending_constraints end @pending_constraints = [] end
update_variables()
click to toggle source
Add any pending variables to the model
# File lib/mipper/model.rb, line 106 def update_variables if @pending_variables.length == 1 add_variable @pending_variables.first elsif @pending_variables.length > 0 add_variables @pending_variables end @pending_variables = [] end